Skip to content

Commit 4e4ced9

Browse files
rhvgoyaldjbw
authored andcommitted
dax: Move mandatory ->zero_page_range() check in alloc_dax()
zero_page_range() dax operation is mandatory for dax devices. Right now that check happens in dax_zero_page_range() function. Dan thinks that's too late and its better to do the check earlier in alloc_dax(). I also modified alloc_dax() to return pointer with error code in it in case of failure. Right now it returns NULL and caller assumes failure happened due to -ENOMEM. But with this ->zero_page_range() check, I need to return -EINVAL instead. Signed-off-by: Vivek Goyal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 4f3b4f1 commit 4e4ced9

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

drivers/dax/bus.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,10 @@ struct dev_dax *__devm_create_dev_dax(struct dax_region *dax_region, int id,
421421
* device outside of mmap of the resulting character device.
422422
*/
423423
dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC);
424-
if (!dax_dev)
424+
if (IS_ERR(dax_dev)) {
425+
rc = PTR_ERR(dax_dev);
425426
goto err;
427+
}
426428

427429
/* a device_dax instance is dead while the driver is not attached */
428430
kill_dax(dax_dev);

drivers/dax/super.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
349349
{
350350
if (!dax_alive(dax_dev))
351351
return -ENXIO;
352-
353-
if (!dax_dev->ops->zero_page_range)
354-
return -EOPNOTSUPP;
355352
/*
356353
* There are no callers that want to zero more than one page as of now.
357354
* Once users are there, this check can be removed after the
@@ -571,9 +568,16 @@ struct dax_device *alloc_dax(void *private, const char *__host,
571568
dev_t devt;
572569
int minor;
573570

571+
if (ops && !ops->zero_page_range) {
572+
pr_debug("%s: error: device does not provide dax"
573+
" operation zero_page_range()\n",
574+
__host ? __host : "Unknown");
575+
return ERR_PTR(-EINVAL);
576+
}
577+
574578
host = kstrdup(__host, GFP_KERNEL);
575579
if (__host && !host)
576-
return NULL;
580+
return ERR_PTR(-ENOMEM);
577581

578582
minor = ida_simple_get(&dax_minor_ida, 0, MINORMASK+1, GFP_KERNEL);
579583
if (minor < 0)
@@ -596,7 +600,7 @@ struct dax_device *alloc_dax(void *private, const char *__host,
596600
ida_simple_remove(&dax_minor_ida, minor);
597601
err_minor:
598602
kfree(host);
599-
return NULL;
603+
return ERR_PTR(-ENOMEM);
600604
}
601605
EXPORT_SYMBOL_GPL(alloc_dax);
602606

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ static struct mapped_device *alloc_dev(int minor)
20052005
if (IS_ENABLED(CONFIG_DAX_DRIVER)) {
20062006
md->dax_dev = alloc_dax(md, md->disk->disk_name,
20072007
&dm_dax_ops, 0);
2008-
if (!md->dax_dev)
2008+
if (IS_ERR(md->dax_dev))
20092009
goto bad;
20102010
}
20112011

drivers/nvdimm/pmem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ static int pmem_attach_disk(struct device *dev,
487487
if (is_nvdimm_sync(nd_region))
488488
flags = DAXDEV_F_SYNC;
489489
dax_dev = alloc_dax(pmem, disk->disk_name, &pmem_dax_ops, flags);
490-
if (!dax_dev) {
490+
if (IS_ERR(dax_dev)) {
491491
put_disk(disk);
492-
return -ENOMEM;
492+
return PTR_ERR(dax_dev);
493493
}
494494
dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
495495
pmem->dax_dev = dax_dev;

drivers/s390/block/dcssblk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
695695

696696
dev_info->dax_dev = alloc_dax(dev_info, dev_info->gd->disk_name,
697697
&dcssblk_dax_ops, DAXDEV_F_SYNC);
698-
if (!dev_info->dax_dev) {
699-
rc = -ENOMEM;
698+
if (IS_ERR(dev_info->dax_dev)) {
699+
rc = PTR_ERR(dev_info->dax_dev);
700+
dev_info->dax_dev = NULL;
700701
goto put_dev;
701702
}
702703

0 commit comments

Comments
 (0)