Skip to content

Commit b5f717b

Browse files
avinashlalotramartinkpetersen
authored andcommitted
scsi: sd: Fix build warning in sd_revalidate_disk()
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>
1 parent 6d55af0 commit b5f717b

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

drivers/scsi/sd.c

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

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

3714+
lim = kmalloc(sizeof(*lim), GFP_KERNEL);
3715+
if (!lim)
3716+
goto out;
3717+
37143718
buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
37153719
if (!buffer) {
37163720
sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
@@ -3720,14 +3724,14 @@ static int sd_revalidate_disk(struct gendisk *disk)
37203724

37213725
sd_spinup_disk(sdkp);
37223726

3723-
lim = queue_limits_start_update(sdkp->disk->queue);
3727+
*lim = queue_limits_start_update(sdkp->disk->queue);
37243728

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

37463750
if (scsi_device_supports_vpd(sdp)) {
37473751
sd_read_block_provisioning(sdkp);
3748-
sd_read_block_limits(sdkp, &lim);
3752+
sd_read_block_limits(sdkp, lim);
37493753
sd_read_block_limits_ext(sdkp);
3750-
sd_read_block_characteristics(sdkp, &lim);
3751-
sd_zbc_read_zones(sdkp, &lim, buffer);
3754+
sd_read_block_characteristics(sdkp, lim);
3755+
sd_zbc_read_zones(sdkp, lim, buffer);
37523756
}
37533757

3754-
sd_config_discard(sdkp, &lim, sd_discard_mode(sdkp));
3758+
sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
37553759

37563760
sd_print_capacity(sdkp, old_capacity);
37573761

@@ -3761,47 +3765,46 @@ static int sd_revalidate_disk(struct gendisk *disk)
37613765
sd_read_app_tag_own(sdkp, buffer);
37623766
sd_read_write_same(sdkp, buffer);
37633767
sd_read_security(sdkp, buffer);
3764-
sd_config_protection(sdkp, &lim);
3768+
sd_config_protection(sdkp, lim);
37653769
}
37663770

37673771
/*
37683772
* We now have all cache related info, determine how we deal
37693773
* with flush requests.
37703774
*/
3771-
sd_set_flush_flag(sdkp, &lim);
3775+
sd_set_flush_flag(sdkp, lim);
37723776

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

37763780
/* Some devices report a maximum block count for READ/WRITE requests. */
37773781
dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks);
3778-
lim.max_dev_sectors = logical_to_sectors(sdp, dev_max);
3782+
lim->max_dev_sectors = logical_to_sectors(sdp, dev_max);
37793783

37803784
if (sd_validate_min_xfer_size(sdkp))
3781-
lim.io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks);
3785+
lim->io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks);
37823786
else
3783-
lim.io_min = 0;
3787+
lim->io_min = 0;
37843788

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

37963800
sdkp->first_scan = 0;
37973801

37983802
set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity));
3799-
sd_config_write_same(sdkp, &lim);
3800-
kfree(buffer);
3803+
sd_config_write_same(sdkp, lim);
38013804

3802-
err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim);
3805+
err = queue_limits_commit_update_frozen(sdkp->disk->queue, lim);
38033806
if (err)
3804-
return err;
3807+
goto out;
38053808

38063809
/*
38073810
* Query concurrent positioning ranges after
@@ -3820,7 +3823,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
38203823
set_capacity_and_notify(disk, 0);
38213824

38223825
out:
3823-
return 0;
3826+
kfree(buffer);
3827+
kfree(lim);
3828+
3829+
return err;
38243830
}
38253831

38263832
/**

0 commit comments

Comments
 (0)