Skip to content

Commit a3cc31e

Browse files
committed
Merge tag 'libnvdimm-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Ira Weiny: "A mix of bug fixes and updates to interfaces used by nvdimm: - Updates to interfaces include: Use the new scope based management Remove deprecated ida interfaces Update to sysfs_emit() - Fixup kdoc comments" * tag 'libnvdimm-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: acpi/nfit: Use sysfs_emit() for all attributes nvdimm/namespace: fix kernel-doc for function params nvdimm/dimm_devs: fix kernel-doc for function params nvdimm/btt: fix btt_blk_cleanup() kernel-doc nvdimm-btt: simplify code with the scope based resource management nvdimm: Remove usage of the deprecated ida_simple_xx() API ACPI: NFIT: Use cleanup.h helpers instead of devm_*()
2 parents 2007758 + a085a5e commit a3cc31e

File tree

8 files changed

+71
-63
lines changed

8 files changed

+71
-63
lines changed

drivers/acpi/nfit/core.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ static ssize_t bus_dsm_mask_show(struct device *dev,
11861186
struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
11871187
struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
11881188

1189-
return sprintf(buf, "%#lx\n", acpi_desc->bus_dsm_mask);
1189+
return sysfs_emit(buf, "%#lx\n", acpi_desc->bus_dsm_mask);
11901190
}
11911191
static struct device_attribute dev_attr_bus_dsm_mask =
11921192
__ATTR(dsm_mask, 0444, bus_dsm_mask_show, NULL);
@@ -1198,7 +1198,7 @@ static ssize_t revision_show(struct device *dev,
11981198
struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
11991199
struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
12001200

1201-
return sprintf(buf, "%d\n", acpi_desc->acpi_header.revision);
1201+
return sysfs_emit(buf, "%d\n", acpi_desc->acpi_header.revision);
12021202
}
12031203
static DEVICE_ATTR_RO(revision);
12041204

@@ -1209,7 +1209,7 @@ static ssize_t hw_error_scrub_show(struct device *dev,
12091209
struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
12101210
struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
12111211

1212-
return sprintf(buf, "%d\n", acpi_desc->scrub_mode);
1212+
return sysfs_emit(buf, "%d\n", acpi_desc->scrub_mode);
12131213
}
12141214

12151215
/*
@@ -1278,7 +1278,7 @@ static ssize_t scrub_show(struct device *dev,
12781278
mutex_lock(&acpi_desc->init_mutex);
12791279
busy = test_bit(ARS_BUSY, &acpi_desc->scrub_flags)
12801280
&& !test_bit(ARS_CANCEL, &acpi_desc->scrub_flags);
1281-
rc = sprintf(buf, "%d%s", acpi_desc->scrub_count, busy ? "+\n" : "\n");
1281+
rc = sysfs_emit(buf, "%d%s", acpi_desc->scrub_count, busy ? "+\n" : "\n");
12821282
/* Allow an admin to poll the busy state at a higher rate */
12831283
if (busy && capable(CAP_SYS_RAWIO) && !test_and_set_bit(ARS_POLL,
12841284
&acpi_desc->scrub_flags)) {
@@ -1382,7 +1382,7 @@ static ssize_t handle_show(struct device *dev,
13821382
{
13831383
struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
13841384

1385-
return sprintf(buf, "%#x\n", memdev->device_handle);
1385+
return sysfs_emit(buf, "%#x\n", memdev->device_handle);
13861386
}
13871387
static DEVICE_ATTR_RO(handle);
13881388

@@ -1391,7 +1391,7 @@ static ssize_t phys_id_show(struct device *dev,
13911391
{
13921392
struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
13931393

1394-
return sprintf(buf, "%#x\n", memdev->physical_id);
1394+
return sysfs_emit(buf, "%#x\n", memdev->physical_id);
13951395
}
13961396
static DEVICE_ATTR_RO(phys_id);
13971397

@@ -1400,7 +1400,7 @@ static ssize_t vendor_show(struct device *dev,
14001400
{
14011401
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14021402

1403-
return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->vendor_id));
1403+
return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->vendor_id));
14041404
}
14051405
static DEVICE_ATTR_RO(vendor);
14061406

