From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Brian Norris <computersforpeace@gmail.com>,
Julia Lawall <Julia.Lawall@lip6.fr>
Cc: David Woodhouse <dwmw2@infradead.org>,
linux-mtd@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org,
Hartley Sweeten <hsweeten@visionengravers.com>,
Ryan Mallon <rmallon@gmail.com>, Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <kernel@pengutronix.de>,
Imre Kaloz <kaloz@openwrt.org>,
Krzysztof Halasa <khalasa@piap.pl>,
Tony Lindgren <tony@atomide.com>,
linux-omap@vger.kernel.org,
Alexander Clouter <alex@digriz.org.uk>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Gregory CLEMENT <gregory.clement@free-electrons.com>,
Jason Cooper <jason@lakedaemon.net>,
Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
Andrew Lunn <andrew@lunn.ch>, Daniel Mack <daniel@zonque.org>,
Haojian Zhuang <haojian.zhuang@gmail.com>,
Robert Jarzmik <robert.jarzmik@free.fr>,
Marek Vasut <marek.vasut@gmail.com>,
Steven Miao <realmz6@gmail.com>,
adi-buildroot-devel@lists.sourceforge.net,
Mikael Starvik <starvik@axis.com>,
Jesper Nilsson <jesper.nilsson@axis.com>,
linux-cris-kernel@axis.com, Josh Wu <josh.wu@atmel.com>,
Wan ZongShun <mcuos.com@gmail.com>,
Ezequiel Garcia <ezequiel.garcia@free-electrons.com>,
Maxim Levitsky <maximlevitsky@gmail.com>,
Kukjin Kim <kgene@kernel.org>,
Krzysztof Kozlowski <k.kozlowski@samsung.com>,
linux-samsung-soc@vger.kernel.org,
Maxime Ripard <maxime.ripard@free-electrons.com>,
Chen-Yu Tsai <wens@csie.org>,
linux-sunxi@googlegroups.com, Stefan Agner <stefan@agner.ch>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
devel@driverdev.osuosl.org
Subject: Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip
Date: Tue, 17 Nov 2015 09:38:36 +0100 [thread overview]
Message-ID: <20151117093836.052c86b5@bbrezillon> (raw)
In-Reply-To: <20151117030019.GY8456@google.com>
Hi Brian,
On Mon, 16 Nov 2015 19:00:19 -0800
Brian Norris <computersforpeace@gmail.com> wrote:
> Hi Boris,
>
> On Mon, Nov 16, 2015 at 02:37:47PM +0100, Boris Brezillon wrote:
> > struct nand_chip now embeds an mtd device. Patch all drivers to make use
> > of this mtd instance instead of using the instance embedded in their
> > private struct or dynamically allocated.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > Cc: Julia Lawall <Julia.Lawall@lip6.fr>
> > ---
> > Most of those changes were generate with this coccinelle script:
> > http://code.bulix.org/5vxuih-89429
>
> I appreciate that this patch is mostly autogenerated (a good thing for
> preventing errors!), but there are some issues that I don't think play
> out very well stylistically. Hopefully the cocci script can be improved
> to handle some of this?
>
> I'll try to point out a few snippets below.
>
> Also, in case others are interested in reviewing your cocci script
> directly, it might be better to paste it inline than to link to it.
> Given the size of the patch, I don't think people would mind a few dozen
> extra lines to show how it wsa generated. Or maybe stick some in the
> cover letter too, if you end up reusing them in several patches.
Sure, I'll paste the script directly in the commit message next time.
>
> > ---
> > drivers/mtd/nand/ams-delta.c | 13 ++--
> > drivers/mtd/nand/atmel_nand.c | 11 ++-
> > drivers/mtd/nand/au1550nd.c | 18 ++---
> > drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 1 -
> > drivers/mtd/nand/bcm47xxnflash/main.c | 7 +-
> > drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c | 2 +-
> > drivers/mtd/nand/bf5xx_nand.c | 14 ++--
> > drivers/mtd/nand/brcmnand/brcmnand.c | 11 ++-
> > drivers/mtd/nand/cafe_nand.c | 10 +--
> > drivers/mtd/nand/cmx270_nand.c | 11 ++-
> > drivers/mtd/nand/cs553x_nand.c | 13 ++--
> > drivers/mtd/nand/davinci_nand.c | 25 +++----
> > drivers/mtd/nand/denali.c | 61 +++++++++--------
> > drivers/mtd/nand/denali.h | 1 -
> > drivers/mtd/nand/diskonchip.c | 11 ++-
> > drivers/mtd/nand/docg4.c | 18 +++--
> > drivers/mtd/nand/fsl_elbc_nand.c | 22 +++---
> > drivers/mtd/nand/fsl_ifc_nand.c | 23 +++----
> > drivers/mtd/nand/fsl_upm.c | 26 +++----
> > drivers/mtd/nand/fsmc_nand.c | 59 +++++++++-------
> > drivers/mtd/nand/gpio.c | 16 ++---
> > drivers/mtd/nand/gpmi-nand/gpmi-lib.c | 2 +-
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 20 +++---
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.h | 1 -
> > drivers/mtd/nand/hisi504_nand.c | 11 ++-
> > drivers/mtd/nand/jz4740_nand.c | 9 ++-
> > drivers/mtd/nand/lpc32xx_mlc.c | 7 +-
> > drivers/mtd/nand/lpc32xx_slc.c | 7 +-
> > drivers/mtd/nand/mpc5121_nfc.c | 3 +-
> > drivers/mtd/nand/mxc_nand.c | 5 +-
> > drivers/mtd/nand/nandsim.c | 12 ++--
> > drivers/mtd/nand/ndfc.c | 22 +++---
> > drivers/mtd/nand/nuc900_nand.c | 21 +++---
> > drivers/mtd/nand/omap2.c | 94 +++++++++++++++-----------
> > drivers/mtd/nand/orion_nand.c | 4 +-
> > drivers/mtd/nand/pasemi_nand.c | 14 ++--
> > drivers/mtd/nand/plat_nand.c | 14 ++--
> > drivers/mtd/nand/pxa3xx_nand.c | 33 ++++-----
>
> ^^ BTW, this file already has a few conflicts. Sorry :(
>
> I'll try to keep any eye out for things like this once we're close to
> being able to apply something like this, so I don't merge unnecessary
> churn. But for now, I hope we can review this series, and it won't be
> too much work to rebase/resend once the bigger things have been worked
> out.
No problem, resolving this conflict was pretty easy.
>
> > drivers/mtd/nand/r852.c | 34 ++++------
> > drivers/mtd/nand/r852.h | 1 -
> > drivers/mtd/nand/s3c2410.c | 19 +++---
> > drivers/mtd/nand/sh_flctl.c | 8 +--
> > drivers/mtd/nand/sharpsl.c | 18 ++---
> > drivers/mtd/nand/socrates_nand.c | 5 +-
> > drivers/mtd/nand/sunxi_nand.c | 13 ++--
> > drivers/mtd/nand/tmio_nand.c | 7 +-
> > drivers/mtd/nand/txx9ndfmc.c | 3 +-
> > drivers/mtd/nand/vf610_nfc.c | 5 +-
> > include/linux/mtd/sh_flctl.h | 3 +-
> > 49 files changed, 383 insertions(+), 385 deletions(-)
> >
>
> ...
>
> > diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> > index f8aac0a..51748b4 100644
> > --- a/drivers/mtd/nand/atmel_nand.c
> > +++ b/drivers/mtd/nand/atmel_nand.c
>
> ...
>
> > @@ -318,7 +317,7 @@ static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> >
> > if (bank) {
> > /* Only for a 2k-page or lower flash, NFC can handle 2 banks */
> > - if (host->mtd.writesize > 2048)
> > + if (nand_to_mtd(&host->nand_chip)->writesize > 2048)
>
> (This isn't the worst one, but it just happens to be one of the first.)
> There are many cases where the typical style would be to declare a new
> variable at the top of the function, where you perform the
> macro/function-call to convert from one abstraction to another. Like
>
> static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> {
> struct mtd_info *mtd = nand_to_mtd(&hot->nand_chip);
> ...
>
> and then use it later. Can that be done very easily?
>
> > return -EINVAL;
> > nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1);
> > } else {
>
> ...
Honestly, I don't know how to do that with a coccinelle script, and it
will probably take me more time to find how to do it than addressing
those problems manually.
Julia, could you give us some hint?
>
> > diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
> > index 73fceb8..7e2a376 100644
> > --- a/drivers/mtd/nand/au1550nd.c
> > +++ b/drivers/mtd/nand/au1550nd.c
> > @@ -23,7 +23,6 @@
> >
> >
> > struct au1550nd_ctx {
> > - struct mtd_info info;
> > struct nand_chip chip;
> >
> > int cs;
> > @@ -197,7 +196,8 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
> >
> > static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
> > {
> > - struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
> > + struct au1550nd_ctx *ctx = container_of(mtd_to_nand(mtd),
> > + struct au1550nd_ctx, chip);
> > struct nand_chip *this = mtd_to_nand(mtd);
>
> This is another good example. It's a little awkward to do this at all
> (function call within a macro):
>
> container_of(mtd_to_nand(mtd), ...);
>
> but that's not unforgiveable. It's a bit worse, though, when followed by
> assigning the next field to the same thing:
>
> struct nand_chip *this = mtd_to_nand(mtd);
>
> i.e., this would be nicer to see as:
>
> struct nand_chip *this = mtd_to_nand(mtd);
> struct au1550nd_ctx *ctx = container_of(this,
> struct au1550nd_ctx, chip);
>
> Again, I'm not sure how best to automate this kind of transformation.
Yes, I noticed all those problems too, but as I said, I don't know how
to handle them using a coccinelle script.
Best Regards,
Boris
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
To: Brian Norris
<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
Cc: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Jonathan Corbet <corbet-T1hC0tSOHrs@public.gmane.org>,
linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Hartley Sweeten
<hsweeten-3FF4nKcrg1dE2c76skzGb0EOCMrvLtNR@public.gmane.org>,
Ryan Mallon <rmallon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Shawn Guo <shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Sascha Hauer <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
Imre Kaloz <kaloz-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>,
Krzysztof Halasa <khalasa-NlWvg49iv0c@public.gmane.org>,
Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>,
linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Alexander Clouter <alex-L4GPcECwBoDe9xe1eoZjHA@public.gmane.org>,
Thomas Petazzoni
<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
Gregory CLEMENT
<gregory.clement-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
Jason Cooper <jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org>,
Sebastian Hesselbarth
<sebastian.hesselbarth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org>,
Daniel Mack <daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>,
Haojian Zhuang
<haojian.zhuang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Robert Jarzmik <robert.jarzmik-GANU6spQydw@public.gmane.org>,
Marek
Subject: Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip
Date: Tue, 17 Nov 2015 09:38:36 +0100 [thread overview]
Message-ID: <20151117093836.052c86b5@bbrezillon> (raw)
In-Reply-To: <20151117030019.GY8456-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Hi Brian,
On Mon, 16 Nov 2015 19:00:19 -0800
Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi Boris,
>
> On Mon, Nov 16, 2015 at 02:37:47PM +0100, Boris Brezillon wrote:
> > struct nand_chip now embeds an mtd device. Patch all drivers to make use
> > of this mtd instance instead of using the instance embedded in their
> > private struct or dynamically allocated.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> > Cc: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
> > ---
> > Most of those changes were generate with this coccinelle script:
> > http://code.bulix.org/5vxuih-89429
>
> I appreciate that this patch is mostly autogenerated (a good thing for
> preventing errors!), but there are some issues that I don't think play
> out very well stylistically. Hopefully the cocci script can be improved
> to handle some of this?
>
> I'll try to point out a few snippets below.
>
> Also, in case others are interested in reviewing your cocci script
> directly, it might be better to paste it inline than to link to it.
> Given the size of the patch, I don't think people would mind a few dozen
> extra lines to show how it wsa generated. Or maybe stick some in the
> cover letter too, if you end up reusing them in several patches.
Sure, I'll paste the script directly in the commit message next time.
>
> > ---
> > drivers/mtd/nand/ams-delta.c | 13 ++--
> > drivers/mtd/nand/atmel_nand.c | 11 ++-
> > drivers/mtd/nand/au1550nd.c | 18 ++---
> > drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 1 -
> > drivers/mtd/nand/bcm47xxnflash/main.c | 7 +-
> > drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c | 2 +-
> > drivers/mtd/nand/bf5xx_nand.c | 14 ++--
> > drivers/mtd/nand/brcmnand/brcmnand.c | 11 ++-
> > drivers/mtd/nand/cafe_nand.c | 10 +--
> > drivers/mtd/nand/cmx270_nand.c | 11 ++-
> > drivers/mtd/nand/cs553x_nand.c | 13 ++--
> > drivers/mtd/nand/davinci_nand.c | 25 +++----
> > drivers/mtd/nand/denali.c | 61 +++++++++--------
> > drivers/mtd/nand/denali.h | 1 -
> > drivers/mtd/nand/diskonchip.c | 11 ++-
> > drivers/mtd/nand/docg4.c | 18 +++--
> > drivers/mtd/nand/fsl_elbc_nand.c | 22 +++---
> > drivers/mtd/nand/fsl_ifc_nand.c | 23 +++----
> > drivers/mtd/nand/fsl_upm.c | 26 +++----
> > drivers/mtd/nand/fsmc_nand.c | 59 +++++++++-------
> > drivers/mtd/nand/gpio.c | 16 ++---
> > drivers/mtd/nand/gpmi-nand/gpmi-lib.c | 2 +-
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 20 +++---
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.h | 1 -
> > drivers/mtd/nand/hisi504_nand.c | 11 ++-
> > drivers/mtd/nand/jz4740_nand.c | 9 ++-
> > drivers/mtd/nand/lpc32xx_mlc.c | 7 +-
> > drivers/mtd/nand/lpc32xx_slc.c | 7 +-
> > drivers/mtd/nand/mpc5121_nfc.c | 3 +-
> > drivers/mtd/nand/mxc_nand.c | 5 +-
> > drivers/mtd/nand/nandsim.c | 12 ++--
> > drivers/mtd/nand/ndfc.c | 22 +++---
> > drivers/mtd/nand/nuc900_nand.c | 21 +++---
> > drivers/mtd/nand/omap2.c | 94 +++++++++++++++-----------
> > drivers/mtd/nand/orion_nand.c | 4 +-
> > drivers/mtd/nand/pasemi_nand.c | 14 ++--
> > drivers/mtd/nand/plat_nand.c | 14 ++--
> > drivers/mtd/nand/pxa3xx_nand.c | 33 ++++-----
>
> ^^ BTW, this file already has a few conflicts. Sorry :(
>
> I'll try to keep any eye out for things like this once we're close to
> being able to apply something like this, so I don't merge unnecessary
> churn. But for now, I hope we can review this series, and it won't be
> too much work to rebase/resend once the bigger things have been worked
> out.
No problem, resolving this conflict was pretty easy.
>
> > drivers/mtd/nand/r852.c | 34 ++++------
> > drivers/mtd/nand/r852.h | 1 -
> > drivers/mtd/nand/s3c2410.c | 19 +++---
> > drivers/mtd/nand/sh_flctl.c | 8 +--
> > drivers/mtd/nand/sharpsl.c | 18 ++---
> > drivers/mtd/nand/socrates_nand.c | 5 +-
> > drivers/mtd/nand/sunxi_nand.c | 13 ++--
> > drivers/mtd/nand/tmio_nand.c | 7 +-
> > drivers/mtd/nand/txx9ndfmc.c | 3 +-
> > drivers/mtd/nand/vf610_nfc.c | 5 +-
> > include/linux/mtd/sh_flctl.h | 3 +-
> > 49 files changed, 383 insertions(+), 385 deletions(-)
> >
>
> ...
>
> > diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> > index f8aac0a..51748b4 100644
> > --- a/drivers/mtd/nand/atmel_nand.c
> > +++ b/drivers/mtd/nand/atmel_nand.c
>
> ...
>
> > @@ -318,7 +317,7 @@ static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> >
> > if (bank) {
> > /* Only for a 2k-page or lower flash, NFC can handle 2 banks */
> > - if (host->mtd.writesize > 2048)
> > + if (nand_to_mtd(&host->nand_chip)->writesize > 2048)
>
> (This isn't the worst one, but it just happens to be one of the first.)
> There are many cases where the typical style would be to declare a new
> variable at the top of the function, where you perform the
> macro/function-call to convert from one abstraction to another. Like
>
> static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> {
> struct mtd_info *mtd = nand_to_mtd(&hot->nand_chip);
> ...
>
> and then use it later. Can that be done very easily?
>
> > return -EINVAL;
> > nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1);
> > } else {
>
> ...
Honestly, I don't know how to do that with a coccinelle script, and it
will probably take me more time to find how to do it than addressing
those problems manually.
Julia, could you give us some hint?
>
> > diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
> > index 73fceb8..7e2a376 100644
> > --- a/drivers/mtd/nand/au1550nd.c
> > +++ b/drivers/mtd/nand/au1550nd.c
> > @@ -23,7 +23,6 @@
> >
> >
> > struct au1550nd_ctx {
> > - struct mtd_info info;
> > struct nand_chip chip;
> >
> > int cs;
> > @@ -197,7 +196,8 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
> >
> > static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
> > {
> > - struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
> > + struct au1550nd_ctx *ctx = container_of(mtd_to_nand(mtd),
> > + struct au1550nd_ctx, chip);
> > struct nand_chip *this = mtd_to_nand(mtd);
>
> This is another good example. It's a little awkward to do this at all
> (function call within a macro):
>
> container_of(mtd_to_nand(mtd), ...);
>
> but that's not unforgiveable. It's a bit worse, though, when followed by
> assigning the next field to the same thing:
>
> struct nand_chip *this = mtd_to_nand(mtd);
>
> i.e., this would be nicer to see as:
>
> struct nand_chip *this = mtd_to_nand(mtd);
> struct au1550nd_ctx *ctx = container_of(this,
> struct au1550nd_ctx, chip);
>
> Again, I'm not sure how best to automate this kind of transformation.
Yes, I noticed all those problems too, but as I said, I don't know how
to handle them using a coccinelle script.
Best Regards,
Boris
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
WARNING: multiple messages have this Message-ID (diff)
From: boris.brezillon@free-electrons.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip
Date: Tue, 17 Nov 2015 09:38:36 +0100 [thread overview]
Message-ID: <20151117093836.052c86b5@bbrezillon> (raw)
In-Reply-To: <20151117030019.GY8456@google.com>
Hi Brian,
On Mon, 16 Nov 2015 19:00:19 -0800
Brian Norris <computersforpeace@gmail.com> wrote:
> Hi Boris,
>
> On Mon, Nov 16, 2015 at 02:37:47PM +0100, Boris Brezillon wrote:
> > struct nand_chip now embeds an mtd device. Patch all drivers to make use
> > of this mtd instance instead of using the instance embedded in their
> > private struct or dynamically allocated.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > Cc: Julia Lawall <Julia.Lawall@lip6.fr>
> > ---
> > Most of those changes were generate with this coccinelle script:
> > http://code.bulix.org/5vxuih-89429
>
> I appreciate that this patch is mostly autogenerated (a good thing for
> preventing errors!), but there are some issues that I don't think play
> out very well stylistically. Hopefully the cocci script can be improved
> to handle some of this?
>
> I'll try to point out a few snippets below.
>
> Also, in case others are interested in reviewing your cocci script
> directly, it might be better to paste it inline than to link to it.
> Given the size of the patch, I don't think people would mind a few dozen
> extra lines to show how it wsa generated. Or maybe stick some in the
> cover letter too, if you end up reusing them in several patches.
Sure, I'll paste the script directly in the commit message next time.
>
> > ---
> > drivers/mtd/nand/ams-delta.c | 13 ++--
> > drivers/mtd/nand/atmel_nand.c | 11 ++-
> > drivers/mtd/nand/au1550nd.c | 18 ++---
> > drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h | 1 -
> > drivers/mtd/nand/bcm47xxnflash/main.c | 7 +-
> > drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c | 2 +-
> > drivers/mtd/nand/bf5xx_nand.c | 14 ++--
> > drivers/mtd/nand/brcmnand/brcmnand.c | 11 ++-
> > drivers/mtd/nand/cafe_nand.c | 10 +--
> > drivers/mtd/nand/cmx270_nand.c | 11 ++-
> > drivers/mtd/nand/cs553x_nand.c | 13 ++--
> > drivers/mtd/nand/davinci_nand.c | 25 +++----
> > drivers/mtd/nand/denali.c | 61 +++++++++--------
> > drivers/mtd/nand/denali.h | 1 -
> > drivers/mtd/nand/diskonchip.c | 11 ++-
> > drivers/mtd/nand/docg4.c | 18 +++--
> > drivers/mtd/nand/fsl_elbc_nand.c | 22 +++---
> > drivers/mtd/nand/fsl_ifc_nand.c | 23 +++----
> > drivers/mtd/nand/fsl_upm.c | 26 +++----
> > drivers/mtd/nand/fsmc_nand.c | 59 +++++++++-------
> > drivers/mtd/nand/gpio.c | 16 ++---
> > drivers/mtd/nand/gpmi-nand/gpmi-lib.c | 2 +-
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 20 +++---
> > drivers/mtd/nand/gpmi-nand/gpmi-nand.h | 1 -
> > drivers/mtd/nand/hisi504_nand.c | 11 ++-
> > drivers/mtd/nand/jz4740_nand.c | 9 ++-
> > drivers/mtd/nand/lpc32xx_mlc.c | 7 +-
> > drivers/mtd/nand/lpc32xx_slc.c | 7 +-
> > drivers/mtd/nand/mpc5121_nfc.c | 3 +-
> > drivers/mtd/nand/mxc_nand.c | 5 +-
> > drivers/mtd/nand/nandsim.c | 12 ++--
> > drivers/mtd/nand/ndfc.c | 22 +++---
> > drivers/mtd/nand/nuc900_nand.c | 21 +++---
> > drivers/mtd/nand/omap2.c | 94 +++++++++++++++-----------
> > drivers/mtd/nand/orion_nand.c | 4 +-
> > drivers/mtd/nand/pasemi_nand.c | 14 ++--
> > drivers/mtd/nand/plat_nand.c | 14 ++--
> > drivers/mtd/nand/pxa3xx_nand.c | 33 ++++-----
>
> ^^ BTW, this file already has a few conflicts. Sorry :(
>
> I'll try to keep any eye out for things like this once we're close to
> being able to apply something like this, so I don't merge unnecessary
> churn. But for now, I hope we can review this series, and it won't be
> too much work to rebase/resend once the bigger things have been worked
> out.
No problem, resolving this conflict was pretty easy.
>
> > drivers/mtd/nand/r852.c | 34 ++++------
> > drivers/mtd/nand/r852.h | 1 -
> > drivers/mtd/nand/s3c2410.c | 19 +++---
> > drivers/mtd/nand/sh_flctl.c | 8 +--
> > drivers/mtd/nand/sharpsl.c | 18 ++---
> > drivers/mtd/nand/socrates_nand.c | 5 +-
> > drivers/mtd/nand/sunxi_nand.c | 13 ++--
> > drivers/mtd/nand/tmio_nand.c | 7 +-
> > drivers/mtd/nand/txx9ndfmc.c | 3 +-
> > drivers/mtd/nand/vf610_nfc.c | 5 +-
> > include/linux/mtd/sh_flctl.h | 3 +-
> > 49 files changed, 383 insertions(+), 385 deletions(-)
> >
>
> ...
>
> > diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> > index f8aac0a..51748b4 100644
> > --- a/drivers/mtd/nand/atmel_nand.c
> > +++ b/drivers/mtd/nand/atmel_nand.c
>
> ...
>
> > @@ -318,7 +317,7 @@ static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> >
> > if (bank) {
> > /* Only for a 2k-page or lower flash, NFC can handle 2 banks */
> > - if (host->mtd.writesize > 2048)
> > + if (nand_to_mtd(&host->nand_chip)->writesize > 2048)
>
> (This isn't the worst one, but it just happens to be one of the first.)
> There are many cases where the typical style would be to declare a new
> variable at the top of the function, where you perform the
> macro/function-call to convert from one abstraction to another. Like
>
> static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank)
> {
> struct mtd_info *mtd = nand_to_mtd(&hot->nand_chip);
> ...
>
> and then use it later. Can that be done very easily?
>
> > return -EINVAL;
> > nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1);
> > } else {
>
> ...
Honestly, I don't know how to do that with a coccinelle script, and it
will probably take me more time to find how to do it than addressing
those problems manually.
Julia, could you give us some hint?
>
> > diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
> > index 73fceb8..7e2a376 100644
> > --- a/drivers/mtd/nand/au1550nd.c
> > +++ b/drivers/mtd/nand/au1550nd.c
> > @@ -23,7 +23,6 @@
> >
> >
> > struct au1550nd_ctx {
> > - struct mtd_info info;
> > struct nand_chip chip;
> >
> > int cs;
> > @@ -197,7 +196,8 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
> >
> > static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
> > {
> > - struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
> > + struct au1550nd_ctx *ctx = container_of(mtd_to_nand(mtd),
> > + struct au1550nd_ctx, chip);
> > struct nand_chip *this = mtd_to_nand(mtd);
>
> This is another good example. It's a little awkward to do this at all
> (function call within a macro):
>
> container_of(mtd_to_nand(mtd), ...);
>
> but that's not unforgiveable. It's a bit worse, though, when followed by
> assigning the next field to the same thing:
>
> struct nand_chip *this = mtd_to_nand(mtd);
>
> i.e., this would be nicer to see as:
>
> struct nand_chip *this = mtd_to_nand(mtd);
> struct au1550nd_ctx *ctx = container_of(this,
> struct au1550nd_ctx, chip);
>
> Again, I'm not sure how best to automate this kind of transformation.
Yes, I noticed all those problems too, but as I said, I don't know how
to handle them using a coccinelle script.
Best Regards,
Boris
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
next prev parent reply other threads:[~2015-11-17 8:38 UTC|newest]
Thread overview: 114+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 13:37 [PATCH 00/27] mtd: nand: refactor the NAND subsystem (part 1) Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 01/27] mtd: nand: fix drivers abusing mtd->priv Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-19 19:07 ` Brian Norris
2015-11-19 19:07 ` Brian Norris
2015-11-19 19:07 ` Brian Norris
2015-11-16 13:37 ` [PATCH 02/27] mtd: nand: add an mtd_to_nand() helper Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-19 19:19 ` Brian Norris
2015-11-19 19:19 ` Brian Norris
2015-11-19 19:19 ` Brian Norris
2015-11-16 13:37 ` [PATCH 03/27] mtd: nand: update examples in the documentation to use mtd_to_nand() Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-19 19:22 ` Brian Norris
2015-11-19 19:22 ` Brian Norris
2015-11-19 19:22 ` Brian Norris
2015-11-16 13:37 ` [PATCH 04/27] ARM: nand: make use of mtd_to_nand() where appropriate Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 05/27] blackfin: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 06/27] cris: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 07/27] mips: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 08/27] sh: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 09/27] mtd: nand: make use of mtd_to_nand() in NAND core code Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 10/27] mtd: nand: make use of mtd_to_nand() in NAND drivers Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 11/27] staging: mt29f_spinand: make use of mtd_to_nand() Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 12/27] mtd: nand: embed an mtd_info structure into nand_chip Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 13/27] mtd: nand: add nand_to_mtd() helper Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-17 3:00 ` Brian Norris
2015-11-17 3:00 ` Brian Norris
2015-11-17 3:00 ` Brian Norris
2015-11-17 8:38 ` Boris Brezillon [this message]
2015-11-17 8:38 ` Boris Brezillon
2015-11-17 8:38 ` Boris Brezillon
2015-11-17 9:05 ` Julia Lawall
2015-11-17 9:05 ` Julia Lawall
2015-11-17 9:05 ` Julia Lawall
2015-11-17 14:22 ` Boris Brezillon
2015-11-17 14:22 ` Boris Brezillon
2015-11-17 14:22 ` Boris Brezillon
2015-11-17 15:32 ` Julia Lawall
2015-11-17 15:32 ` Julia Lawall
2015-11-17 15:32 ` Julia Lawall
2015-11-16 13:37 ` [PATCH 15/27] mtd: nand: update the documentation to reflect framework changes Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 16/27] staging: mt29f_spinand: use the mtd instance embedded in struct nand_chip Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 17/27] cris: nand: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 18/27] mtd: nand: update mtd_to_nand() Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-17 3:03 ` Brian Norris
2015-11-17 3:03 ` Brian Norris
2015-11-17 3:03 ` Brian Norris
2015-11-17 8:26 ` Boris Brezillon
2015-11-17 8:26 ` Boris Brezillon
2015-11-17 8:26 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 19/27] mtd: nand: remove useless mtd->priv = chip assignments Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 20/27] cris: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 21/27] staging: mt29f_spinand: remove useless mtd->priv = chip assignment Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 22/27] mtd: nand: simplify nand_dt_init() usage Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 23/27] mtd: nand: kill the chip->flash_node field Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 24/27] mtd: nand: add helpers to access ->priv Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 25/27] ARM: make use of nand_set/get_controller_data() helpers Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` [PATCH 26/27] mtd: nand: " Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:37 ` Boris Brezillon
2015-11-16 13:38 ` [PATCH 27/27] staging: mt29f_spinand: " Boris Brezillon
2015-11-16 13:38 ` Boris Brezillon
2015-11-16 13:38 ` Boris Brezillon
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=20151117093836.052c86b5@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=Julia.Lawall@lip6.fr \
--cc=adi-buildroot-devel@lists.sourceforge.net \
--cc=alex@digriz.org.uk \
--cc=andrew@lunn.ch \
--cc=computersforpeace@gmail.com \
--cc=corbet@lwn.net \
--cc=daniel@zonque.org \
--cc=devel@driverdev.osuosl.org \
--cc=dwmw2@infradead.org \
--cc=ezequiel.garcia@free-electrons.com \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@free-electrons.com \
--cc=haojian.zhuang@gmail.com \
--cc=hsweeten@visionengravers.com \
--cc=jason@lakedaemon.net \
--cc=jesper.nilsson@axis.com \
--cc=josh.wu@atmel.com \
--cc=k.kozlowski@samsung.com \
--cc=kaloz@openwrt.org \
--cc=kernel@pengutronix.de \
--cc=kgene@kernel.org \
--cc=khalasa@piap.pl \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-cris-kernel@axis.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=marek.vasut@gmail.com \
--cc=maxime.ripard@free-electrons.com \
--cc=maximlevitsky@gmail.com \
--cc=mcuos.com@gmail.com \
--cc=realmz6@gmail.com \
--cc=rmallon@gmail.com \
--cc=robert.jarzmik@free.fr \
--cc=sebastian.hesselbarth@gmail.com \
--cc=shawnguo@kernel.org \
--cc=starvik@axis.com \
--cc=stefan@agner.ch \
--cc=thomas.petazzoni@free-electrons.com \
--cc=tony@atomide.com \
--cc=wens@csie.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.