DPDK patches and discussions
 help / color / mirror / Atom feed
From: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
To: dev@dpdk.org, david.hunt@intel.com
Cc: stable@dpdk.org, alan.carew@intel.com, pablo.de.lara.guarch@intel.com
Subject: [dpdk-dev] [PATCH 1/3] power: removing code macros
Date: Sat, 11 Nov 2017 19:55:05 +0100	[thread overview]
Message-ID: <1510426507-28245-2-git-send-email-radoslaw.biernacki@linaro.org> (raw)
In-Reply-To: <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org>

This fix implements David Hunt suggestion to remove error checking
code macros.  Together with improved code readability it removes
checkpatch warnings.

Fixes: 445c6528b55f ("power: common interface for guest and host")
CC: stable@dpdk.org

Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
---
 lib/librte_power/rte_power_acpi_cpufreq.c | 81 ++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 33 deletions(-)

diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c
index 01ac5ac..3d0872f 100644
--- a/lib/librte_power/rte_power_acpi_cpufreq.c
+++ b/lib/librte_power/rte_power_acpi_cpufreq.c
@@ -55,27 +55,6 @@
 #define POWER_DEBUG_TRACE(fmt, args...)
 #endif
 
-#define FOPEN_OR_ERR_RET(f, retval) do { \
-		if ((f) == NULL) { \
-			RTE_LOG(ERR, POWER, "File not openned\n"); \
-			return retval; \
-		} \
-} while (0)
-
-#define FOPS_OR_NULL_GOTO(ret, label) do { \
-		if ((ret) == NULL) { \
-			RTE_LOG(ERR, POWER, "fgets returns nothing\n"); \
-			goto label; \
-		} \
-} while (0)
-
-#define FOPS_OR_ERR_GOTO(ret, label) do { \
-		if ((ret) < 0) { \
-			RTE_LOG(ERR, POWER, "File operations failed\n"); \
-			goto label; \
-		} \
-} while (0)
-
 #define STR_SIZE     1024
 #define POWER_CONVERT_TO_DECIMAL 10
 
@@ -172,10 +151,16 @@ power_set_governor_userspace(struct rte_power_info *pi)
 	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
 			pi->lcore_id);
 	f = fopen(fullpath, "rw+");
-	FOPEN_OR_ERR_RET(f, ret);
+	if (!f) {
+		RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath);
+		return ret;
+	}
 
 	s = fgets(buf, sizeof(buf), f);
-	FOPS_OR_NULL_GOTO(s, out);
+	if (!s) {
+		RTE_LOG(ERR, POWER, "fgets returns nothing\n");
+		goto out;
+	}
 
 	/* Check if current governor is userspace */
 	if (strncmp(buf, POWER_GOVERNOR_USERSPACE,
@@ -190,10 +175,16 @@ power_set_governor_userspace(struct rte_power_info *pi)
 
 	/* Write 'userspace' to the governor */
 	val = fseek(f, 0, SEEK_SET);
-	FOPS_OR_ERR_GOTO(val, out);
+	if (val < 0) {
+		RTE_LOG(ERR, POWER, "fseek failed\n");
+		goto out;
+	}
 
 	val = fputs(POWER_GOVERNOR_USERSPACE, f);
-	FOPS_OR_ERR_GOTO(val, out);
+	if (val < 0) {
+		RTE_LOG(ERR, POWER, "fputs failed\n");
+		goto out;
+	}
 
 	ret = 0;
 	RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
@@ -222,10 +213,16 @@ power_get_available_freqs(struct rte_power_info *pi)
 	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_FREQ,
 			pi->lcore_id);
 	f = fopen(fullpath, "r");
-	FOPEN_OR_ERR_RET(f, ret);
+	if (!f) {
+		RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath);
+		return ret;
+	}
 
 	s = fgets(buf, sizeof(buf), f);
-	FOPS_OR_NULL_GOTO(s, out);
+	if (!s) {
+		RTE_LOG(ERR, POWER, "fgets returns nothing\n");
+		goto out;
+	}
 
 	/* Strip the line break if there is */
 	p = strchr(buf, '\n');
@@ -290,10 +287,16 @@ power_init_for_setting_freq(struct rte_power_info *pi)
 	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SETSPEED,
 			pi->lcore_id);
 	f = fopen(fullpath, "rw+");
-	FOPEN_OR_ERR_RET(f, -1);
+	if (!f) {
+		RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath);
+		return -1;
+	}
 
 	s = fgets(buf, sizeof(buf), f);
-	FOPS_OR_NULL_GOTO(s, out);
+	if (!s) {
+		RTE_LOG(ERR, POWER, "fgets returns nothing\n");
+		goto out;
+	}
 
 	freq = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);
 	for (i = 0; i < pi->nb_freqs; i++) {
@@ -387,10 +390,16 @@ power_set_governor_original(struct rte_power_info *pi)
 	snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
 			pi->lcore_id);
 	f = fopen(fullpath, "rw+");
-	FOPEN_OR_ERR_RET(f, ret);
+	if (!f) {
+		RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath);
+		return ret;
+	}
 
 	s = fgets(buf, sizeof(buf), f);
-	FOPS_OR_NULL_GOTO(s, out);
+	if (!s) {
+		RTE_LOG(ERR, POWER, "fgets returns nothing\n");
+		goto out;
+	}
 
 	/* Check if the governor to be set is the same as current */
 	if (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {
@@ -403,10 +412,16 @@ power_set_governor_original(struct rte_power_info *pi)
 
 	/* Write back the original governor */
 	val = fseek(f, 0, SEEK_SET);
-	FOPS_OR_ERR_GOTO(val, out);
+	if (val < 0) {
+		RTE_LOG(ERR, POWER, "fseek failed\n");
+		goto out;
+	}
 
 	val = fputs(pi->governor_ori, f);
-	FOPS_OR_ERR_GOTO(val, out);
+	if (val < 0) {
+		RTE_LOG(ERR, POWER, "fputs failed\n");
+		goto out;
+	}
 
 	ret = 0;
 	RTE_LOG(INFO, POWER, "Power management governor of lcore %u "
-- 
2.7.4

  reply	other threads:[~2017-11-11 18:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-16 13:47 [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access Radoslaw Biernacki
2017-10-16 13:47 ` [dpdk-dev] [PATCH 2/2] power: check if userspace governor is available Radoslaw Biernacki
2017-10-18 10:53   ` Hunt, David
2017-10-18 14:02     ` Radoslaw Biernacki
2017-10-18 10:28 ` [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access Hunt, David
2017-10-18 10:33 ` Hunt, David
2017-10-18 13:56   ` Radoslaw Biernacki
2017-11-11 18:55 ` [dpdk-dev] [PATCH 0/3] power: fixes for power ACPI through sysfs Radoslaw Biernacki
2017-11-11 18:55   ` Radoslaw Biernacki [this message]
2017-11-11 18:55   ` [dpdk-dev] [PATCH 2/3] power: switching to unbuffered access for /sys files Radoslaw Biernacki
2017-11-23 14:42     ` Hunt, David
2017-12-01 21:01       ` Radoslaw Biernacki
2018-01-31 23:38         ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2017-11-11 18:55   ` [dpdk-dev] [PATCH 3/3] power: check if userspace governor is available Radoslaw Biernacki
2017-11-21 11:09   ` [dpdk-dev] [PATCH 0/3] power: fixes for power ACPI through sysfs Radoslaw Biernacki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1510426507-28245-2-git-send-email-radoslaw.biernacki@linaro.org \
    --to=radoslaw.biernacki@linaro.org \
    --cc=alan.carew@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).