@@ -1409,7 +1409,7 @@ static ssize_t rev_id_show(struct device *dev,
14091409
{
14101410
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14111411

1412-
return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id));
1412+
return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id));
14131413
}
14141414
static DEVICE_ATTR_RO(rev_id);
14151415

@@ -1418,7 +1418,7 @@ static ssize_t device_show(struct device *dev,
14181418
{
14191419
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14201420

1421-
return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->device_id));
1421+
return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->device_id));
14221422
}
14231423
static DEVICE_ATTR_RO(device);
14241424

@@ -1427,7 +1427,7 @@ static ssize_t subsystem_vendor_show(struct device *dev,
14271427
{
14281428
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14291429

1430-
return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id));
1430+
return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id));
14311431
}
14321432
static DEVICE_ATTR_RO(subsystem_vendor);
14331433

@@ -1436,7 +1436,7 @@ static ssize_t subsystem_rev_id_show(struct device *dev,
14361436
{
14371437
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14381438

1439-
return sprintf(buf, "0x%04x\n",
1439+
return sysfs_emit(buf, "0x%04x\n",
14401440
be16_to_cpu(dcr->subsystem_revision_id));
14411441
}
14421442
static DEVICE_ATTR_RO(subsystem_rev_id);
@@ -1446,7 +1446,7 @@ static ssize_t subsystem_device_show(struct device *dev,
14461446
{
14471447
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14481448

1449-
return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id));
1449+
return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id));
14501450
}
14511451
static DEVICE_ATTR_RO(subsystem_device);
14521452

