mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: cgel.zte@gmail.com
Cc: weiyongjun1@huawei.com, colin.king@intel.com, lv.ruyi@zte.com.cn,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] usb: ftdi-elan: Fix undefined behaviour
Date: Fri, 1 Apr 2022 11:10:19 +0200	[thread overview]
Message-ID: <YkbBe823hCSNzZ8X@kroah.com> (raw)
In-Reply-To: <20220401075747.2407536-1-lv.ruyi@zte.com.cn>

On Fri, Apr 01, 2022 at 07:57:47AM +0000, cgel.zte@gmail.com wrote:
> 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.

What do you mean by "undefined behavior" here?  How is this working now?

> 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[];
> };

gcc and clang both support [0] for a very long time so this isn't an
issue.

> 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[];

How did you test and verify that this change is correct?

thanks,

greg k-h

      reply	other threads:[~2022-04-01  9:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01  7:57 cgel.zte
2022-04-01  9:10 ` Greg KH [this message]

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=YkbBe823hCSNzZ8X@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=cgel.zte@gmail.com \
    --cc=colin.king@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lv.ruyi@zte.com.cn \
    --cc=weiyongjun1@huawei.com \
    --cc=zealci@zte.com.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome