Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 804e498e0496 ("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>

authored by

Abinash Singh and committed by
Martin K. Petersen
b5f717b3 6d55af0f

+28 -22
+28 -22
drivers/scsi/sd.c
··· 3696 3696 struct scsi_disk *sdkp = scsi_disk(disk); 3697 3697 struct scsi_device *sdp = sdkp->device; 3698 3698 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; 3701 3701 unsigned int dev_max; 3702 - int err; 3702 + int err = 0; 3703 3703 3704 3704 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, 3705 3705 "sd_revalidate_disk\n")); ··· 3711 3711 if (!scsi_device_online(sdp)) 3712 3712 goto out; 3713 3713 3714 + lim = kmalloc(sizeof(*lim), GFP_KERNEL); 3715 + if (!lim) 3716 + goto out; 3717 + 3714 3718 buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL); 3715 3719 if (!buffer) { 3716 3720 sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory " ··· 3724 3720 3725 3721 sd_spinup_disk(sdkp); 3726 3722 3727 - lim = queue_limits_start_update(sdkp->disk->queue); 3723 + *lim = queue_limits_start_update(sdkp->disk->queue); 3728 3724 3729 3725 /* 3730 3726 * Without media there is no reason to ask; moreover, some devices 3731 3727 * react badly if we do. 3732 3728 */ 3733 3729 if (sdkp->media_present) { 3734 - sd_read_capacity(sdkp, &lim, buffer); 3730 + sd_read_capacity(sdkp, lim, buffer); 3735 3731 /* 3736 3732 * Some USB/UAS devices return generic values for mode pages 3737 3733 * until the media has been accessed. Trigger a READ operation ··· 3745 3741 * cause this to be updated correctly and any device which 3746 3742 * doesn't support it should be treated as rotational. 3747 3743 */ 3748 - lim.features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM); 3744 + lim->features |= (BLK_FEAT_ROTATIONAL | BLK_FEAT_ADD_RANDOM); 3749 3745 3750 3746 if (scsi_device_supports_vpd(sdp)) { 3751 3747 sd_read_block_provisioning(sdkp); 3752 - sd_read_block_limits(sdkp, &lim); 3748 + sd_read_block_limits(sdkp, lim); 3753 3749 sd_read_block_limits_ext(sdkp); 3754 - sd_read_block_characteristics(sdkp, &lim); 3755 - sd_zbc_read_zones(sdkp, &lim, buffer); 3750 + sd_read_block_characteristics(sdkp, lim); 3751 + sd_zbc_read_zones(sdkp, lim, buffer); 3756 3752 } 3757 3753 3758 - sd_config_discard(sdkp, &lim, sd_discard_mode(sdkp)); 3754 + sd_config_discard(sdkp, lim, sd_discard_mode(sdkp)); 3759 3755 3760 3756 sd_print_capacity(sdkp, old_capacity); 3761 3757 ··· 3765 3761 sd_read_app_tag_own(sdkp, buffer); 3766 3762 sd_read_write_same(sdkp, buffer); 3767 3763 sd_read_security(sdkp, buffer); 3768 - sd_config_protection(sdkp, &lim); 3764 + sd_config_protection(sdkp, lim); 3769 3765 } 3770 3766 3771 3767 /* 3772 3768 * We now have all cache related info, determine how we deal 3773 3769 * with flush requests. 3774 3770 */ 3775 - sd_set_flush_flag(sdkp, &lim); 3771 + sd_set_flush_flag(sdkp, lim); 3776 3772 3777 3773 /* Initial block count limit based on CDB TRANSFER LENGTH field size. */ 3778 3774 dev_max = sdp->use_16_for_rw ? SD_MAX_XFER_BLOCKS : SD_DEF_XFER_BLOCKS; 3779 3775 3780 3776 /* Some devices report a maximum block count for READ/WRITE requests. */ 3781 3777 dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks); 3782 - lim.max_dev_sectors = logical_to_sectors(sdp, dev_max); 3778 + lim->max_dev_sectors = logical_to_sectors(sdp, dev_max); 3783 3779 3784 3780 if (sd_validate_min_xfer_size(sdkp)) 3785 - lim.io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks); 3781 + lim->io_min = logical_to_bytes(sdp, sdkp->min_xfer_blocks); 3786 3782 else 3787 - lim.io_min = 0; 3783 + lim->io_min = 0; 3788 3784 3789 3785 /* 3790 3786 * Limit default to SCSI host optimal sector limit if set. There may be 3791 3787 * an impact on performance for when the size of a request exceeds this 3792 3788 * host limit. 3793 3789 */ 3794 - lim.io_opt = sdp->host->opt_sectors << SECTOR_SHIFT; 3790 + lim->io_opt = sdp->host->opt_sectors << SECTOR_SHIFT; 3795 3791 if (sd_validate_opt_xfer_size(sdkp, dev_max)) { 3796 - lim.io_opt = min_not_zero(lim.io_opt, 3792 + lim->io_opt = min_not_zero(lim->io_opt, 3797 3793 logical_to_bytes(sdp, sdkp->opt_xfer_blocks)); 3798 3794 } 3799 3795 3800 3796 sdkp->first_scan = 0; 3801 3797 3802 3798 set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity)); 3803 - sd_config_write_same(sdkp, &lim); 3804 - kfree(buffer); 3799 + sd_config_write_same(sdkp, lim); 3805 3800 3806 - err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim); 3801 + err = queue_limits_commit_update_frozen(sdkp->disk->queue, lim); 3807 3802 if (err) 3808 - return err; 3803 + goto out; 3809 3804 3810 3805 /* 3811 3806 * Query concurrent positioning ranges after ··· 3823 3820 set_capacity_and_notify(disk, 0); 3824 3821 3825 3822 out: 3826 - return 0; 3823 + kfree(buffer); 3824 + kfree(lim); 3825 + 3826 + return err; 3827 3827 } 3828 3828 3829 3829 /**