Skip to content

Commit 4fbcd2b

Browse files
avinashlalotragregkh
authored andcommitted
scsi: sd: Fix build warning in sd_revalidate_disk()
commit b5f717b upstream. A build warning was triggered due to excessive stack usage in sd_revalidate_disk(): drivers/scsi/sd.c: In function ‘sd_revalidate_disk.isra’: drivers/scsi/sd.c:3824:1: warning: the frame size of 1160 bytes is larger than 1024 bytes [-Wframe-larger-than=] This is caused by a large local struct queue_limits (~400B) allocated on the stack. Replacing it with a heap allocation using kmalloc() significantly reduces frame usage. Kernel stack is limited (~8 KB), and allocating large structs on the stack is discouraged. As the function already performs heap allocations (e.g. for buffer), this change fits well. Fixes: 804e498 ("sd: convert to the atomic queue limits API") Cc: stable@vger.kernel.org Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com> Link: https://lore.kernel.org/r/20250825183940.13211-2-abinashsinghlalotra@gmail.com Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7b2ef1a commit 4fbcd2b

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

drivers/scsi/sd.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,10 +3695,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
36953695
struct scsi_disk *sdkp = scsi_disk(disk);
36963696
struct scsi_device *sdp = sdkp->device;
36973697
sector_t old_capacity = sdkp->capacity;
3698-
struct queue_limits lim;
3699-
unsigned char *buffer;
3698+
struct queue_limits *lim = NULL;
3699+
unsigned char *buffer = NULL;
37003700
unsigned int dev_max;
3701-
int err;
3701+
int err = 0;
37023702

37033703
SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp,
37043704
"sd_revalidate_disk\n"));
@@ -3710,6 +3710,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
37103710
if (!scsi_device_online(sdp))
37113711
goto out;
37123712

3713+
lim = kmalloc(sizeof(*lim), GFP_KERNEL);
3714+
if (!lim)
3715+
goto out;
3716+
37133717
buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
37143718
if (!buffer) {
37153719
sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
@@ -3719,14 +3723,14 @@ static int sd_revalidate_disk(struct gendisk *disk)
37193723

37203724
sd_spinup_disk(sdkp);
37213725

3722-
lim = queue_limits_start_update(sdkp->disk->queue);
3726+
*lim = queue_limits_start_update(sdkp->disk->queue);
37233727

37243728
/*
37253729
* Without media there is no reason to ask; moreover, some devices
37263730
* react badly if we do.
37273731
*/
37283732
if (sdkp->media_present) {
3729-
sd_read_capacity(sdkp, &lim, buffer);
3733+
sd_read_capacity(sdkp, lim, buffer);
37303734
/*
37313735
* Some USB/UAS devices return generic values for mode pages
37323736
* until the media has been accessed. Trigger a READ operation
@@ -3740,17 +3744,17 @@ static int sd_revalidate_disk(struct gendisk *disk)
37403744
* cause this to be updated correctly and any device which
37413745
* doesn't support it should be treated as rotational.
37423746
*/
3743-
lim.features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
3747+
lim->features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM);
37443748

37453749
if (scsi_device_supports_vpd(sdp)) {
37463750
sd_read_block_provisioning(sdkp);
3747-
sd_read_block_limits(sdkp, &lim);
3751+
sd_read_block_limits(sdkp, lim);
37483752
sd_read_block_limits_ext(sdkp);
3749-
sd_read_block_characteristics(sdkp, &lim);
3750-
sd_zbc_read_zones(sdkp, &lim, buffer);
3753+
sd_read_block_characteristics(sdkp, lim);
3754+
sd_zbc_read_zones(sdkp, lim, buffer);
37513755
}
37523756

3753-
sd_config_discard(sdkp, &lim, sd_discard_mode(sdkp));
3757+
sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
37543758

37553759
sd_print_capacity(sdkp, old_capacity);
37563760

@@ -3760,47 +3764,46 @@ static int sd_revalidate_disk(struct gendisk *disk)
37603764
sd_read_app_tag_own(sdkp, buffer);
37613765
sd_read_write_same(sdkp, buffer);
37623766
sd_read_security(sdkp, buffer);
3763-
sd_config_protection(sdkp, &lim);
3767+
sd_config_protection(sdkp, lim);
37643768
}
37653769

37663770
/*
37673771
* We now have all cache related info, determine how we deal
37683772
* with flush requests.
37693773
*/
3770-
sd_set_flush_flag(sdkp, &lim);
3774+
sd_set_flush_flag(sdkp, lim);
37713775

37723776
/* Initial block count limit based on CDB TRANSFER LENGTH field size. */
37733777
dev_max = sdp->use_16_for_rw ? SD_MAX_XFER_BLOCKS : SD_DEF_XFER_BLOCKS;
37743778

37753779
/* Some devices report a maximum block count for READ/WRITE requests. */
37763780
dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks);
3777-
lim.max_dev_sectors = logical_to_sectors(sdp, dev_max);
3781+
lim->max_dev_sectors = logical_to_sectors(sdp, dev_max);
37783782

37793783
if (sd_validate_min_xfer_size(sdkp))
3780-
lim.io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks);
3784+
lim->io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks);
37813785
else
3782-
lim.io_min = 0;
3786+
lim->io_min = 0;
37833787

37843788
/*
37853789
* Limit default to SCSI host optimal sector limit if set. There may be
37863790
* an impact on performance for when the size of a request exceeds this
37873791
* host limit.
37883792
*/
3789-
lim.io_opt = sdp->host->opt_sectors << SECTOR_SHIFT;
3793+
lim->io_opt = sdp->host->opt_sectors << SECTOR_SHIFT;
37903794
if (sd_validate_opt_xfer_size(sdkp, dev_max)) {
3791-
lim.io_opt = min_not_zero(lim.io_opt,
3795+
lim->io_opt = min_not_zero(lim->io_opt,
37923796
logical_to_bytes(sdp, sdkp->opt_xfer_blocks));
37933797
}
37943798

37953799
sdkp->first_scan = 0;
37963800

37973801
set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity));
3798-
sd_config_write_same(sdkp, &lim);
3799-
kfree(buffer);
3802+
sd_config_write_same(sdkp, lim);
38003803

3801-
err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim);
3804+
err = queue_limits_commit_update_frozen(sdkp->disk->queue, lim);
38023805
if (err)
3803-
return err;
3806+
goto out;
38043807

38053808
/*
38063809
* Query concurrent positioning ranges after
@@ -3819,7 +3822,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
38193822
set_capacity_and_notify(disk, 0);
38203823

38213824
out:
3822-
return 0;
3825+
kfree(buffer);
3826+
kfree(lim);
3827+
3828+
return err;
38233829
}
38243830

38253831
/**

0 commit comments

Comments
 (0)