On Fri, Jul 07, 2023 at 11:46:13AM +0200, Christoph Hellwig wrote: > { > q->limits.max_hw_discard_sectors = max_discard_sectors; > - q->limits.max_discard_sectors = max_discard_sectors; > + if (!q->limits.max_discard_sectors || > + q->limits.max_discard_sectors > max_discard_sectors) > + q->limits.max_discard_sectors = max_discard_sectors; Could simplify to min_not_zero(). But this only allows you to make the limit smaller. If the user never set max_discard_sectors before, and a firmware update allows a larger max_hw_discard_sectors, the subsequent rescan won't use the new limit.