From patchwork Sat Nov 11 18:55:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radoslaw Biernacki X-Patchwork-Id: 118616 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp58435qgn; Sat, 11 Nov 2017 10:56:09 -0800 (PST) X-Google-Smtp-Source: AGs4zMYnc2XL2JKVhDFGc5JeG9V4QO3Sf71zodbMoKCGVANnYU5b40DQZ75KZpetd/oLOnasdDO2 X-Received: by 10.223.184.42 with SMTP id h39mr3537288wrf.38.1510426569882; Sat, 11 Nov 2017 10:56:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510426569; cv=none; d=google.com; s=arc-20160816; b=z3zUsv49AxF0Vt5TY6k49ceaL5YBrT4dHzZgo+dW6BdFhjxcSxe6k6whg/Ti+JTu3F 4UqiR60bzBNkerkr6wLWgDwJbUwqYeWw0KH2OW9Ke86Kk1HxwFrKopwX/tMrWlt0ggRN SIN6OXCl9dKLzhnjvEILpXJ1MnOJMdD8QQNre0N4N4tbBVk/zg+nhVt1uGpx7UM1vMdp lfyhUEpBC18d0QhnC7vfsWDVAV9lyuhyzs1Lkvt2xs4uLlCk0r4L1F5eYhZC8fNmUsZe IP+TwxlLc1HWd6QLLGOjknCXvk/cQtobLHdpY5I1IGNcozlceKQfc81l8vf+dKCSH9mP PA8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from:dkim-signature :arc-authentication-results; bh=vUQCCJSN8CGiB4UZE3IjW0aIFc0qwXtMv5b8I8XzhgA=; b=gcb1kxu92Ed7bRZKigbblMWNVkVPWyJGwc2QLEGK37lLJoSVT8RnBzJhlE8E+TGcKM IYjU4/ayVFfCfg85BP2JdHExoOLUq1aa3pX19EGjSPPTmIwjYACMtoKOn3HioBZIU+TB jCQ6yszo9HHitvbIYtravlS1h55epAjlQu9+snof7oznOL7Bg8yUUYER2McofSVTOP3N 5ftf634djOq05zMNpA3RNWLd7lgWGC3uTsrAFNmmxQMEO6TOwgzDZSAgQyUKlXpA0Dog y61fUWQs39hPS1mHyb5xrhWFRzR/joFnxHoa5g6ZWQ7nmHMW/ZJJ33iAW2SrsqRsAX1Q NJFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VNHJIk1D; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id b78si10196246wrd.92.2017.11.11.10.56.09; Sat, 11 Nov 2017 10:56:09 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VNHJIk1D; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1D0B61B218; Sat, 11 Nov 2017 19:56:04 +0100 (CET) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by dpdk.org (Postfix) with ESMTP id 4FA3F1B20F for ; Sat, 11 Nov 2017 19:56:02 +0100 (CET) Received: by mail-lf0-f68.google.com with SMTP id s16so14104372lfs.1 for ; Sat, 11 Nov 2017 10:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vUQCCJSN8CGiB4UZE3IjW0aIFc0qwXtMv5b8I8XzhgA=; b=VNHJIk1DnqYBa3jfeghu5D9wgKaMu7jOxSqFbukRENtDhNM/551FuaeLqzO9WQR2e4 pzLxEgMBwt6jovlcBqdQ1SUjnNQOqCLP4mMwx50veAgTdyGzg/rfVqyzNd9atnP0rnbH 3Elrf6+6mdHoQEzantWPjPkr+DFZwd+WAqtQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vUQCCJSN8CGiB4UZE3IjW0aIFc0qwXtMv5b8I8XzhgA=; b=IOKjnVPJVIEuJtec0uUNwsAEQ3WkJI/w16ESI2QCTImsntp9cpPPVGSuxayK9FZ188 +ZKdpGZ4ttiCNuhDJhDsYbYYp10Ss8j155UmXt3Ya6e5IqqPqQ58Dp6TgQLGOpQWSGR6 cdCD0SQk6jXdU8cnmrv0BLpq23ZPg+gl0H1VCQDjoS+TGxpne4aBFdKqHFniURtfjG4B 9pXghLY9PjvVReYPhBkNU9dsr1cBlhb0FG5l6vqfwCFAI4X8FXghROjFXxkKH3s5xoOM EPPbzdSdwOGCDOxCjg1i4BeyAA050SOpfPvFFfoIv1K0YYmHsAq/ERUC2lxx801OfV9u 8bJw== X-Gm-Message-State: AJaThX7HSQPpbxGBRX6pgj0SgHH58sTz4armqF89NXJnESnZl+vGdL5B iSk/wsc7POiiS9bUfmgGjUBXQLzL0S8= X-Received: by 10.46.67.207 with SMTP id z76mr999246lje.61.1510426561433; Sat, 11 Nov 2017 10:56:01 -0800 (PST) Received: from rad-H81M-S1.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id x90sm2342107ljb.86.2017.11.11.10.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Nov 2017 10:56:00 -0800 (PST) From: Radoslaw Biernacki To: dev@dpdk.org, david.hunt@intel.com Cc: stable@dpdk.org, alan.carew@intel.com, pablo.de.lara.guarch@intel.com Date: Sat, 11 Nov 2017 19:55:05 +0100 Message-Id: <1510426507-28245-2-git-send-email-radoslaw.biernacki@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org> References: <1508161628-4265-1-git-send-email-radoslaw.biernacki@linaro.org> <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org> Subject: [dpdk-dev] [PATCH 1/3] power: removing code macros X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- lib/librte_power/rte_power_acpi_cpufreq.c | 81 ++++++++++++++++++------------- 1 file changed, 48 insertions(+), 33 deletions(-) -- 2.7.4 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 "