mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: ftdi-elan: Fix undefined behaviour
@ 2022-04-01  7:57 cgel.zte
  2022-04-01  9:10 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2022-04-01  7:57 UTC (permalink / raw)
  To: gregkh
  Cc: weiyongjun1, colin.king, lv.ruyi, linux-usb, linux-kernel, Zeal Robot

From: Lv Ruyi <lv.ruyi@zte.com.cn>

The use of zero-sized array causes undefined behaviour when it is not
the last member in a structure. As it happens to be in this case.

Also, the current code makes use of a language extension to the C90
standard, but the preferred mechanism to declare variable-length
types such as this one is a flexible array member, introduced in
C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last. Which is beneficial
to cultivate a high-quality code.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 drivers/usb/misc/ftdi-elan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 6c38c62d29b2..e818d2ed6831 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -171,7 +171,6 @@ struct usb_ftdi {
 	struct delayed_work command_work;
 	struct delayed_work respond_work;
 	struct u132_platform_data platform_data;
-	struct resource resources[0];
 	struct platform_device platform_dev;
 	unsigned char *bulk_in_buffer;
 	size_t bulk_in_size;
@@ -185,6 +184,7 @@ struct usb_ftdi {
 	int expected;
 	int received;
 	int ed_found;
+	struct resource resources[];
 };
 #define kref_to_usb_ftdi(d) container_of(d, struct usb_ftdi, kref)
 #define platform_device_to_usb_ftdi(d) container_of(d, struct usb_ftdi, \
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-01  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01  7:57 [PATCH] usb: ftdi-elan: Fix undefined behaviour cgel.zte
2022-04-01  9:10 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome