linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>, Olof Johansson <olof@lixom.net>,
	Markus Mayer <mmayer@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com,
	Florian Fainelli <f.fainelli@gmail.com>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Roger Quadros <rogerq@ti.com>, Tony Lindgren <tony@atomide.com>,
	Vladimir Zapolskiy <vz@mleia.com>, Kukjin Kim <kgene@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-omap@vger.kernel.org,
	linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Krzysztof Kozlowski <krzk@kernel.org>
Subject: [RFT v2 21/29] memory: omap-gpmc: Remove GPMC_SET_ONE_CD_MAX macro for safety
Date: Fri, 24 Jul 2020 09:40:30 +0200	[thread overview]
Message-ID: <20200724074038.5597-22-krzk@kernel.org> (raw)
In-Reply-To: <20200724074038.5597-1-krzk@kernel.org>

The GPMC_SET_ONE_CD_MAX macro uses return statement and variable 'cs'
coming from called scope.  This is not a good practice.  Also
checkpatch complained:

    WARNING: Macros with flow control statements should be avoided
    ERROR: Macros starting with if should be enclosed by a do - while
        loop to avoid possible if/else logic defects

Since GPMC_SET_ONE_CD_MAX macro just calls one function, it can be open
coded.  The difference with original code is that function will exit on
error not after every register set, but after a group of sets.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

---

Not tested

Changes since v1:
1. Drop the macro, after comments from Arnd.
---
 drivers/memory/omap-gpmc.c | 137 +++++++++++++++++++++++++------------
 1 file changed, 93 insertions(+), 44 deletions(-)

diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c
index 1e370142dfca..2a2d0297e071 100644
--- a/drivers/memory/omap-gpmc.c
+++ b/drivers/memory/omap-gpmc.c
@@ -635,14 +635,6 @@ static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, int max
 	return 0;
 }
 