@@ -1465,7 +1465,7 @@ static ssize_t format_show(struct device *dev,
14651465
{
14661466
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
14671467

1468-
return sprintf(buf, "0x%04x\n", le16_to_cpu(dcr->code));
1468+
return sysfs_emit(buf, "0x%04x\n", le16_to_cpu(dcr->code));
14691469
}
14701470
static DEVICE_ATTR_RO(format);
14711471

@@ -1498,7 +1498,7 @@ static ssize_t format1_show(struct device *dev,
14981498
continue;
14991499
if (nfit_dcr->dcr->code == dcr->code)
15001500
continue;
1501-
rc = sprintf(buf, "0x%04x\n",
1501+
rc = sysfs_emit(buf, "0x%04x\n",
15021502
le16_to_cpu(nfit_dcr->dcr->code));
15031503
break;
15041504
}
@@ -1515,7 +1515,7 @@ static ssize_t formats_show(struct device *dev,
15151515
{
15161516
struct nvdimm *nvdimm = to_nvdimm(dev);
15171517

1518-
return sprintf(buf, "%d\n", num_nvdimm_formats(nvdimm));
1518+
return sysfs_emit(buf, "%d\n", num_nvdimm_formats(nvdimm));
15191519
}
15201520
static DEVICE_ATTR_RO(formats);
15211521

@@ -1524,7 +1524,7 @@ static ssize_t serial_show(struct device *dev,
15241524
{
15251525
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
15261526

1527-
return sprintf(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number));
1527+
return sysfs_emit(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number));
15281528
}
15291529
static DEVICE_ATTR_RO(serial);
15301530

@@ -1536,7 +1536,7 @@ static ssize_t family_show(struct device *dev,
15361536

15371537
if (nfit_mem->family < 0)
15381538
return -ENXIO;
1539-
return sprintf(buf, "%d\n", nfit_mem->family);
1539+
return sysfs_emit(buf, "%d\n", nfit_mem->family);
15401540
}
15411541
static DEVICE_ATTR_RO(family);
15421542

@@ -1548,7 +1548,7 @@ static ssize_t dsm_mask_show(struct device *dev,
15481548

15491549
if (nfit_mem->family < 0)
15501550
return -ENXIO;
1551-
return sprintf(buf, "%#lx\n", nfit_mem->dsm_mask);
1551+
return sysfs_emit(buf, "%#lx\n", nfit_mem->dsm_mask);
15521552
}
15531553
static DEVICE_ATTR_RO(dsm_mask);
15541554

@@ -1562,7 +1562,7 @@ static ssize_t flags_show(struct device *dev,
15621562
if (test_bit(NFIT_MEM_DIRTY, &nfit_mem->flags))
15631563
flags |= ACPI_NFIT_MEM_FLUSH_FAILED;
15641564

1565-
return sprintf(buf, "%s%s%s%s%s%s%s\n",
1565+
return sysfs_emit(buf, "%s%s%s%s%s%s%s\n",
15661566
flags & ACPI_NFIT_MEM_SAVE_FAILED ? "save_fail " : "",
15671567
flags & ACPI_NFIT_MEM_RESTORE_FAILED ? "restore_fail " : "",
15681568
flags & ACPI_NFIT_MEM_FLUSH_FAILED ? "flush_fail " : "",
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
15791579
struct nvdimm *nvdimm = to_nvdimm(dev);
15801580
struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
15811581

1582-
return sprintf(buf, "%s\n", nfit_mem->id);
1582+
return sysfs_emit(buf, "%s\n", nfit_mem->id);
15831583
}
15841584
static DEVICE_ATTR_RO(id);
15851585

@@ -1589,7 +1589,7 @@ static ssize_t dirty_shutdown_show(struct device *dev,
15891589
struct nvdimm *nvdimm = to_nvdimm(dev);
15901590
struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
15911591

1592-
return sprintf(buf, "%d\n", nfit_mem->dirty_shutdown);
1592+
return sysfs_emit(buf, "%d\n", nfit_mem->dirty_shutdown);
15931593
}
15941594
static DEVICE_ATTR_RO(dirty_shutdown);
15951595

@@ -2172,7 +2172,7 @@ static ssize_t range_index_show(struct device *dev,
21722172
struct nd_region *nd_region = to_nd_region(dev);
21732173
struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region);
21742174

2175-
return sprintf(buf, "%d\n", nfit_spa->spa->range_index);
2175+
return sysfs_emit(buf, "%d\n", nfit_spa->spa->range_index);
21762176
}
21772177
static DEVICE_ATTR_RO(range_index);
21782178

@@ -2257,26 +2257,23 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
22572257
struct nd_region_desc *ndr_desc,
22582258
struct acpi_nfit_system_address *spa)
22592259
{
2260+
u16 nr = ndr_desc->num_mappings;
2261+
struct nfit_set_info2 *info2 __free(kfree) =
2262+
kcalloc(nr, sizeof(*info2), GFP_KERNEL);
2263+
struct nfit_set_info *info __free(kfree) =
2264+
kcalloc(nr, sizeof(*info), GFP_KERNEL);
22602265
struct device *dev = acpi_desc->dev;
22612266
struct nd_interleave_set *nd_set;
2262-
u16 nr = ndr_desc->num_mappings;
2263-
struct nfit_set_info2 *info2;
2264-
struct nfit_set_info *info;
22652267
int i;
22662268

2269+
if (!info || !info2)
2270+
return -ENOMEM;
2271+
22672272
nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL);
22682273
if (!nd_set)
22692274
return -ENOMEM;
22702275
import_guid(&nd_set->type_guid, spa->range_guid);
22712276

2272-
info = devm_kcalloc(dev, nr, sizeof(*info), GFP_KERNEL);
2273-
if (!info)
2274-
return -ENOMEM;
2275-
2276-
info2 = devm_kcalloc(dev, nr, sizeof(*info2), GFP_KERNEL);
2277-
if (!info2)
2278-
return -ENOMEM;
2279-
22802277
for (i = 0; i < nr; i++) {
22812278
struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
22822279
struct nvdimm *nvdimm = mapping->nvdimm;
@@ -2337,8 +2334,6 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
23372334
}
23382335

23392336
ndr_desc->nd_set = nd_set;
2340-
devm_kfree(dev, info);
2341-
devm_kfree(dev, info2);
23422337

23432338
return 0;
23442339
}

drivers/nvdimm/btt.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/fs.h>
1717
#include <linux/nd.h>
1818
#include <linux/backing-dev.h>
19+
#include <linux/cleanup.h>
1920
#include "btt.h"
2021
#include "nd.h"
2122

@@ -847,23 +848,20 @@ static int discover_arenas(struct btt *btt)
847848
{
848849
int ret = 0;
849850
struct arena_info *arena;
850-
struct btt_sb *super;
851851
size_t remaining = btt->rawsize;
852852
u64 cur_nlba = 0;
853853
size_t cur_off = 0;
854854
int num_arenas = 0;
855855

856-
super = kzalloc(sizeof(*super), GFP_KERNEL);
856+
struct btt_sb *super __free(kfree) = kzalloc(sizeof(*super), GFP_KERNEL);
857857
if (!super)
858858
return -ENOMEM;
859859

860860
while (remaining) {
861861
/* Alloc memory for arena */
862862
arena = alloc_arena(btt, 0, 0, 0);
863-
if (!arena) {
864-
ret = -ENOMEM;
865-
goto out_super;
866-
}
863+
if (!arena)
864+
return -ENOMEM;
867865

868866
arena->infooff = cur_off;
869867
ret = btt_info_read(arena, super);
@@ -919,14 +917,11 @@ static int discover_arenas(struct btt *btt)
919917
btt->nlba = cur_nlba;
920918
btt->init_state = INIT_READY;
921919

922-
kfree(super);
923920
return ret;
924921

925922
out:
926923
kfree(arena);
927924
free_arenas(btt);
928-
out_super:
929-
kfree(super);
930925
return ret;
931926
}
932927

@@ -1550,7 +1545,7 @@ static void btt_blk_cleanup(struct btt *btt)
15501545
* @rawsize: raw size in bytes of the backing device
15511546
* @lbasize: lba size of the backing device
15521547
* @uuid: A uuid for the backing device - this is stored on media
1553-
* @maxlane: maximum number of parallel requests the device can handle
1548+
* @nd_region: &struct nd_region for the REGION device
15541549
*
15551550
* Initialize a Block Translation Table on a backing device to provide
15561551
* single sector power fail atomicity.

drivers/nvdimm/btt_devs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void nd_btt_release(struct device *dev)
1919

2020
dev_dbg(dev, "trace\n");
2121
nd_detach_ndns(&nd_btt->dev, &nd_btt->ndns);
22-
ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
22+
ida_free(&nd_region->btt_ida, nd_btt->id);
2323
kfree(nd_btt->uuid);
2424
kfree(nd_btt);
2525
}
@@ -191,7 +191,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
191191
if (!nd_btt)
192192
return NULL;
193193

194-
nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
194+
nd_btt->id = ida_alloc(&nd_region->btt_ida, GFP_KERNEL);
195195
if (nd_btt->id < 0)
196196
goto out_nd_btt;
197197

@@ -217,7 +217,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
217217
return dev;
218218

219219
out_put_id:
220-
ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
220+
ida_free(&nd_region->btt_ida, nd_btt->id);
221221

222222
out_nd_btt:
223223
kfree(nd_btt);

drivers/nvdimm/bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static void nvdimm_bus_release(struct device *dev)
285285
struct nvdimm_bus *nvdimm_bus;
286286

287287
nvdimm_bus = container_of(dev, struct nvdimm_bus, dev);
288-
ida_simple_remove(&nd_ida, nvdimm_bus->id);
288+
ida_free(&nd_ida, nvdimm_bus->id);
289289
kfree(nvdimm_bus);
290290
}
291291

