scsi: uapi: Replace 0-length array with flexible array

Message ID 20230105233042.never.913-kees@kernel.org
State New
Headers
Series scsi: uapi: Replace 0-length array with flexible array |

Commit Message

Kees Cook Jan. 5, 2023, 11:30 p.m. UTC
  Zero-length arrays are deprecated[1]. Replace struct
fc_bsg_host_vendor_reply's "vendor_rsp" 0-length array with a flexible
array. Detected with GCC 13, using -fstrict-flex-arrays=3:

drivers/scsi/qla2xxx/qla_isr.c: In function 'qla25xx_process_bidir_status_iocb.isra':
drivers/scsi/qla2xxx/qla_isr.c:3117:54: warning: array subscript 0 is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
 3117 |         bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from drivers/scsi/qla2xxx/qla_def.h:34,
                 from drivers/scsi/qla2xxx/qla_isr.c:6:
include/uapi/scsi/scsi_bsg_fc.h:219:15: note: while referencing 'vendor_rsp'
  219 |         __u32 vendor_rsp[0];
      |               ^~~~~~~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/uapi/scsi/scsi_bsg_fc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Gustavo A. R. Silva Jan. 6, 2023, 4:17 p.m. UTC | #1
On Thu, Jan 05, 2023 at 03:30:46PM -0800, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct
> fc_bsg_host_vendor_reply's "vendor_rsp" 0-length array with a flexible
> array. Detected with GCC 13, using -fstrict-flex-arrays=3:
> 
> drivers/scsi/qla2xxx/qla_isr.c: In function 'qla25xx_process_bidir_status_iocb.isra':
> drivers/scsi/qla2xxx/qla_isr.c:3117:54: warning: array subscript 0 is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
>  3117 |         bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
> In file included from drivers/scsi/qla2xxx/qla_def.h:34,
>                  from drivers/scsi/qla2xxx/qla_isr.c:6:
> include/uapi/scsi/scsi_bsg_fc.h:219:15: note: while referencing 'vendor_rsp'
>   219 |         __u32 vendor_rsp[0];
>       |               ^~~~~~~~~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  include/uapi/scsi/scsi_bsg_fc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/scsi/scsi_bsg_fc.h b/include/uapi/scsi/scsi_bsg_fc.h
> index 7f5930801f72..5e46cf1054af 100644
> --- a/include/uapi/scsi/scsi_bsg_fc.h
> +++ b/include/uapi/scsi/scsi_bsg_fc.h
> @@ -216,7 +216,7 @@ struct fc_bsg_host_vendor {
>   */
>  struct fc_bsg_host_vendor_reply {
>  	/* start of vendor response area */
> -	__u32 vendor_rsp[0];
> +	__DECLARE_FLEX_ARRAY(__u32, vendor_rsp);
>  };
>  
>  
> -- 
> 2.34.1
>
  
Martin K. Petersen Jan. 14, 2023, 1:26 a.m. UTC | #2
Kees,

> Zero-length arrays are deprecated[1]. Replace struct
> fc_bsg_host_vendor_reply's "vendor_rsp" 0-length array with a flexible
> array. Detected with GCC 13, using -fstrict-flex-arrays=3:

Applied to 6.3/scsi-staging, thanks!
  
Martin K. Petersen Jan. 19, 2023, 12:23 a.m. UTC | #3
On Thu, 05 Jan 2023 15:30:46 -0800, Kees Cook wrote:

> Zero-length arrays are deprecated[1]. Replace struct
> fc_bsg_host_vendor_reply's "vendor_rsp" 0-length array with a flexible
> array. Detected with GCC 13, using -fstrict-flex-arrays=3:
> 
> drivers/scsi/qla2xxx/qla_isr.c: In function 'qla25xx_process_bidir_status_iocb.isra':
> drivers/scsi/qla2xxx/qla_isr.c:3117:54: warning: array subscript 0 is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
>  3117 |         bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
> In file included from drivers/scsi/qla2xxx/qla_def.h:34,
>                  from drivers/scsi/qla2xxx/qla_isr.c:6:
> include/uapi/scsi/scsi_bsg_fc.h:219:15: note: while referencing 'vendor_rsp'
>   219 |         __u32 vendor_rsp[0];
>       |               ^~~~~~~~~~
> 
> [...]

Applied to 6.3/scsi-queue, thanks!

[1/1] scsi: uapi: Replace 0-length array with flexible array
      https://git.kernel.org/mkp/scsi/c/64b6deadc938
  

Patch

diff --git a/include/uapi/scsi/scsi_bsg_fc.h b/include/uapi/scsi/scsi_bsg_fc.h
index 7f5930801f72..5e46cf1054af 100644
--- a/include/uapi/scsi/scsi_bsg_fc.h
+++ b/include/uapi/scsi/scsi_bsg_fc.h
@@ -216,7 +216,7 @@  struct fc_bsg_host_vendor {
  */
 struct fc_bsg_host_vendor_reply {
 	/* start of vendor response area */
-	__u32 vendor_rsp[0];
+	__DECLARE_FLEX_ARRAY(__u32, vendor_rsp);
 };