diff mbox series

[2/2] mtd: rawnand: use unnamed union in struct nand_op_parser_pattern_elem

Message ID 1548142975-14219-3-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series mtd: nand: use unnamed union field | expand

Commit Message

Masahiro Yamada Jan. 22, 2019, 7:42 a.m. UTC
Although drivers do not directly get access to the private data of
instruction patterns, let's use unnamed union field to be consistent
with nand_op_instr.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 drivers/mtd/nand/raw/nand_base.c | 12 ++++++------
 include/linux/mtd/rawnand.h      |  8 ++++----
 2 files changed, 10 insertions(+), 10 deletions(-)

-- 
2.7.4


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Comments

Masahiro Yamada Jan. 22, 2019, 8:55 a.m. UTC | #1
On Tue, Jan 22, 2019 at 5:33 PM Boris Brezillon <bbrezillon@kernel.org> wrote:
>

> On Tue, 22 Jan 2019 09:08:30 +0100

> Miquel Raynal <miquel.raynal@bootlin.com> wrote:

>

> > Hi Masahiro,

> >

> > Masahiro Yamada <yamada.masahiro@socionext.com> wrote on Tue, 22 Jan

> > 2019 17:00:54 +0900:

> >

> > > On Tue, Jan 22, 2019 at 4:50 PM Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> > > >

> > > > Hi Masahiro,

> > > >

> > > > Masahiro Yamada <yamada.masahiro@socionext.com> wrote on Tue, 22 Jan

> > > > 2019 16:42:55 +0900:

> > > >

> > > > > Although drivers do not directly get access to the private data of

> > > > > instruction patterns, let's use unnamed union field to be consistent

> > > > > with nand_op_instr.

> > > > >

> > > >

> > > > Actually this is how we wrote it the first time. Then we got robots

> > > > reporting that anonymous unions where not allowed with older (still

> > > > supported) GCC versions and I had to do this:

> > > >

> > > >

> > > > commit c1a72e2dbb4abb90bd408480d7c48ba40cb799ce

> > > > Author: Miquel Raynal <miquel.raynal@free-electrons.com>

> > > > Date:   Fri Jan 19 19:11:27 2018 +0100

> > > >

> > > >     mtd: nand: Fix build issues due to an anonymous union

> > > >

> > > >     GCC-4.4.4 raises errors when assigning a parameter in an anonymous

> > > >     union, leading to this kind of failure:

> > > >

> > > >     drivers/mtd/nand/marvell_nand.c:1936:

> > > >         warning: missing braces around initializer

> > > >         warning: (near initialization for '(anonymous)[1].<anonymous>')

> > > >         error: unknown field 'data' specified in initializer

> > > >         error: unknown field 'addr' specified in initializer

> > > >

> > > >     Work around the situation by naming these unions.

> > > >

> > > >     Fixes: 8878b126df76 ("mtd: nand: add ->exec_op() implementation")

> > > >     Reported-by: Andrew Morton <akpm@linux-foundation.org>

> > > >     Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>

> > > >     Tested-by: Andrew Morton <akpm@linux-foundation.org>

> > > >     Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> > > >

> > >

> > >

> > > Hmm, how come Andrew's compiler was fine with the following?

> > >

> > > struct nand_flash_dev {

> > >         char *name;

> > >         union {

> > >                 struct {

> > >                         uint8_t mfr_id;

> > >                         uint8_t dev_id;

> > >                 };

> > >                 uint8_t id[NAND_MAX_ID_LEN];

> > >         };

> > >         unsigned int pagesize;

> > >         ...

> > > };

> > >

> >

> > It is probably not :)

>

> It was compile fine. I don't know all the subtleties, but maybe it's

> because ->id[] is a base type and not a struct.

>

> >

> > >

> > >

> > > The current minimum version is GCC 4.6

> > > (commit cafa0010cd51fb7)

> > > but I am not sure if this restriction is remaining.

> > >

> >

> > That's right, can you please test if this limitation is still

> > ongoing wit GCC 4.6?

>

> I have a more important question: why should we go bad back to unnamed

> unions? Why is that a problem to have a named union? Sure, we initially

> started with an unnamed ones because it made lines shorter, but now that

> we switched to named unions I don't see the point of going back and

> patching all drivers again (at the risk of seeing this problem appear

> again when compiled with an old compiler version).



I did not know commit c1a72e2dbb4.

We can drop the union name if and only if we are "100% sure" about the safety.
I cannot prove it.

Generally, 0day bot helps us.
Last time, nobody noticed the build error until Andrew reported it.
So, we cannot count on the 0day bot.


Less praise for this work.
Lots of criticism once I break it.

So, I have no reason to take the risk.



--
Best Regards
Masahiro Yamada

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 3b620cd..d29de69 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -1995,24 +1995,24 @@  nand_op_parser_must_split_instr(const struct nand_op_parser_pattern_elem *pat,
 {
 	switch (pat->type) {
 	case NAND_OP_ADDR_INSTR:
-		if (!pat->ctx.addr.maxcycles)
+		if (!pat->addr.maxcycles)
 			break;
 
 		if (instr->addr.naddrs - *start_offset >
-		    pat->ctx.addr.maxcycles) {
-			*start_offset += pat->ctx.addr.maxcycles;
+		    pat->addr.maxcycles) {
+			*start_offset += pat->addr.maxcycles;
 			return true;
 		}
 		break;
 
 	case NAND_OP_DATA_IN_INSTR:
 	case NAND_OP_DATA_OUT_INSTR:
-		if (!pat->ctx.data.maxlen)
+		if (!pat->data.maxlen)
 			break;
 
 		if (instr->data.len - *start_offset >
-		    pat->ctx.data.maxlen) {
-			*start_offset += pat->ctx.data.maxlen;
+		    pat->data.maxlen) {
+			*start_offset += pat->data.maxlen;
 			return true;
 		}
 		break;
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index b606ed3..7abb605 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -741,7 +741,7 @@  struct nand_op_parser_pattern_elem {
 	union {
 		struct nand_op_parser_addr_constraints addr;
 		struct nand_op_parser_data_constraints data;
-	} ctx;
+	};
 };
 
 #define NAND_OP_PARSER_PAT_CMD_ELEM(_opt)			\
@@ -754,21 +754,21 @@  struct nand_op_parser_pattern_elem {
 	{							\
 		.type = NAND_OP_ADDR_INSTR,			\
 		.optional = _opt,				\
-		.ctx.addr.maxcycles = _maxcycles,		\
+		.addr.maxcycles = _maxcycles,			\
 	}
 
 #define NAND_OP_PARSER_PAT_DATA_IN_ELEM(_opt, _maxlen)		\
 	{							\
 		.type = NAND_OP_DATA_IN_INSTR,			\
 		.optional = _opt,				\
-		.ctx.data.maxlen = _maxlen,			\
+		.data.maxlen = _maxlen,				\
 	}
 
 #define NAND_OP_PARSER_PAT_DATA_OUT_ELEM(_opt, _maxlen)		\
 	{							\
 		.type = NAND_OP_DATA_OUT_INSTR,			\
 		.optional = _opt,				\
-		.ctx.data.maxlen = _maxlen,			\
+		.data.maxlen = _maxlen,				\
 	}
 
 #define NAND_OP_PARSER_PAT_WAITRDY_ELEM(_opt)			\