* [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling
@ 2021-11-03 16:40 Luis Chamberlain
2021-11-03 16:41 ` Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Luis Chamberlain @ 2021-11-03 16:40 UTC (permalink / raw)
To: axboe, hare, hch
Cc: linux-block, linux-kernel, Luis Chamberlain, kernel test robot,
Dan Carpenter
Commit 83cbce957446 ("block: add error handling for device_add_disk /
add_disk") added error handling to device_add_disk(), however the goto
label for the kobject_create_and_add() failure did not set the return
value correctly, and so we can end up in a situation where
kobject_create_and_add() fails but we report success.
Fixes: 83cbce957446 ("block: add error handling for device_add_disk / add_disk")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
block/genhd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c
index be4775c13760..b0b484116c3a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -478,8 +478,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
if (!disk->part0->bd_holder_dir)
goto out_del_integrity;
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
- if (!disk->slave_dir)
+ if (!disk->slave_dir) {
+ ret = -ENOMEM;
goto out_put_holder_dir;
+ }
ret = bd_register_pending_holders(disk);
if (ret < 0)
--
2.33.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling
2021-11-03 16:40 [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling Luis Chamberlain
@ 2021-11-03 16:41 ` Christoph Hellwig
2021-11-03 19:28 ` Jens Axboe
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-11-03 16:41 UTC (permalink / raw)
To: Luis Chamberlain
Cc: axboe, hare, hch, linux-block, linux-kernel, kernel test robot,
Dan Carpenter
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling
2021-11-03 16:40 [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling Luis Chamberlain
2021-11-03 16:41 ` Christoph Hellwig
@ 2021-11-03 19:28 ` Jens Axboe
2021-11-04 10:55 ` Wu Bo
2021-11-04 10:57 ` Wu Bo
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-11-03 19:28 UTC (permalink / raw)
To: Luis Chamberlain, hare, hch
Cc: linux-block, Dan Carpenter, kernel test robot, linux-kernel
On Wed, 3 Nov 2021 09:40:23 -0700, Luis Chamberlain wrote:
> Commit 83cbce957446 ("block: add error handling for device_add_disk /
> add_disk") added error handling to device_add_disk(), however the goto
> label for the kobject_create_and_add() failure did not set the return
> value correctly, and so we can end up in a situation where
> kobject_create_and_add() fails but we report success.
>
>
> [...]
Applied, thanks!
[1/1] block: fix device_add_disk() kobject_create_and_add() error handling
commit: 3554ce121f632db1f56f4e28dfe37da846617c9c
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling
2021-11-03 16:40 [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling Luis Chamberlain
2021-11-03 16:41 ` Christoph Hellwig
2021-11-03 19:28 ` Jens Axboe
@ 2021-11-04 10:55 ` Wu Bo
2021-11-04 10:57 ` Wu Bo
3 siblings, 0 replies; 5+ messages in thread
From: Wu Bo @ 2021-11-04 10:55 UTC (permalink / raw)
To: Luis Chamberlain, axboe, hare, hch
Cc: linux-block, linux-kernel, kernel test robot, Dan Carpenter
On 2021/11/4 0:40, Luis Chamberlain wrote:
> Commit 83cbce957446 ("block: add error handling for device_add_disk /
> add_disk") added error handling to device_add_disk(), however the goto
> label for the kobject_create_and_add() failure did not set the return
> value correctly, and so we can end up in a situation where
> kobject_create_and_add() fails but we report success.
>
> Fixes: 83cbce957446 ("block: add error handling for device_add_disk / add_disk")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
> block/genhd.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index be4775c13760..b0b484116c3a 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -478,8 +478,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
> if (!disk->part0->bd_holder_dir)in here also should be add ret = -ENOMEM; ?
> goto out_del_integrity;
> disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
> - if (!disk->slave_dir)
> + if (!disk->slave_dir) {
> + ret = -ENOMEM;
> goto out_put_holder_dir;
> + }
>
> ret = bd_register_pending_holders(disk);
> if (ret < 0)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling
2021-11-03 16:40 [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling Luis Chamberlain
` (2 preceding siblings ...)
2021-11-04 10:55 ` Wu Bo
@ 2021-11-04 10:57 ` Wu Bo
3 siblings, 0 replies; 5+ messages in thread
From: Wu Bo @ 2021-11-04 10:57 UTC (permalink / raw)
To: Luis Chamberlain, axboe, hare, hch
Cc: linux-block, linux-kernel, kernel test robot, Dan Carpenter
On 2021/11/4 0:40, Luis Chamberlain wrote:
> Commit 83cbce957446 ("block: add error handling for device_add_disk /
> add_disk") added error handling to device_add_disk(), however the goto
> label for the kobject_create_and_add() failure did not set the return
> value correctly, and so we can end up in a situation where
> kobject_create_and_add() fails but we report success.
>
> Fixes: 83cbce957446 ("block: add error handling for device_add_disk / add_disk")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
> block/genhd.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index be4775c13760..b0b484116c3a 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -478,8 +478,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
> if (!disk->part0->bd_holder_dir)
in here also should be add ret = -ENOMEM;
> goto out_del_integrity;
> disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
> - if (!disk->slave_dir)
> + if (!disk->slave_dir) {
> + ret = -ENOMEM;
> goto out_put_holder_dir;
> + }
>
> ret = bd_register_pending_holders(disk);
> if (ret < 0)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-04 10:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 16:40 [PATCH] block: fix device_add_disk() kobject_create_and_add() error handling Luis Chamberlain
2021-11-03 16:41 ` Christoph Hellwig
2021-11-03 19:28 ` Jens Axboe
2021-11-04 10:55 ` Wu Bo
2021-11-04 10:57 ` Wu Bo
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).