mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] libnvdimm: fix badblock range handling of ARS range
@ 2017-07-07 23:44 Toshi Kani
  2017-07-10 21:31 ` Vishal Verma
  0 siblings, 1 reply; 2+ messages in thread
From: Toshi Kani @ 2017-07-07 23:44 UTC (permalink / raw)
  To: dan.j.williams; +Cc: vishal.l.verma, linux-nvdimm, linux-kernel

__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: 0caeef63e6d2f866d85bb507bf63e0ce8ec91cef
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: <stable@vger.kernel.org>
---
 drivers/nvdimm/core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c
index 2dee908..932c3994 100644
--- a/drivers/nvdimm/core.c
+++ b/drivers/nvdimm/core.c
@@ -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)
 {
 	const unsigned int sector_size = 512;
-	sector_t start_sector;
+	sector_t start_sector, end_sector;
 	u64 num_sectors;
 	u32 rem;
 
 	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)
-		num_sectors++;
+		end_sector++;
+	num_sectors = end_sector - start_sector;
 
 	if (unlikely(num_sectors > (u64)INT_MAX)) {
 		u64 remaining = num_sectors;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-10 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07 23:44 [PATCH] libnvdimm: fix badblock range handling of ARS range Toshi Kani
2017-07-10 21:31 ` Vishal Verma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®