Skip to contentSkip to conversation

bfa: remove VLA

PATCH Applied Stephen Kitt 4 participants 5 messages Mar 8, 2018 – Mar 15, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bfa: remove VLA

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

---
 drivers/scsi/bfa/bfad_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/bfa/bfad_bsg.c +1 -1
index 3976e787ba64..7c884f881180 100644
@@ -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;
 	}
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stephen Kitt

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

-Kees

Quoted 20 lines
---
 drivers/scsi/bfa/bfad_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/bfa/bfad_bsg.c +1 -2
index 3976e787ba64..7c884f881180 100644
@@ -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

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw

Hi,

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

Regards,

Stephen

Quoted 44 lines · Kees Cook
Quoted 11 lines · Stephen Kitt

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

-Kees

Quoted 21 lines
---
 drivers/scsi/bfa/bfad_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/bfa/bfad_bsg.c +1 -1
index 3976e787ba64..7c884f881180 100644
@@ -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

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw
In reply to Stephen Kitt

Stephen,

drivers/scsi/bfa/bfad_bsg.c bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd, · line 894

Quoted 7 lines

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.

drivers/scsi/bfa/bfad_bsg.c +1 -1
-		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.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
Quoted 4 lines

drivers/scsi/bfa/bfad_bsg.c bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd, · line 894

Quoted 2 lines
drivers/scsi/bfa/bfad_bsg.c +1 -1
-		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