* [PATCH] lightnvm: propagate device_add() error code
@ 2016-09-15 15:53 Arnd Bergmann
2016-09-16 10:19 ` Matias Bjørling
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-09-15 15:53 UTC (permalink / raw)
To: Matias Bjorling
Cc: Arnd Bergmann, Simon A. F. Lund, Matias Bjørling,
linux-block, linux-kernel
device_add() may fail, and all callers are supposed to check the
return value, but one new user in lightnvm doesn't:
drivers/lightnvm/sysfs.c: In function 'nvm_sysfs_register_dev':
drivers/lightnvm/sysfs.c:184:2: error: ignoring return value of 'device_add', declared with attribute warn_unused_result [-Werror=unused-result]
This changes the caller to propagate any error codes, which avoids
the warning.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 38c9e260b9f9 ("lightnvm: expose device geometry through sysfs")
---
drivers/lightnvm/lightnvm.h | 2 +-
drivers/lightnvm/sysfs.c | 9 ++++++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h
index 93f1aacc9f02..305c181509a6 100644
--- a/drivers/lightnvm/lightnvm.h
+++ b/drivers/lightnvm/lightnvm.h
@@ -24,7 +24,7 @@
#include <linux/lightnvm.h>
/* core -> sysfs.c */
-int nvm_sysfs_register_dev(struct nvm_dev *);
+int __must_check nvm_sysfs_register_dev(struct nvm_dev *);
void nvm_sysfs_unregister_dev(struct nvm_dev *);
int nvm_sysfs_register(void);
void nvm_sysfs_unregister(void);
diff --git a/drivers/lightnvm/sysfs.c b/drivers/lightnvm/sysfs.c
index 72ad089c0269..0338c27ab95a 100644
--- a/drivers/lightnvm/sysfs.c
+++ b/drivers/lightnvm/sysfs.c
@@ -174,6 +174,8 @@ static struct device_type nvm_type = {
int nvm_sysfs_register_dev(struct nvm_dev *dev)
{
+ int ret;
+
if (!dev->parent_dev)
return 0;
@@ -181,11 +183,12 @@ int nvm_sysfs_register_dev(struct nvm_dev *dev)
dev_set_name(&dev->dev, "%s", dev->name);
dev->dev.type = &nvm_type;
device_initialize(&dev->dev);
- device_add(&dev->dev);
+ ret = device_add(&dev->dev);
- blk_mq_register_dev(&dev->dev, dev->q);
+ if (!ret)
+ blk_mq_register_dev(&dev->dev, dev->q);
- return 0;
+ return ret;
}
void nvm_sysfs_unregister_dev(struct nvm_dev *dev)
--
2.9.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lightnvm: propagate device_add() error code
2016-09-15 15:53 [PATCH] lightnvm: propagate device_add() error code Arnd Bergmann
@ 2016-09-16 10:19 ` Matias Bjørling
0 siblings, 0 replies; 2+ messages in thread
From: Matias Bjørling @ 2016-09-16 10:19 UTC (permalink / raw)
To: Arnd Bergmann, Matias Bjorling
Cc: Simon A. F. Lund, linux-block, linux-kernel
On 09/15/2016 05:53 PM, Arnd Bergmann wrote:
> device_add() may fail, and all callers are supposed to check the
> return value, but one new user in lightnvm doesn't:
>
> drivers/lightnvm/sysfs.c: In function 'nvm_sysfs_register_dev':
> drivers/lightnvm/sysfs.c:184:2: error: ignoring return value of 'device_add', declared with attribute warn_unused_result [-Werror=unused-result]
>
> This changes the caller to propagate any error codes, which avoids
> the warning.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: 38c9e260b9f9 ("lightnvm: expose device geometry through sysfs")
> ---
> drivers/lightnvm/lightnvm.h | 2 +-
> drivers/lightnvm/sysfs.c | 9 ++++++---
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h
> index 93f1aacc9f02..305c181509a6 100644
> --- a/drivers/lightnvm/lightnvm.h
> +++ b/drivers/lightnvm/lightnvm.h
> @@ -24,7 +24,7 @@
> #include <linux/lightnvm.h>
>
> /* core -> sysfs.c */
> -int nvm_sysfs_register_dev(struct nvm_dev *);
> +int __must_check nvm_sysfs_register_dev(struct nvm_dev *);
> void nvm_sysfs_unregister_dev(struct nvm_dev *);
> int nvm_sysfs_register(void);
> void nvm_sysfs_unregister(void);
> diff --git a/drivers/lightnvm/sysfs.c b/drivers/lightnvm/sysfs.c
> index 72ad089c0269..0338c27ab95a 100644
> --- a/drivers/lightnvm/sysfs.c
> +++ b/drivers/lightnvm/sysfs.c
> @@ -174,6 +174,8 @@ static struct device_type nvm_type = {
>
> int nvm_sysfs_register_dev(struct nvm_dev *dev)
> {
> + int ret;
> +
> if (!dev->parent_dev)
> return 0;
>
> @@ -181,11 +183,12 @@ int nvm_sysfs_register_dev(struct nvm_dev *dev)
> dev_set_name(&dev->dev, "%s", dev->name);
> dev->dev.type = &nvm_type;
> device_initialize(&dev->dev);
> - device_add(&dev->dev);
> + ret = device_add(&dev->dev);
>
> - blk_mq_register_dev(&dev->dev, dev->q);
> + if (!ret)
> + blk_mq_register_dev(&dev->dev, dev->q);
>
> - return 0;
> + return ret;
> }
>
> void nvm_sysfs_unregister_dev(struct nvm_dev *dev)
>
Thans Arnd. Applied for 4.9.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-16 10:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 15:53 [PATCH] lightnvm: propagate device_add() error code Arnd Bergmann
2016-09-16 10:19 ` Matias Bjørling
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).