]> www.infradead.org Git - users/jedix/linux-maple.git/commit
badblocks: return error directly when setting badblocks exceeds 512
authorLi Nan <linan122@huawei.com>
Thu, 27 Feb 2025 07:54:59 +0000 (15:54 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Mar 2025 15:03:28 +0000 (08:03 -0700)
commit28243dcd1f49cc8be398a1396d16a45527882ce5
tree84d65007a0437ddad90f03b23e72cb8b953de67f
parent32e9ad4d11f69949ff331e35a417871ee0d31d99
badblocks: return error directly when setting badblocks exceeds 512

In the current handling of badblocks settings, a lot of processing has
been done for scenarios where the number of badblocks exceeds 512.
This makes the code look quite complex and also introduces some issues,

For example, if there is 512 badblocks already:
  for((i=0; i<510; i++)); do ((sector=i*2)); echo "$sector 1" > bad_blocks; done
  echo 2100 10 > bad_blocks
  echo 2200 10 > bad_blocks
Set new one, exceed 512:
  echo 2000 500 > bad_blocks
Expected:
  2000 500
Actual:
  2100 400

In fact, a disk shouldn't have too many badblocks, and for disks with
512 badblocks, attempting to set more bad blocks doesn't make much sense.
At that point, the more appropriate action would be to replace the disk.
Therefore, to resolve these issues and simplify the code somewhat, return
error directly when setting badblocks exceeds 512.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250227075507.151331-5-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/badblocks.c