Skip to content

Commit 4e3f070

Browse files
toshikanidjbw
authored andcommitted
libnvdimm: fix badblock range handling of ARS range
__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. Cc: <[email protected]> Fixes: 0caeef6 ("libnvdimm: Add a poison list and export badblocks") Signed-off-by: Toshi Kani <[email protected]> Reviewed-by: Vishal Verma <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 5771a8c commit 4e3f070

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/nvdimm/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,15 @@ static void set_badblock(struct badblocks *bb, sector_t s, int num)
421421
static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
422422
{
423423
const unsigned int sector_size = 512;
424-
sector_t start_sector;
424+
sector_t start_sector, end_sector;
425425
u64 num_sectors;
426426
u32 rem;
427427

428428
start_sector = div_u64(ns_offset, sector_size);
429-
num_sectors = div_u64_rem(len, sector_size, &rem);
429+
end_sector = div_u64_rem(ns_offset + len, sector_size, &rem);
430430
if (rem)
431-
num_sectors++;
431+
end_sector++;
432+
num_sectors = end_sector - start_sector;
432433

433434
if (unlikely(num_sectors > (u64)INT_MAX)) {
434435
u64 remaining = num_sectors;

0 commit comments

Comments
 (0)