linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Olof Johansson <olof@lixom.net>, arm-soc <arm@kernel.org>,
	SoC Team <soc@kernel.org>, Markus Mayer <mmayer@broadcom.com>,
	bcm-kernel-feedback-list <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>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	"moderated list:ARM/Mediatek SoC..."
	<linux-mediatek@lists.infradead.org>,
	linux-omap <linux-omap@vger.kernel.org>"open list:TEGRA
	ARCHITECTURE SUPPORT" <li>
Subject: Re: [PATCH 19/23] memory: omap-gpmc: Enclose macro statements in do-while
Date: Thu, 23 Jul 2020 12:16:34 +0200	[thread overview]
Message-ID: <20200723101634.GD30472@kozik-lap> (raw)
In-Reply-To: <CAK8P3a3emZd=Tz5JhxevkX3OJMMEn_2Nb+_LQtGZJ9-GWNpd2g@mail.gmail.com>

On Thu, Jul 23, 2020 at 11:09:40AM +0200, Arnd Bergmann wrote:
> On Thu, Jul 23, 2020 at 9:39 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >
> > do-while is a preferred way for complex macros because of safety
> > reasons.  This fixes checkpatch error:
> >
> >     ERROR: Macros starting with if should be enclosed by a do - while
> >         loop to avoid possible if/else logic defects
> >
> > Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> 
> This is an improvement, but the macro still has other issues that
> are just as bad as the one you address:
> 
> - Using the # operator to avoid the "" in the invocation seems confusing

I guess it was useful for debugging.

> - it implicitly uses the 'cs' and 't' variables of the calling function instead
>   of passing them as arguments.

Actually another reason to convert it to just a function.

> - it calls 'return -1' in a function that otherwise uses errno-style
>   return codes, so this gets interpreted as EPERM "Operation not
>   permitted".

The users of this macro also do it (gpmc_cs_set_timings()) so this
wrong practice is consistent with the driver. :)

> 
> I would probably just open-code the entire thing and remove the
> macro like:
> 
> 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;a

I like this approach because it also removes the 'return' from macro
which is not desired.

> 
> Of maybe leave the macro, but remove the if/return part and use
> the "ret |= GPMC_SET_ONE(...)" trick to avoid some of the problems.

I could probably then keep it as a function.  This would be the safest
and remove most of the problems here.

Best regards,
Krzysztof

  reply	other threads:[~2020-07-23 10:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200723073744.13400-1-krzk@kernel.org>
     [not found] ` <20200723073744.13400-15-krzk@kernel.org>
     [not found]   ` <20200723073744.13400-15-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23  8:48     ` [PATCH 14/23] memory: ti-emif-pm: Fix cast to iomem pointer Arnd Bergmann
     [not found]       ` <CAK8P3a3btGD5oqmPXJk=UOmA=wuUxn-vOOO982uAjuRcE3crVg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-07-23  9:02         ` Krzysztof Kozlowski
2020-07-23  9:14           ` Arnd Bergmann
     [not found]             ` <CAK8P3a2O4bCb_Bcpc+Y4BuXmrO6mbVwgo67aGF5E=uxHQpeTnw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-07-23 10:01               ` Krzysztof Kozlowski
     [not found] ` <20200723073744.13400-19-krzk@kernel.org>
     [not found]   ` <20200723073744.13400-19-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23  8:50     ` [PATCH 18/23] memory: mtk-smi: Add argument to function definition Arnd Bergmann
2020-07-23  8:55       ` Krzysztof Kozlowski
     [not found] ` <20200723073744.13400-20-krzk@kernel.org>
     [not found]   ` <20200723073744.13400-20-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23  9:09     ` [PATCH 19/23] memory: omap-gpmc: Enclose macro statements in do-while Arnd Bergmann
2020-07-23 10:16       ` Krzysztof Kozlowski [this message]
     [not found] ` <20200723073744.13400-21-krzk@kernel.org>
     [not found]   ` <20200723073744.13400-21-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23  9:11     ` [PATCH 20/23] memory: omap-gpmc: Fix whitespace issue Arnd Bergmann
     [not found]       ` <CAK8P3a1=WCQ5326Et5RRK7yiOYeHH7uUkQ+T3YPtj2XRh+gkgA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-07-23 10:08         ` Krzysztof Kozlowski
     [not found] ` <20200723073744.13400-1-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23  9:31   ` [RFC PATCH 00/23] memory: Cleanup, improve and compile test memory drivers Arnd Bergmann
     [not found]     ` <CAK8P3a0hcVhBbKCBDSZYXChmPpRVsEi_G6+oj5quC6uUiPeeiA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-07-23  9:52       ` Krzysztof Kozlowski
2020-07-23 10:14         ` Arnd Bergmann
     [not found] ` <20200723073744.13400-17-krzk@kernel.org>
     [not found]   ` <20200723073744.13400-17-krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-07-23 17:11     ` [PATCH 16/23] memory: brcmstb_dpfe: Constify the contents of string Florian Fainelli
2020-07-23 17:15       ` Markus Mayer
     [not found] ` <20200723073744.13400-18-krzk@kernel.org>
2020-07-23 17:11   ` [PATCH 17/23] memory: brcmstb_dpfe: Remove unneeded braces Florian Fainelli
     [not found]     ` <e65d4ed3-3c01-acb7-f324-be99201815df-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2020-07-23 17:15       ` Markus Mayer
     [not found] ` <20200723073744.13400-24-krzk@kernel.org>
2020-07-23 17:12   ` [PATCH 23/23] MAINTAINERS: Add Krzysztof Kozlowski as maintainer of memory controllers Florian Fainelli
2020-07-24  7:15     ` 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=20200723101634.GD30472@kozik-lap \
    --to=krzk@kernel.org \
    --cc=arm@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=f.fainelli@gmail.com \
    --cc=jonathanh@nvidia.com \
    --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=matthias.bgg@gmail.com \
    --cc=mmayer@broadcom.com \
    --cc=olof@lixom.net \
    --cc=rogerq@ti.com \
    --cc=soc@kernel.org \
    --cc=ssantosh@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=tony@atomide.com \
    --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).