All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pktcdvd.c: Fix wrong return code when alloc_disk() fails.
@ 2018-08-15  3:22 Jiecheng Wu
  2018-08-15 14:22 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Jiecheng Wu @ 2018-08-15  3:22 UTC (permalink / raw)
  To: linux-block

Function pkt_setup_dev() defined in drivers/block/pktcdvd.c calls alloc_disk(). However, it forgets to set the error return code when alloc_disk() fails. Instead, when alloc_disk() fails, it simply jumps to label 'out_mem' leaving the variable ret unchanged.
---
 drivers/block/pktcdvd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index b3f83cd..f63fa1f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2716,8 +2716,10 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
 	pd->write_congestion_off = write_congestion_off;
 
 	disk = alloc_disk(1);
-	if (!disk)
+	if (!disk) {
+		ret = -ENOMEM;
 		goto out_mem;
+	}
 	pd->disk = disk;
 	disk->major = pktdev_major;
 	disk->first_minor = idx;
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pktcdvd.c: Fix wrong return code when alloc_disk() fails.
  2018-08-15  3:22 [PATCH] pktcdvd.c: Fix wrong return code when alloc_disk() fails Jiecheng Wu
@ 2018-08-15 14:22 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2018-08-15 14:22 UTC (permalink / raw)
  To: Jiecheng Wu, linux-block

On 8/14/18 9:22 PM, Jiecheng Wu wrote:
> Function pkt_setup_dev() defined in drivers/block/pktcdvd.c calls
> alloc_disk(). However, it forgets to set the error return code when
> alloc_disk() fails. Instead, when alloc_disk() fails, it simply jumps
> to label 'out_mem' leaving the variable ret unchanged.

We do init it to -ENOMEM, the problem is that
mempool_init_kmalloc_pool() overwrites it, and any unset jump to error
out after that won't work so well.

So your fix isn't complete, since it won't catch blk_alloc_queue()
failure. The below should do it.


diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index e285413d4a75..6f1d25c1eb64 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2740,6 +2740,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
 	pd->write_congestion_on  = write_congestion_on;
 	pd->write_congestion_off = write_congestion_off;
 
+	ret = -ENOMEM;
 	disk = alloc_disk(1);
 	if (!disk)
 		goto out_mem;

-- 
Jens Axboe

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-15 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15  3:22 [PATCH] pktcdvd.c: Fix wrong return code when alloc_disk() fails Jiecheng Wu
2018-08-15 14:22 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.