Skip to contentSkip to conversation

nvmem: core: Remove unused devm_nvmem_unregister()

PATCH In review Andy Shevchenko 2 participants 7 messages Jan 24, 2022 – Jan 25, 2022

Subsystems (4)
lore
Share & tools
lore
#4 lore raw

PATCH v2 5/5 thunderbolt: Drop duplicate NULL checks around nvmem_unregister()

In reply to Andy Shevchenko

Since nvmem_unregister() checks for NULL, no need to repeat in the caller. Drop duplicate NULL checks.

---
v2: added tag (Mika)

 drivers/thunderbolt/nvm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thunderbolt/nvm.c +2 -4
index 3a5336913cca..b3f310389378 100644
@@ -154,10 +154,8 @@ int tb_nvm_add_non_active(struct tb_nvm *nvm, size_t size,
 void tb_nvm_free(struct tb_nvm *nvm)
 {
 	if (nvm) {
-		if (nvm->non_active)
-			nvmem_unregister(nvm->non_active);
-		if (nvm->active)
-			nvmem_unregister(nvm->active);
+		nvmem_unregister(nvm->non_active);
+		nvmem_unregister(nvm->active);
 		vfree(nvm->buf);
 		ida_simple_remove(&nvm_ida, nvm->id);
 	}
Signature · 1 line
2.34.1
#0 lore raw

PATCH v2 1/5 nvmem: core: Remove unused devm_nvmem_unregister()

There are no users and seems no will come of the devm_nvmem_unregister(). Remove the function and remove the unused devm_nvmem_match() along with it.

---
v2: removed unused devm_nvmem_match() (lkp)

 drivers/nvmem/core.c           | 22 ----------------------
 include/linux/nvmem-provider.h |  8 --------
 2 files changed, 30 deletions(-)
drivers/nvmem/core.c +0 -22
index 23a38dcf0fc4..1a70b3bdb71d 100644
@@ -945,28 +945,6 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_nvmem_register);
 
-static int devm_nvmem_match(struct device *dev, void *res, void *data)
-{
-	struct nvmem_device **r = res;
-
-	return *r == data;
-}
-
-/**
- * devm_nvmem_unregister() - Unregister previously registered managed nvmem
- * device.
- *
- * @dev: Device that uses the nvmem device.
- * @nvmem: Pointer to previously registered nvmem device.
- *
- * Return: Will be negative on error or zero on success.
- */
-int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
-{
-	return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem);
-}
-EXPORT_SYMBOL(devm_nvmem_unregister);
-
 static struct nvmem_device *__nvmem_device_get(void *data,
 			int (*match)(struct device *dev, const void *data))
 {
include/linux/nvmem-provider.h +0 -8
index 98efb7b5660d..99c01c43d7a8 100644
@@ -133,8 +133,6 @@ void nvmem_unregister(struct nvmem_device *nvmem);
 struct nvmem_device *devm_nvmem_register(struct device *dev,
 					 const struct nvmem_config *cfg);
 
-int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
-
 void nvmem_add_cell_table(struct nvmem_cell_table *table);
 void nvmem_del_cell_table(struct nvmem_cell_table *table);
 
@@ -153,12 +151,6 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
 	return nvmem_register(c);
 }
 
-static inline int
-devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
-{
-	return -EOPNOTSUPP;
-}
-
 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/5 nvmem: core: Use devm_add_action_or_reset()

Slightly simplify the devm_nvmem_register() by using the devm_add_action_or_reset().

---
v2: no changes

 drivers/nvmem/core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/nvmem/core.c +9 -13
index 1a70b3bdb71d..68db7d3303ac 100644
@@ -907,9 +907,9 @@ void nvmem_unregister(struct nvmem_device *nvmem)
 }
 EXPORT_SYMBOL_GPL(nvmem_unregister);
 
-static void devm_nvmem_release(struct device *dev, void *res)
+static void devm_nvmem_unregister(void *nvmem)
 {
-	nvmem_unregister(*(struct nvmem_device **)res);
+	nvmem_unregister(nvmem);
 }
 
 /**
@@ -926,20 +926,16 @@ static void devm_nvmem_release(struct device *dev, void *res)
 struct nvmem_device *devm_nvmem_register(struct device *dev,
 					 const struct nvmem_config *config)
 {
-	struct nvmem_device **ptr, *nvmem;
-
-	ptr = devres_alloc(devm_nvmem_release, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr)
-		return ERR_PTR(-ENOMEM);
+	struct nvmem_device *nvmem;
+	int ret;
 
 	nvmem = nvmem_register(config);
+	if (IS_ERR(nvmem))
+		return nvmem;
 
-	if (!IS_ERR(nvmem)) {
-		*ptr = nvmem;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-	}
+	ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem);
+	if (ret)
+		return ERR_PTR(ret);
 
 	return nvmem;
 }
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 3/5 nvmem: core: Check input parameter for NULL in nvmem_unregister()

In reply to Andy Shevchenko

nvmem_unregister() frees resources and standard pattern is to allow caller to not care if it's NULL or not. This will reduce burden on the callers to perform this check.

---
v2: no changes

 drivers/nvmem/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +2 -1
index 68db7d3303ac..53a43d843743 100644
@@ -903,7 +903,8 @@ static void nvmem_device_release(struct kref *kref)
  */
 void nvmem_unregister(struct nvmem_device *nvmem)
 {
-	kref_put(&nvmem->refcnt, nvmem_device_release);
+	if (nvmem)
+		kref_put(&nvmem->refcnt, nvmem_device_release);
 }
 EXPORT_SYMBOL_GPL(nvmem_unregister);
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 4/5 mtd: core: Drop duplicate NULL checks around nvmem_unregister()

