Commit 08196c1c authored by Toshi Kani's avatar Toshi Kani Committed by Greg Kroah-Hartman

libnvdimm: fix badblock range handling of ARS range

commit 4e3f0701 upstream.

__add_badblock_range() does not account sector alignment when
it sets 'num_sectors'.  Therefore, an ARS error record range
spanning across two sectors is set to a single sector length,
which leaves the 2nd sector unprotected.

Change __add_badblock_range() to set 'num_sectors' properly.

Fixes: 0caeef63 ("libnvdimm: Add a poison list and export badblocks")
Signed-off-by: default avatarToshi Kani <toshi.kani@hpe.com>
Reviewed-by: default avatarVishal Verma <vishal.l.verma@intel.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e01c81e8
...@@ -421,14 +421,15 @@ static void set_badblock(struct badblocks *bb, sector_t s, int num) ...@@ -421,14 +421,15 @@ static void set_badblock(struct badblocks *bb, sector_t s, int num)
static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len) static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
{ {
const unsigned int sector_size = 512; const unsigned int sector_size = 512;
sector_t start_sector; sector_t start_sector, end_sector;
u64 num_sectors; u64 num_sectors;
u32 rem; u32 rem;
start_sector = div_u64(ns_offset, sector_size); start_sector = div_u64(ns_offset, sector_size);
num_sectors = div_u64_rem(len, sector_size, &rem); end_sector = div_u64_rem(ns_offset + len, sector_size, &rem);
if (rem) if (rem)
num_sectors++; end_sector++;
num_sectors = end_sector - start_sector;
if (unlikely(num_sectors > (u64)INT_MAX)) { if (unlikely(num_sectors > (u64)INT_MAX)) {
u64 remaining = num_sectors; u64 remaining = num_sectors;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment