Re: [PATCH] block: fix divide by zero in queue_limit_discard_alignment()

From: Christoph Hellwig

Date: Fri Nov 20 2026 - 10:25:03 EST


On Fri, Nov 20, 2026 at 06:30:13PM +0800, tongzhiwei wrote:
> Commit e924da7d6622 ("block: Drop granularity check in
> queue_limit_discard_alignment()") removed the check for a sub-sector
> discard granularity on the assumption that lim->discard_granularity
> is always at least SECTOR_SIZE.
>
> That assumption does not hold for every queue: a backing device can
> report a non-zero discard granularity smaller than 512 bytes. When
> blk_stack_limits() stacks such limits, only the non-zero granularity
> is checked, and queue_limit_discard_alignment() shifts the value down
> to zero and divides by it:

Well, then let's fix the setup time to reject this. Because a discard
granularity less than a sector by definition makes no sense whatsoever.