In reply to Andy Shevchenko

Since nvmem_unregister() checks for NULL, no need to repeat in the caller. Drop duplicate NULL checks.

---
v2: added tag (Miquel)

 drivers/mtd/mtdcore.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/mtd/mtdcore.c +4 -9
index 70f492dce158..010ffc34532a 100644
@@ -742,8 +742,7 @@ int del_mtd_device(struct mtd_info *mtd)
 		debugfs_remove_recursive(mtd->dbg.dfs_dir);
 
 		/* Try to remove the NVMEM provider */
-		if (mtd->nvmem)
-			nvmem_unregister(mtd->nvmem);
+		nvmem_unregister(mtd->nvmem);
 
 		device_unregister(&mtd->dev);
 
@@ -921,8 +920,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
 	return 0;
 
 err:
-	if (mtd->otp_user_nvmem)
-		nvmem_unregister(mtd->otp_user_nvmem);
+	nvmem_unregister(mtd->otp_user_nvmem);
 	return err;
 }
 
@@ -1026,11 +1024,8 @@ int mtd_device_unregister(struct mtd_info *master)
 		memset(&master->reboot_notifier, 0, sizeof(master->reboot_notifier));
 	}
 
-	if (master->otp_user_nvmem)
-		nvmem_unregister(master->otp_user_nvmem);
-
-	if (master->otp_factory_nvmem)
-		nvmem_unregister(master->otp_factory_nvmem);
+	nvmem_unregister(master->otp_user_nvmem);
+	nvmem_unregister(master->otp_factory_nvmem);
 
 	err = del_mtd_partitions(master);
 	if (err)
Signature · 1 line
2.34.1
#5 lore raw
In reply to Andy Shevchenko

Thanks Andy for the cleanup,

Quoted 4 lines · Andy Shevchenko

There are no users and seems no will come of the devm_nvmem_unregister(). Remove the function and remove the unused devm_nvmem_match() along with it.

Applied 1/5, 2/5 and 3/5 patches.

Others can go via there own subsystems as I do not see any dependencies.

--srini

Quoted 55 lines

---
v2: removed unused devm_nvmem_match() (lkp)

  drivers/nvmem/core.c           | 22 ----------------------
  include/linux/nvmem-provider.h |  8 --------
  2 files changed, 30 deletions(-)
drivers/nvmem/core.c +0 -22
index 23a38dcf0fc4..1a70b3bdb71d 100644
@@ -945,28 +945,6 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
  }
  EXPORT_SYMBOL_GPL(devm_nvmem_register);
 
-static int devm_nvmem_match(struct device *dev, void *res, void *data)
-{
-	struct nvmem_device **r = res;
-
-	return *r == data;
-}
-
-/**
- * devm_nvmem_unregister() - Unregister previously registered managed nvmem
- * device.
- *
- * @dev: Device that uses the nvmem device.
- * @nvmem: Pointer to previously registered nvmem device.
- *
- * Return: Will be negative on error or zero on success.
- */
-int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
-{
-	return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem);
-}
-EXPORT_SYMBOL(devm_nvmem_unregister);
-
  static struct nvmem_device *__nvmem_device_get(void *data,
  			int (*match)(struct device *dev, const void *data))
  {
include/linux/nvmem-provider.h +0 -2
index 98efb7b5660d..99c01c43d7a8 100644
@@ -133,8 +133,6 @@ void nvmem_unregister(struct nvmem_device *nvmem);
  struct nvmem_device *devm_nvmem_register(struct device *dev,
  					 const struct nvmem_config *cfg);
 
-int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
-
  void nvmem_add_cell_table(struct nvmem_cell_table *table);
  void nvmem_del_cell_table(struct nvmem_cell_table *table);
 
@@ -153,12 +151,6 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
  	return nvmem_register(c);
  }

include/linux/nvmem-provider.h devm_nvmem_register(struct device *dev, const struct nvmem_config *c) · line 156

Quoted 10 lines
include/linux/nvmem-provider.h +0 -6
 
-static inline int
-devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
-{
-	return -EOPNOTSUPP;
-}
-
  static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
  static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw
Quoted 5 lines · Srinivas Kandagatla
Quoted 2 lines · Andy Shevchenko

There are no users and seems no will come of the devm_nvmem_unregister(). Remove the function and remove the unused devm_nvmem_match() along with it.

Applied 1/5, 2/5 and 3/5 patches.

Thanks!

Quoted 1 line

Others can go via there own subsystems as I do not see any dependencies.

They are dependent on the patch 3 ("nvmem: core: Check input parameter for NULL in nvmem_unregister()"). Since there are tags, can you apply them as well?

Signature · 8 lines
With Best Regards,
Andy Shevchenko



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/