# \[PATCH\] block: Fix an error handling in add\_partition

- Subsystems: BLOCK LAYER, THE REST
- Maintainers: Jens Axboe, Linus Torvalds
- List: linux-block
- 3 messages, 3 authors
- Page: https://ratatoskr.run/linux-block/2021/01/6237571/t

## \[PATCH\] block: Fix an error handling in add\_partition

- From: Dinghao Liu \<hidden\>
- Date: 2021-01-17 09:01:53 
- Message: https://ratatoskr.run/linux-block/2021/01/6237571.md

```text
Once we have called device_initialize(), we should use put_device() to
give up the reference on error, just like what we have done on failure
of device_add().

Signed-off-by: Dinghao Liu <redacted>
---

Changelog:

v2: - Refine commit message.
---
 block/partitions/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index e7d776db803b..23460cee9de5 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -384,7 +384,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
 
 	err = blk_alloc_devt(bdev, &devt);
 	if (err)
-		goto out_bdput;
+		goto out_put;
 	pdev->devt = devt;
 
 	/* delay uevent until 'holders' subdir is created */
-- 
2.17.1

```

## Re: \[PATCH\] block: Fix an error handling in add\_partition

- From: Christoph Hellwig \<hch@infradead.org\>
- Date: 2021-01-20 10:30:33 
- Message: https://ratatoskr.run/linux-block/2021/01/6241038.md

```text
On Sun, Jan 17, 2021 at 04:50:17PM +0800, Dinghao Liu wrote:
> Once we have called device_initialize(), we should use put_device() to
> give up the reference on error, just like what we have done on failure
> of device_add().
> 
> Signed-off-by: Dinghao Liu <redacted>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
```

## Re: \[PATCH\] block: Fix an error handling in add\_partition

- From: Jens Axboe \<axboe@kernel.dk\>
- Date: 2021-01-25 04:37:17 
- Message: https://ratatoskr.run/linux-block/2021/01/6245947.md

```text
On 1/17/21 1:50 AM, Dinghao Liu wrote:
> Once we have called device_initialize(), we should use put_device() to
> give up the reference on error, just like what we have done on failure
> of device_add().

Applied for 5.11, thanks.

-- 
Jens Axboe

```
