mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: host: replace zero-length array with flexible-array member
@ 2022-04-01  8:03 cgel.zte
  2022-04-01  9:10 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2022-04-01  8:03 UTC (permalink / raw)
  To: mailhol.vincent
  Cc: gregkh, lv.ruyi, cai.huoqing, linux-usb, linux-kernel, Zeal Robot

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

There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

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

diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index b741670525e3..86f92aadeb0e 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -169,7 +169,7 @@ struct ehci_regs {
 #define FLAG_CF		(1<<0)		/* true: we'll support "high speed" */
 
 	/* PORTSC: offset 0x44 */
-	u32		port_status[0];	/* up to N_PORTS */
+	u32		port_status[];	/* up to N_PORTS */
 /* 31:23 reserved */
 #define PORT_WKOC_E	(1<<22)		/* wake on overcurrent (enable) */
 #define PORT_WKDISC_E	(1<<21)		/* wake on disconnect (enable) */
-- 
2.25.1


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

* Re: [PATCH] usb: host: replace zero-length array with flexible-array member
  2022-04-01  8:03 [PATCH] usb: host: replace zero-length array with flexible-array member cgel.zte
@ 2022-04-01  9:10 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-04-01  9:10 UTC (permalink / raw)
  To: cgel.zte
  Cc: mailhol.vincent, lv.ruyi, cai.huoqing, linux-usb, linux-kernel,
	Zeal Robot

On Fri, Apr 01, 2022 at 08:03:37AM +0000, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> There is a regular need in the kernel to provide a way to declare
> having a dynamically sized set of trailing elements in a structure.
> Kernel code should always use “flexible array members”[1] for these
> cases. The older style of one-element or zero-length arrays should
> no longer be used[2].
> 
> [1] https://en.wikipedia.org/wiki/Flexible_array_member
> [2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>  drivers/usb/host/oxu210hp-hcd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
> index b741670525e3..86f92aadeb0e 100644
> --- a/drivers/usb/host/oxu210hp-hcd.c
> +++ b/drivers/usb/host/oxu210hp-hcd.c
> @@ -169,7 +169,7 @@ struct ehci_regs {
>  #define FLAG_CF		(1<<0)		/* true: we'll support "high speed" */
>  
>  	/* PORTSC: offset 0x44 */
> -	u32		port_status[0];	/* up to N_PORTS */
> +	u32		port_status[];	/* up to N_PORTS */
>  /* 31:23 reserved */
>  #define PORT_WKOC_E	(1<<22)		/* wake on overcurrent (enable) */
>  #define PORT_WKDISC_E	(1<<21)		/* wake on disconnect (enable) */
> -- 
> 2.25.1
> 

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

^ 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  8:03 [PATCH] usb: host: replace zero-length array with flexible-array member 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

all inboxes | Powered by JetHome®