diff mbox

bfa: remove VLA

Message ID 20180308213841.13807-1-steve@sk2.org (mailing list archive)
State New, archived
Headers show

Commit Message

Stephen Kitt March 8, 2018, 9:38 p.m. UTC
In preparation to enabling -Wvla, remove VLAs and replace them with
fixed-length arrays instead.

bfad_bsg.c uses a variable-length array declaration to measure the
size of a putative array; this can be replaced by the product of the
size of an element and the number of elements, avoiding the VLA
altogether.

This was prompted by https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 drivers/scsi/bfa/bfad_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kees Cook March 8, 2018, 9:43 p.m. UTC | #1
On Thu, Mar 8, 2018 at 1:38 PM, Stephen Kitt <steve@sk2.org> wrote:
> In preparation to enabling -Wvla, remove VLAs and replace them with
> fixed-length arrays instead.
>
> bfad_bsg.c uses a variable-length array declaration to measure the
> size of a putative array; this can be replaced by the product of the
> size of an element and the number of elements, avoiding the VLA
> altogether.
>
> This was prompted by https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Stephen Kitt <steve@sk2.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  drivers/scsi/bfa/bfad_bsg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> index 3976e787ba64..7c884f881180 100644
> --- a/drivers/scsi/bfa/bfad_bsg.c
> +++ b/drivers/scsi/bfa/bfad_bsg.c
> @@ -891,7 +891,7 @@ bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
>
>         if (bfad_chk_iocmd_sz(payload_len,
>                 sizeof(struct bfa_bsg_fabric_get_lports_s),
> -               sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> +               sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
>                 iocmd->status = BFA_STATUS_VERSION_FAIL;
>                 goto out;
>         }
> --
> 2.11.0
>
Stephen Kitt March 9, 2018, 10:15 p.m. UTC | #2
Hi,

I sent this to the wrong maintainers, sorry — you’ll find the original patch
on https://patchwork.kernel.org/patch/10269257/

Regards,

Stephen


On Thu, 8 Mar 2018 13:43:07 -0800, Kees Cook <keescook@chromium.org> wrote:
> On Thu, Mar 8, 2018 at 1:38 PM, Stephen Kitt <steve@sk2.org> wrote:
> > In preparation to enabling -Wvla, remove VLAs and replace them with
> > fixed-length arrays instead.
> >
> > bfad_bsg.c uses a variable-length array declaration to measure the
> > size of a putative array; this can be replaced by the product of the
> > size of an element and the number of elements, avoiding the VLA
> > altogether.
> >
> > This was prompted by https://lkml.org/lkml/2018/3/7/621
> >
> > Signed-off-by: Stephen Kitt <steve@sk2.org>  
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> 
> -Kees
> 
> > ---
> >  drivers/scsi/bfa/bfad_bsg.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> > index 3976e787ba64..7c884f881180 100644
> > --- a/drivers/scsi/bfa/bfad_bsg.c
> > +++ b/drivers/scsi/bfa/bfad_bsg.c
> > @@ -891,7 +891,7 @@ bfad_iocmd_fabric_get_lports(struct bfad_s *bfad,
> > void *cmd,
> >
> >         if (bfad_chk_iocmd_sz(payload_len,
> >                 sizeof(struct bfa_bsg_fabric_get_lports_s),
> > -               sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> > +               sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
> >                 iocmd->status = BFA_STATUS_VERSION_FAIL;
> >                 goto out;
> >         }
> > --
> > 2.11.0
> >  
> 
> 
> 
> -- 
> Kees Cook
> Pixel Security
Martin K. Petersen March 15, 2018, 4:37 a.m. UTC | #3
Stephen,

> bfad_bsg.c uses a variable-length array declaration to measure the
> size of a putative array; this can be replaced by the product of the
> size of an element and the number of elements, avoiding the VLA
> altogether.
>
> -		sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> +		sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {

These parentheses made me blurry eyed but it's actually OK.

Applied to 4.17/scsi-queue.
David Laight March 15, 2018, 11:40 a.m. UTC | #4
> > -		sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> > +		sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
> 
> These parentheses made me blurry eyed but it's actually OK.

		iocmd->nports * sizeof(wwn_t)) != BFA_STATUS_OK) {

is easier to focus on :-)

	David
diff mbox

Patch

diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 3976e787ba64..7c884f881180 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -891,7 +891,7 @@  bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
 
 	if (bfad_chk_iocmd_sz(payload_len,
 		sizeof(struct bfa_bsg_fabric_get_lports_s),
-		sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
+		sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
 		iocmd->status = BFA_STATUS_VERSION_FAIL;
 		goto out;
 	}