* [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister()
@ 2022-01-24 18:00 Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 2/5] nvmem: core: Use devm_add_action_or_reset() Andy Shevchenko
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-24 18:00 UTC (permalink / raw)
To: Miquel Raynal, Greg Kroah-Hartman, Srinivas Kandagatla,
Mika Westerberg, Andy Shevchenko, linux-mtd, linux-kernel,
linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: removed unused devm_nvmem_match() (lkp)
drivers/nvmem/core.c | 22 ----------------------
include/linux/nvmem-provider.h | 8 --------
2 files changed, 30 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 23a38dcf0fc4..1a70b3bdb71d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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))
{
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 98efb7b5660d..99c01c43d7a8 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -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) {}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] nvmem: core: Use devm_add_action_or_reset()
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
@ 2022-01-24 18:00 ` Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 3/5] nvmem: core: Check input parameter for NULL in nvmem_unregister() Andy Shevchenko
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-24 18:00 UTC (permalink / raw)
To: Miquel Raynal, Greg Kroah-Hartman, Srinivas Kandagatla,
Mika Westerberg, Andy Shevchenko, linux-mtd, linux-kernel,
linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
Slightly simplify the devm_nvmem_register() by using the
devm_add_action_or_reset().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: no changes
drivers/nvmem/core.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 1a70b3bdb71d..68db7d3303ac 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] nvmem: core: Check input parameter for NULL in nvmem_unregister()
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 2/5] nvmem: core: Use devm_add_action_or_reset() Andy Shevchenko
@ 2022-01-24 18:00 ` Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 4/5] mtd: core: Drop duplicate NULL checks around nvmem_unregister() Andy Shevchenko
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-24 18:00 UTC (permalink / raw)
To: Miquel Raynal, Greg Kroah-Hartman, Srinivas Kandagatla,
Mika Westerberg, Andy Shevchenko, linux-mtd, linux-kernel,
linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: no changes
drivers/nvmem/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 68db7d3303ac..53a43d843743 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] mtd: core: Drop duplicate NULL checks around nvmem_unregister()
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 2/5] nvmem: core: Use devm_add_action_or_reset() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 3/5] nvmem: core: Check input parameter for NULL in nvmem_unregister() Andy Shevchenko
@ 2022-01-24 18:00 ` Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 5/5] thunderbolt: " Andy Shevchenko
2022-01-25 10:35 ` [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Srinivas Kandagatla
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-24 18:00 UTC (permalink / raw)
To: Miquel Raynal, Greg Kroah-Hartman, Srinivas Kandagatla,
Mika Westerberg, Andy Shevchenko, linux-mtd, linux-kernel,
linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
Since nvmem_unregister() checks for NULL, no need to repeat in
the caller. Drop duplicate NULL checks.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
v2: added tag (Miquel)
drivers/mtd/mtdcore.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 70f492dce158..010ffc34532a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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)
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] thunderbolt: Drop duplicate NULL checks around nvmem_unregister()
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
` (2 preceding siblings ...)
2022-01-24 18:00 ` [PATCH v2 4/5] mtd: core: Drop duplicate NULL checks around nvmem_unregister() Andy Shevchenko
@ 2022-01-24 18:00 ` Andy Shevchenko
2022-01-25 10:35 ` [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Srinivas Kandagatla
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-24 18:00 UTC (permalink / raw)
To: Miquel Raynal, Greg Kroah-Hartman, Srinivas Kandagatla,
Mika Westerberg, Andy Shevchenko, linux-mtd, linux-kernel,
linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
Since nvmem_unregister() checks for NULL, no need to repeat in
the caller. Drop duplicate NULL checks.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
v2: added tag (Mika)
drivers/thunderbolt/nvm.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/thunderbolt/nvm.c b/drivers/thunderbolt/nvm.c
index 3a5336913cca..b3f310389378 100644
--- a/drivers/thunderbolt/nvm.c
+++ b/drivers/thunderbolt/nvm.c
@@ -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);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister()
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
` (3 preceding siblings ...)
2022-01-24 18:00 ` [PATCH v2 5/5] thunderbolt: " Andy Shevchenko
@ 2022-01-25 10:35 ` Srinivas Kandagatla
2022-01-25 14:04 ` Andy Shevchenko
4 siblings, 1 reply; 7+ messages in thread
From: Srinivas Kandagatla @ 2022-01-25 10:35 UTC (permalink / raw)
To: Andy Shevchenko, Miquel Raynal, Greg Kroah-Hartman,
Mika Westerberg, linux-mtd, linux-kernel, linux-usb
Cc: Richard Weinberger, Vignesh Raghavendra, Andreas Noever,
Michael Jamet, Yehezkel Bernat
Thanks Andy for the cleanup,
On 24/01/2022 18:00, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Applied 1/5, 2/5 and 3/5 patches.
Others can go via there own subsystems as I do not see any dependencies.
--srini
> ---
> v2: removed unused devm_nvmem_match() (lkp)
> drivers/nvmem/core.c | 22 ----------------------
> include/linux/nvmem-provider.h | 8 --------
> 2 files changed, 30 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 23a38dcf0fc4..1a70b3bdb71d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -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))
> {
> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index 98efb7b5660d..99c01c43d7a8 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -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) {}
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister()
2022-01-25 10:35 ` [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Srinivas Kandagatla
@ 2022-01-25 14:04 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-01-25 14:04 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Miquel Raynal, Greg Kroah-Hartman, Mika Westerberg, linux-mtd,
linux-kernel, linux-usb, Richard Weinberger, Vignesh Raghavendra,
Andreas Noever, Michael Jamet, Yehezkel Bernat
On Tue, Jan 25, 2022 at 10:35:24AM +0000, Srinivas Kandagatla wrote:
> On 24/01/2022 18:00, Andy Shevchenko wrote:
> > 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!
> 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?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-01-25 14:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 18:00 [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 2/5] nvmem: core: Use devm_add_action_or_reset() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 3/5] nvmem: core: Check input parameter for NULL in nvmem_unregister() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 4/5] mtd: core: Drop duplicate NULL checks around nvmem_unregister() Andy Shevchenko
2022-01-24 18:00 ` [PATCH v2 5/5] thunderbolt: " Andy Shevchenko
2022-01-25 10:35 ` [PATCH v2 1/5] nvmem: core: Remove unused devm_nvmem_unregister() Srinivas Kandagatla
2022-01-25 14:04 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).