diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 260a247c60d2da5c56c93144cdaac1340fd2750a..a2463320b86b51732d6c79cc9e71bbcd15c9b99f 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -433,6 +433,11 @@ static int dax_host_hash(const char *host) * that any fault handlers or operations that might have seen * dax_alive(), have completed. Any operations that start after * synchronize_srcu() has run will abort upon seeing !dax_alive(). + * + * Note, because alloc_dax() returns an ERR_PTR() on error, callers + * typically store its result into a local variable in order to check + * the result. Therefore, care must be taken to populate the struct + * device dax_dev field make sure the dax_dev is not leaked. */ void kill_dax(struct dax_device *dax_dev) { diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index d5dd79b59b16c0254d85ba66cda179c3ab173594..9947cc2bd2fc5a6448ea49d6437af44bc531829b 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -498,7 +498,13 @@ static int pmem_attach_disk(struct device *dev, gendev = disk_to_dev(disk); gendev->groups = pmem_attribute_groups; - device_add_disk(dev, disk, NULL); + rc = device_add_disk_safe(dev, disk, NULL); + if (rc) { + kill_dax(dax_dev); + put_dax(dax_dev); + put_disk(disk); + return rc; + } if (devm_add_action_or_reset(dev, pmem_release_disk, pmem)) return -ENOMEM; diff --git a/include/linux/dax.h b/include/linux/dax.h index b52f084aa643434a2c9554259814b5ba59c5eda6..f6f26a66ead07ba406567d4ffc32fa0e20851a37 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -80,11 +80,7 @@ static inline struct dax_device *dax_get_by_host(const char *host) static inline struct dax_device *alloc_dax(void *private, const char *host, const struct dax_operations *ops, unsigned long flags) { - /* - * Callers should check IS_ENABLED(CONFIG_DAX) to know if this - * NULL is an error or expected. - */ - return NULL; + return ERR_PTR(-EOPNOTSUPP); } static inline void put_dax(struct dax_device *dax_dev) {