scsi: myrs: avoid stack overflow warning
Subsystems (2)
PATCH 1/1 scsi: myrs: avoid stack overflow warning
Putting a 1024 byte data structure on the stack is generally a bad idea. On 32-bit systems, it also triggers a compile-time warning when building with -Og:
drivers/scsi/myrs.c: In function 'myrs_get_ctlr_info':drivers/scsi/myrs.c:212:1: error: the frame size of 1028 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
We only really need three members of the structure, so just read them manually here instead of copying the entire structure.
--- drivers/scsi/myrs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/scsi/myrs.c +8 -5
@@ -163,9 +163,12 @@ static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs)dma_addr_t ctlr_info_addr;union myrs_sgl *sgl;unsigned char status; -struct myrs_ctlr_info old; +unsigned short ldev_present, ldev_critical, ldev_offline; + + ldev_present = cs->ctlr_info->ldev_present; + ldev_critical = cs->ctlr_info->ldev_critical; + ldev_offline = cs->ctlr_info->ldev_offline; -memcpy (&old, cs->ctlr_info,sizeof (struct myrs_ctlr_info )); ctlr_info_addr =dma_map_single (&cs->pdev->dev, cs->ctlr_info,sizeof (struct myrs_ctlr_info ),DMA_FROM_DEVICE );
@@ -198,9 +201,9 @@ static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs) cs->ctlr_info->rbld_active + cs->ctlr_info->exp_active != 0) cs->needs_update = true; -if (cs->ctlr_info->ldev_present != old.ldev_present || - cs->ctlr_info->ldev_critical != old.ldev_critical || - cs->ctlr_info->ldev_offline != old.ldev_offline) +if (cs->ctlr_info->ldev_present != ldev_present || + cs->ctlr_info->ldev_critical != ldev_critical || + cs->ctlr_info->ldev_offline != ldev_offline) shost_printk(KERN_INFO, cs->host, "Logical drive count changes (%d/%d/%d)\n", cs->ctlr_info->ldev_critical,
Signature · 1 line
2.18.0
Quoted 39 lines · Arnd Bergmann
Putting a 1024 byte data structure on the stack is generally a bad idea. On 32-bit systems, it also triggers a compile-time warning when building with -Og:
drivers/scsi/myrs.c: In function 'myrs_get_ctlr_info':drivers/scsi/myrs.c:212:1: error: the frame size of 1028 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]We only really need three members of the structure, so just read them manually here instead of copying the entire structure.
Fixes 77266186397c ("scsi: myrs: Add Mylex RAID controller (SCSI interface)")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/scsi/myrs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/scsi/myrs.c +5
-2@@ -163,9 +163,12 @@ static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs)dma_addr_t ctlr_info_addr;union myrs_sgl *sgl;unsigned char status; -struct myrs_ctlr_info old; +unsigned short ldev_present, ldev_critical, ldev_offline; + + ldev_present = cs->ctlr_info->ldev_present; + ldev_critical = cs->ctlr_info->ldev_critical; + ldev_offline = cs->ctlr_info->ldev_offline; -memcpy (&old, cs->ctlr_info,sizeof (struct myrs_ctlr_info )); ctlr_info_addr =dma_map_single (&cs->pdev->dev, cs->ctlr_info,sizeof (struct myrs_ctlr_info ),DMA_FROM_DEVICE );@@ -198,9 +201,9 @@ static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs) cs->ctlr_info->rbld_active + cs->ctlr_info->exp_active != 0)
drivers/scsi/myrs.c static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs) · line 209
Quoted 10 lines
drivers/scsi/myrs.c +3
-3cs->needs_update = true; -if (cs->ctlr_info->ldev_present != old.ldev_present || - cs->ctlr_info->ldev_critical != old.ldev_critical || - cs->ctlr_info->ldev_offline != old.ldev_offline) +if (cs->ctlr_info->ldev_present != ldev_present || + cs->ctlr_info->ldev_critical != ldev_critical || + cs->ctlr_info->ldev_offline != ldev_offline) shost_printk(KERN_INFO, cs->host, "Logical drive count changes (%d/%d/%d)\n", cs->ctlr_info->ldev_critical,
Cheers,
Hannes
Martin K. Petersen
AppliedArnd,
Quoted 3 lines
Putting a 1024 byte data structure on the stack is generally a bad idea. On 32-bit systems, it also triggers a compile-time warning when building with -Og:
Applied to 4.20/scsi-fixes, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering