block: Avoid divide by 0 when max_discard_sectors is 0
PATCH 1/1 block: Avoid divide by 0 when max_discard_sectors is 0
The recent commit "block: discard granularity might not be power of 2" introduced a divide by 0 in the kernel. Previously the code didn't try to divide by discard_granularity when max_discard_sectors was 0.
Fix the code to only do the division if max_discard_sectors is specified.
Error looked like this:
Division by zero in kernel.
[<8001618c>] (unwind_backtrace+0x0/0xec) from [<8046cfac>] (dump_stack+0x20/0x24) [<8046cfac>] (dump_stack+0x20/0x24) from [<80012bf0>] (__div0+0x20/0x28) [<80012bf0>] (__div0+0x20/0x28) from [<80224c24>] (Ldiv0_64+0x8/0x18) [<80224c24>] (Ldiv0_64+0x8/0x18) from [<8021bcb8>] (add_partition+0x308/0x344) [<8021bcb8>] (add_partition+0x308/0x344) from [<8021bf3c>] (rescan_partitions+0x248/0x2b8) [<8021bf3c>] (rescan_partitions+0x248/0x2b8) from [<80127ae4>] (__blkdev_get+0x170/0x380) [<80127ae4>] (__blkdev_get+0x170/0x380) from [<80127e60>] (blkdev_get+0x16c/0x2d0) [<80127e60>] (blkdev_get+0x16c/0x2d0) from [<8021984c>] (add_disk+0x284/0x42c) [<8021984c>] (add_disk+0x284/0x42c) from [<80342f50>] (mmc_add_disk+0x28/0x100) [<80342f50>] (mmc_add_disk+0x28/0x100) from [<8034392c>] (mmc_blk_probe+0x2a8/0x2d8) [<8034392c>] (mmc_blk_probe+0x2a8/0x2d8) from [<8033865c>] (mmc_bus_probe+0x24/0x28) [<8033865c>] (mmc_bus_probe+0x24/0x28) from [<802969d8>] (driver_probe_device+0xb0/0x220) [<802969d8>] (driver_probe_device+0xb0/0x220) from [<80296c1c>] (__device_attach+0x38/0x54) [<80296c1c>] (__device_attach+0x38/0x54) from [<80294da4>] (bus_for_each_drv+0x5c/0xa4) [<80294da4>] (bus_for_each_drv+0x5c/0xa4) from [<802968d0>] (device_attach+0x78/0x9c) [<802968d0>] (device_attach+0x78/0x9c) from [<80295df8>] (bus_probe_device+0x38/0xa8) [<80295df8>] (bus_probe_device+0x38/0xa8) from [<80294250>] (device_add+0x43c/0x60c) [<80294250>] (device_add+0x43c/0x60c) from [<80338b84>] (mmc_add_card+0x18c/0x1e8) [<80338b84>] (mmc_add_card+0x18c/0x1e8) from [<8033d414>] (mmc_attach_sd+0x18c/0x214) [<8033d414>] (mmc_attach_sd+0x18c/0x214) from [<803382b0>] (mmc_rescan+0x25c/0x2c8) [<803382b0>] (mmc_rescan+0x25c/0x2c8) from [<80042788>] (process_one_work+0x228/0x408) [<80042788>] (process_one_work+0x228/0x408) from [<80042df4>] (worker_thread+0x280/0x3c4) [<80042df4>] (worker_thread+0x280/0x3c4) from [<80048544>] (kthread+0xbc/0xcc) [<80048544>] (kthread+0xbc/0xcc) from [<8000e358>] (ret_from_fork+0x14/0x20)
--- include/linux/blkdev.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/blkdev.h +1 -1
@@ -1189,11 +1189,11 @@ static inline int queue_discard_alignment(struct request_queue *q)static inline int queue_limit_discard_alignment (struct queue_limits *lim,sector_t sector) {sector_t alignment = sector <<9 ; - alignment =sector_div (alignment, lim->discard_granularity);if (!lim->max_discard_sectors)return 0 ; + alignment =sector_div (alignment, lim->discard_granularity); alignment = lim->discard_granularity + lim->discard_alignment - alignment;return sector_div (alignment, lim->discard_granularity); }
Signature · 1 line
1.7.7.3
Quoted 7 lines · Doug Anderson
The recent commit "block: discard granularity might not be power of 2" introduced a divide by 0 in the kernel. Previously the code didn't try to divide by
discard_granularitywhenmax_discard_sectorswas 0.Fix the code to only do the division if
max_discard_sectorsis specified.
Could you try Linus' patch at
http://marc.info/?l=linux-kernel&m=135584941732572 and give your Tested-by if it solves your issue?
Thanks.
David,
Quoted 6 lines · David Rientjes
Quoted 4 lines · Doug Anderson
The recent commit "block: discard granularity might not be power of 2" introduced a divide by 0 in the kernel. Previously the code didn't try to divide by
discard_granularitywhenmax_discard_sectorswas 0.
Quoted 7 lines
Quoted 3 lines
Fix the code to only do the division if
max_discard_sectorsis specified.Could you try Linus' patch at
http://marc.info/?l=linux-kernel&m=135584941732572 and give your Tested-by if it solves your issue?
Hoo boy. Thanks for the pointer. I missed that when searching to see if this had already been fixed. :(
I'm pretty sure Linus's patch will fix my problem since I think my system has "max_discard_sectors" as 0 and his patch has the same effect as mine: avoid the divide by 0. Someone else will need to test his patch on a system that actually uses discard. In any case, I will test and send a Tested-by as soon as I'm able.
Please consider my patch abandoned.
Quoted 2 lines
Thanks.