Skip to contentSkip to conversation

kfifo: initialize fifo accordingly to C99 standard

PATCH RESEND In review Andy Shevchenko 3 participants 6 messages Nov 21, 2012 – Nov 29, 2012 Kfifo

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 kfifo: initialize fifo accordingly to C99 standard

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

Cc Stefani Seibold <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 include/linux/kfifo.h |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
include/linux/kfifo.h +1 -4
index 10308c6..3de51a1 100644
@@ -155,8 +155,7 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
 #define DEFINE_KFIFO(fifo, type, size) \
 	DECLARE_KFIFO(fifo, type, size) = \
 	(typeof(fifo)) { \
-		{ \
-			{ \
+		.kfifo = { \
 			.in	= 0, \
 			.out	= 0, \
 			.mask	= __is_kfifo_ptr(&(fifo)) ? \
@@ -166,11 +165,9 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
 			.data	= __is_kfifo_ptr(&(fifo)) ? \
 				NULL : \
 				(fifo).buf, \
-			} \
 		} \
 	}
 
-
 static inline unsigned int __must_check
 __kfifo_uint_must_check_helper(unsigned int val)
 {
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · On Wed, 21 Nov 2012 16:31:11 +0200 Andy Shevchenko…

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

I see no such warning. When fixing warnings or compilation errors, please always quote the compiler output in the changelog.

#2 lore raw
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Wed, 21 Nov 2012 16:31:11 +0200 Andy Shevchenko…

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

I see no such warning. When fixing warnings or compilation errors, please always quote the compiler output in the changelog.

Oh, I did wrong assumption. However, it looks like linux-stable 3.0.y is affected;

CC [M] samples/kfifo/inttype-example.o
samples/kfifo/inttype-example.c:44:506: warning: missing initializer [-Wmissing-field-initializers] samples/kfifo/inttype-example.c:44:506: warning: (near initialization for ‘(anonymous).buf’) [-Wmissing-field-initializers]

And it seems that my solution not the one which is used in linux-next.

gcc (Debian 4.7.2-2) 4.7.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 16 lines · Andy Shevchenko
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Wed, 21 Nov 2012 16:31:11 +0200 Andy Shevchenko…

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

I see no such warning. When fixing warnings or compilation errors, please always quote the compiler output in the changelog.

Oh, I did wrong assumption. However, it looks like linux-stable 3.0.y is affected;

Quoted 7 lines

CC [M] samples/kfifo/inttype-example.o
samples/kfifo/inttype-example.c:44:506: warning: missing initializer [-Wmissing-field-initializers] samples/kfifo/inttype-example.c:44:506: warning: (near initialization for ‘(anonymous).buf’) [-Wmissing-field-initializers]

And it seems that my solution not the one which is used in linux-next.

Okay. I found the commit f858ee8b8cd8c216ddbeefae6e047ce90cae9cca ("kbuild: disable -Wmissing-field-initializers for W=1") hides the warning.
After reverting this one I get the same warning as before:

CC [M] samples/kfifo/inttype-example.o
samples/kfifo/inttype-example.c:44:506: warning: missing initializer [-Wmissing-field-initializers] samples/kfifo/inttype-example.c:44:506: warning: (near initialization for ‘(anonymous).buf’) [-Wmissing-field-initializers]

Quoted 1 line

gcc (Debian 4.7.2-2) 4.7.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · On Wed, 21 Nov 2012 16:31:11 +0200 Andy Shevchenko…

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

This doesn't actually work:

drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'kfifo' specified in initializer drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'in' specified in initializer drivers/pci/pcie/aer/aerdrv_core.c:573: warning: missing braces around initializer drivers/pci/pcie/aer/aerdrv_core.c:573: warning: (near initialization for '(anonymous).<anonymous>.kfifo') drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'out' specified in initializer

gcc-4.4.4.

#5 lore raw
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Wed, 21 Nov 2012 16:31:11 +0200 Andy Shevchenko…

When build a kernel with "make W=1" we will get a warning about missing initializer. It comes from kfifo usage style. The DEFINE_KFIFO macro doesn't initialize the buf[] field of the fifo structure. So, using C99 style helps in such case.

Quoted 7 lines

This doesn't actually work:

drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'kfifo' specified in initializer drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'in' specified in initializer drivers/pci/pcie/aer/aerdrv_core.c:573: warning: missing braces around initializer drivers/pci/pcie/aer/aerdrv_core.c:573: warning: (near initialization for '(anonymous).<anonymous>.kfifo') drivers/pci/pcie/aer/aerdrv_core.c:573: error: unknown field 'out' specified in initializer

It's strange. After I reverted the mentioned commit (about Makefile.build) and applied my patch I got no warnings
CC [M] samples/kfifo/inttype-example.o
CC [M] samples/kfifo/record-example.o

Quoted 1 line

gcc-4.4.4.

gcc 4.7.2 might be the case.

Signature · 2 lines
With Best Regards,
Andy Shevchenko