| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright(c) 2017 Intel Corporation. All rights reserved. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of version 2 of the GNU General Public License as |
|---|
| 6 | | - * published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 9 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 11 | | - * General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | #include <linux/libnvdimm.h> |
|---|
| 14 | 6 | #include <linux/badblocks.h> |
|---|
| .. | .. |
|---|
| 219 | 211 | } |
|---|
| 220 | 212 | |
|---|
| 221 | 213 | static void badblocks_populate(struct badrange *badrange, |
|---|
| 222 | | - struct badblocks *bb, const struct resource *res) |
|---|
| 214 | + struct badblocks *bb, const struct range *range) |
|---|
| 223 | 215 | { |
|---|
| 224 | 216 | struct badrange_entry *bre; |
|---|
| 225 | 217 | |
|---|
| .. | .. |
|---|
| 230 | 222 | u64 bre_end = bre->start + bre->length - 1; |
|---|
| 231 | 223 | |
|---|
| 232 | 224 | /* Discard intervals with no intersection */ |
|---|
| 233 | | - if (bre_end < res->start) |
|---|
| 225 | + if (bre_end < range->start) |
|---|
| 234 | 226 | continue; |
|---|
| 235 | | - if (bre->start > res->end) |
|---|
| 227 | + if (bre->start > range->end) |
|---|
| 236 | 228 | continue; |
|---|
| 237 | 229 | /* Deal with any overlap after start of the namespace */ |
|---|
| 238 | | - if (bre->start >= res->start) { |
|---|
| 230 | + if (bre->start >= range->start) { |
|---|
| 239 | 231 | u64 start = bre->start; |
|---|
| 240 | 232 | u64 len; |
|---|
| 241 | 233 | |
|---|
| 242 | | - if (bre_end <= res->end) |
|---|
| 234 | + if (bre_end <= range->end) |
|---|
| 243 | 235 | len = bre->length; |
|---|
| 244 | 236 | else |
|---|
| 245 | | - len = res->start + resource_size(res) |
|---|
| 237 | + len = range->start + range_len(range) |
|---|
| 246 | 238 | - bre->start; |
|---|
| 247 | | - __add_badblock_range(bb, start - res->start, len); |
|---|
| 239 | + __add_badblock_range(bb, start - range->start, len); |
|---|
| 248 | 240 | continue; |
|---|
| 249 | 241 | } |
|---|
| 250 | 242 | /* |
|---|
| 251 | 243 | * Deal with overlap for badrange starting before |
|---|
| 252 | 244 | * the namespace. |
|---|
| 253 | 245 | */ |
|---|
| 254 | | - if (bre->start < res->start) { |
|---|
| 246 | + if (bre->start < range->start) { |
|---|
| 255 | 247 | u64 len; |
|---|
| 256 | 248 | |
|---|
| 257 | | - if (bre_end < res->end) |
|---|
| 258 | | - len = bre->start + bre->length - res->start; |
|---|
| 249 | + if (bre_end < range->end) |
|---|
| 250 | + len = bre->start + bre->length - range->start; |
|---|
| 259 | 251 | else |
|---|
| 260 | | - len = resource_size(res); |
|---|
| 252 | + len = range_len(range); |
|---|
| 261 | 253 | __add_badblock_range(bb, 0, len); |
|---|
| 262 | 254 | } |
|---|
| 263 | 255 | } |
|---|
| .. | .. |
|---|
| 275 | 267 | * and add badblocks entries for all matching sub-ranges |
|---|
| 276 | 268 | */ |
|---|
| 277 | 269 | void nvdimm_badblocks_populate(struct nd_region *nd_region, |
|---|
| 278 | | - struct badblocks *bb, const struct resource *res) |
|---|
| 270 | + struct badblocks *bb, const struct range *range) |
|---|
| 279 | 271 | { |
|---|
| 280 | 272 | struct nvdimm_bus *nvdimm_bus; |
|---|
| 281 | 273 | |
|---|
| .. | .. |
|---|
| 287 | 279 | nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); |
|---|
| 288 | 280 | |
|---|
| 289 | 281 | nvdimm_bus_lock(&nvdimm_bus->dev); |
|---|
| 290 | | - badblocks_populate(&nvdimm_bus->badrange, bb, res); |
|---|
| 282 | + badblocks_populate(&nvdimm_bus->badrange, bb, range); |
|---|
| 291 | 283 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
|---|
| 292 | 284 | } |
|---|
| 293 | 285 | EXPORT_SYMBOL_GPL(nvdimm_badblocks_populate); |
|---|