Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1270984

Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip

From Julia Lawall <julia.lawall@lip6.fr>
Newsgroups linux.kernel
Subject Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct nand_chip
Date 2015-11-17 10:10 +0100
Message-ID <qvKr0-31p-29@gated-at.bofh.it> (permalink)
References <qvsaK-7Us-5@gated-at.bofh.it> <qvskr-7Yr-55@gated-at.bofh.it> <qvEOD-7G2-27@gated-at.bofh.it> <qvJXY-2zA-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


> > (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?

Probably something like the following would be easiest.  You can just run
it after your other transformations:

@r exists@
identifier f;
expression e;
@@

f(...) { <+...  nand_to_mtd(e) ...+> }

@@
identifier r.f;
expression r.e;
@@

f(...) {
+ struct mtd_info *mtd = nand_to_mtd(e);
...
}

This won't work if there is more than one possible value of e.  If that is
likely, then I could come up with something more complex.  It also assumes
that you want to convert all such calls.  If you only want to convert calls
that occur in a particular context, eg a field reference, then you could
enhance the pattern inside the <+... ...+> in the first rule.

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/27] mtd: nand: refactor the NAND subsystem (part 1) Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-16 15:00 +0100
  Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct  nand_chip Brian Norris <computersforpeace@gmail.com> - 2015-11-17 04:10 +0100
    Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in  struct nand_chip Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-17 09:40 +0100
      Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct  nand_chip Julia Lawall <julia.lawall@lip6.fr> - 2015-11-17 10:10 +0100
        Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in  struct nand_chip Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-11-17 15:30 +0100
          Re: [PATCH 14/27] mtd: nand: use the mtd instance embedded in struct  nand_chip Julia Lawall <julia.lawall@lip6.fr> - 2015-11-17 16:40 +0100

csiph-web