-#define GPMC_SET_ONE_CD_MAX(reg, st, end, max, field, cd)  \
-	if (set_gpmc_timing_reg(cs, (reg), (st), (end), (max), \
-	    t->field, (cd), #field) < 0)                       \
-		return -ENXIO
-
-#define GPMC_SET_ONE(reg, st, end, field) \
-	GPMC_SET_ONE_CD_MAX(reg, st, end, 0, field, GPMC_CD_FCLK)
-
 /**
  * gpmc_calc_waitmonitoring_divider - calculate proper GPMCFCLKDIVIDER based on WAITMONITORINGTIME
  * WAITMONITORINGTIME will be _at least_ as long as desired, i.e.
@@ -703,7 +695,7 @@ int gpmc_calc_divider(unsigned int sync_clk)
 int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t,
 			const struct gpmc_settings *s)
 {
-	int div;
+	int div, ret;
 	u32 l;
 
 	div = gpmc_calc_divider(t->sync_clk);
@@ -737,53 +729,110 @@ int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t,
 		}
 	}
 
-	GPMC_SET_ONE(GPMC_CS_CONFIG2,  0,  3, cs_on);
-	GPMC_SET_ONE(GPMC_CS_CONFIG2,  8, 12, cs_rd_off);
-	GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
+	ret = 0;
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 0, 3, 0, t->cs_on,
+				   GPMC_CD_FCLK, "cs_on");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 8, 12, 0, t->cs_rd_off,
+				   GPMC_CD_FCLK, "cs_rd_off");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 16, 20, 0, t->cs_wr_off,
+				   GPMC_CD_FCLK, "cs_wr_off");
+	if (ret)
+		return -ENXIO;
+
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 0, 3, 0, t->adv_on,
+				   GPMC_CD_FCLK, "adv_on");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 8, 12, 0, t->adv_rd_off,
+				   GPMC_CD_FCLK, "adv_rd_off");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 16, 20, 0, t->adv_wr_off,
+				   GPMC_CD_FCLK, "adv_wr_off");
+	if (ret)
+		return -ENXIO;
 
-	GPMC_SET_ONE(GPMC_CS_CONFIG3,  0,  3, adv_on);
-	GPMC_SET_ONE(GPMC_CS_CONFIG3,  8, 12, adv_rd_off);
-	GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
 	if (gpmc_capability & GPMC_HAS_MUX_AAD) {
-		GPMC_SET_ONE(GPMC_CS_CONFIG3,  4,  6, adv_aad_mux_on);
-		GPMC_SET_ONE(GPMC_CS_CONFIG3, 24, 26, adv_aad_mux_rd_off);
-		GPMC_SET_ONE(GPMC_CS_CONFIG3, 28, 30, adv_aad_mux_wr_off);
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 4, 6, 0,
+					   t->adv_aad_mux_on, GPMC_CD_FCLK,
+					   "adv_aad_mux_on");
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 24, 26, 0,
+					   t->adv_aad_mux_rd_off, GPMC_CD_FCLK,
+					   "adv_aad_mux_rd_off");
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 28, 30, 0,
+					   t->adv_aad_mux_wr_off, GPMC_CD_FCLK,
+					   "adv_aad_mux_wr_off");
+		if (ret)
+			return -ENXIO;
 	}
 
-	GPMC_SET_ONE(GPMC_CS_CONFIG4,  0,  3, oe_on);
-	GPMC_SET_ONE(GPMC_CS_CONFIG4,  8, 12, oe_off);
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 0, 3, 0, t->oe_on,
+				   GPMC_CD_FCLK, "oe_on");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 8, 12, 0, t->oe_off,
+				   GPMC_CD_FCLK, "oe_off");
 	if (gpmc_capability & GPMC_HAS_MUX_AAD) {
-		GPMC_SET_ONE(GPMC_CS_CONFIG4,  4,  6, oe_aad_mux_on);
-		GPMC_SET_ONE(GPMC_CS_CONFIG4, 13, 15, oe_aad_mux_off);
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 4, 6, 0,
+					   t->oe_aad_mux_on, GPMC_CD_FCLK,
+					   "oe_aad_mux_on");
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 13, 15, 0,
+					   t->oe_aad_mux_off, GPMC_CD_FCLK,
+					   "oe_aad_mux_off");
+	}
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 16, 19, 0, t->we_on,
+				   GPMC_CD_FCLK, "we_on");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 24, 28, 0, t->we_off,
+				   GPMC_CD_FCLK, "we_off");
+	if (ret)
+		return -ENXIO;
+
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 0, 4, 0, t->rd_cycle,
+				   GPMC_CD_FCLK, "rd_cycle");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 8, 12, 0, t->wr_cycle,
+				   GPMC_CD_FCLK, "wr_cycle");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 16, 20, 0, t->access,
+				   GPMC_CD_FCLK, "access");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 24, 27, 0,
+				   t->page_burst_access, GPMC_CD_FCLK,
+				   "page_burst_access");
+	if (ret)
+		return -ENXIO;
+
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 0, 3, 0,
+				   t->bus_turnaround, GPMC_CD_FCLK,
+				   "bus_turnaround");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 8, 11, 0,
+				   t->cycle2cycle_delay, GPMC_CD_FCLK,
+				   "cycle2cycle_delay");
+	if (ret)
+		return -ENXIO;
+
+	if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS) {
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 16, 19, 0,
+					   t->wr_data_mux_bus, GPMC_CD_FCLK,
+					   "wr_data_mux_bus");
+		if (ret)
+			return -ENXIO;
+	}
+	if (gpmc_capability & GPMC_HAS_WR_ACCESS) {
+		ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 24, 28, 0,
+					   t->wr_access, GPMC_CD_FCLK,
+					   "wr_access");
+		if (ret)
+			return -ENXIO;
 	}
-	GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
-	GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
-
-	GPMC_SET_ONE(GPMC_CS_CONFIG5,  0,  4, rd_cycle);
-	GPMC_SET_ONE(GPMC_CS_CONFIG5,  8, 12, wr_cycle);
-	GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
-
-	GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
-
-	GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
-	GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
-
-	if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
-		GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
-	if (gpmc_capability & GPMC_HAS_WR_ACCESS)
-		GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
 
 	l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
 	l &= ~0x03;
 	l |= (div - 1);
 	gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
 
-	GPMC_SET_ONE_CD_MAX(GPMC_CS_CONFIG1, 18, 19,
-			    GPMC_CONFIG1_WAITMONITORINGTIME_MAX,
-			    wait_monitoring, GPMC_CD_CLK);
-	GPMC_SET_ONE_CD_MAX(GPMC_CS_CONFIG1, 25, 26,
-			    GPMC_CONFIG1_CLKACTIVATIONTIME_MAX,
-			    clk_activation, GPMC_CD_FCLK);
+	ret = 0;
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG1, 18, 19,
+				   GPMC_CONFIG1_WAITMONITORINGTIME_MAX,
+				   t->wait_monitoring, GPMC_CD_CLK,
+				   "wait_monitoring");
+	ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG1, 25, 26,
+				   GPMC_CONFIG1_CLKACTIVATIONTIME_MAX,
+				   t->clk_activation, GPMC_CD_FCLK,
+				   "clk_activation");
+	if (ret)
+		return -ENXIO;
 
 #ifdef CONFIG_OMAP_GPMC_DEBUG
 	pr_info("GPMC CS%d CLK period is %lu ns (div %d)\n",
-- 
2.17.1


  parent reply	other threads:[~2020-07-24  7:42 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24  7:40 [PATCH v2 00/29] *memory: Cleanup, improve and compile test memory drivers Krzysztof Kozlowski
2020-07-24  7:40 ` [RFT v2 01/29] memory: omap-gpmc: Remove unneeded asm/mach-types.h inclusion Krzysztof Kozlowski
2020-08-17 18:27   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [RFT v2 02/29] memory: omap-gpmc: Remove unused file-scope phys_base and mem_size Krzysztof Kozlowski
2020-08-17 18:31   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 03/29] memory: omap-gpmc: Include <linux/sizes.h> for SZ_16M Krzysztof Kozlowski
2020-07-24 14:09   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 04/29] memory: ti-aemif: Rename SS to SSTROBE to avoid name conflicts Krzysztof Kozlowski
2020-07-24 14:10   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 05/29] memory: jz4780-nemc: Do not enable by default on every compile test Krzysztof Kozlowski
2020-07-24 13:45   ` Arnd Bergmann
2020-07-24 13:53     ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 06/29] memory: Enable compile testing for most of the drivers Krzysztof Kozlowski
2020-07-27  8:17   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 07/29] memory: of: Remove unused headers Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 08/29] memory: of: Remove __func__ in device related messages Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 09/29] memory: of: Correct indentation Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 10/29] memory: of: Remove unneeded extern from function declarations Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 11/29] memory: emif-asm-offsets: Add GPLv2 SPDX license header Krzysztof Kozlowski
2020-07-24 14:10   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 12/29] memory: emif: Put constant in comparison on the right side Krzysztof Kozlowski
2020-07-24 14:10   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 13/29] memory: emif: Fix whitespace coding style violations Krzysztof Kozlowski
2020-07-24 14:11   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 14/29] memory: emif: Silence platform_get_irq() error in driver Krzysztof Kozlowski
2020-07-24 14:11   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 15/29] memory: ti-emif-pm: Fix cast to iomem pointer Krzysztof Kozlowski
2020-07-24 14:12   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 16/29] memory: renesas-rpc-if: Simplify with PTR_ERR_OR_ZERO Krzysztof Kozlowski
2020-08-17 18:34   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 17/29] memory: brcmstb_dpfe: Constify the contents of string Krzysztof Kozlowski
2020-07-24 14:12   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 18/29] memory: brcmstb_dpfe: Remove unneeded braces Krzysztof Kozlowski
2020-07-24 14:13   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 19/29] memory: mtk-smi: Add argument to function pointer definition Krzysztof Kozlowski
2020-07-24 14:13   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [RFT v2 20/29] memory: omap-gpmc: Return meaningful error codes in gpmc_cs_set_timings() Krzysztof Kozlowski
2020-08-17 18:32   ` Krzysztof Kozlowski
2020-07-24  7:40 ` Krzysztof Kozlowski [this message]
2020-08-17 18:33   ` [RFT v2 21/29] memory: omap-gpmc: Remove GPMC_SET_ONE_CD_MAX macro for safety Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 22/29] memory: omap-gpmc: Fix whitespace issue Krzysztof Kozlowski
2020-07-24 14:16   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 23/29] memory: pl172: Add GPLv2 SPDX license header Krzysztof Kozlowski
2020-07-24 14:16   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 24/29] memory: tegra: tegra210-emc: Fix indentation Krzysztof Kozlowski
2020-08-17 18:34   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 25/29] MAINTAINERS: Add Krzysztof Kozlowski as maintainer of memory controllers Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 26/29] memory: fsl_ifc: Fix whitespace issues Krzysztof Kozlowski
2020-07-24 14:15   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 27/29] memory: da8xx-ddrctl: Remove unused 'node' variable Krzysztof Kozlowski
2020-07-24 14:15   ` Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 28/29] memory: Describe the MEMORY Kconfig entry Krzysztof Kozlowski
2020-07-24  7:40 ` [PATCH v2 29/29] memory: samsung: exynos-srom: Describe the " Krzysztof Kozlowski
2020-07-24 13:51 ` [PATCH v2 00/29] *memory: Cleanup, improve and compile test memory drivers Arnd Bergmann
2020-07-24 14:03   ` Krzysztof Kozlowski

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=20200724074038.5597-22-krzk@kernel.org \
    --to=krzk@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=f.fainelli@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=kgene@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mmayer@broadcom.com \
    --cc=olof@lixom.net \
    --cc=rogerq@ti.com \
    --cc=ssantosh@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=tony@atomide.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vz@mleia.com \
    /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).