@@ -342,7 +342,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
342342
INIT_LIST_HEAD(&nvdimm_bus->list);
343343
INIT_LIST_HEAD(&nvdimm_bus->mapping_list);
344344
init_waitqueue_head(&nvdimm_bus->wait);
345-
nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL);
345+
nvdimm_bus->id = ida_alloc(&nd_ida, GFP_KERNEL);
346346
if (nvdimm_bus->id < 0) {
347347
kfree(nvdimm_bus);
348348
return NULL;

drivers/nvdimm/dax_devs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void nd_dax_release(struct device *dev)
1818

1919
dev_dbg(dev, "trace\n");
2020
nd_detach_ndns(dev, &nd_pfn->ndns);
21-
ida_simple_remove(&nd_region->dax_ida, nd_pfn->id);
21+
ida_free(&nd_region->dax_ida, nd_pfn->id);
2222
kfree(nd_pfn->uuid);
2323
kfree(nd_dax);
2424
}
@@ -55,7 +55,7 @@ static struct nd_dax *nd_dax_alloc(struct nd_region *nd_region)
5555
return NULL;
5656

5757
nd_pfn = &nd_dax->nd_pfn;
58-
nd_pfn->id = ida_simple_get(&nd_region->dax_ida, 0, 0, GFP_KERNEL);
58+
nd_pfn->id = ida_alloc(&nd_region->dax_ida, GFP_KERNEL);
5959
if (nd_pfn->id < 0) {
6060
kfree(nd_dax);
6161
return NULL;

0 commit comments

Comments
 (0)