linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL
@ 2017-01-09 20:20 Jeff Moyer
  2017-01-09 20:27 ` Omar Sandoval
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Moyer @ 2017-01-09 20:20 UTC (permalink / raw)
  To: axboe, Markus Pargmann
  Cc: linux-block, nbd-general, linux-kernel, Omar Sandoval

Additionally, don't assign directly to disk->queue, otherwise
blk_put_queue (called via put_disk) will choke (panic) on the errno
stored there.

Bug found by code inspection after Omar found a similar issue in
virtio_blk.  Compile-tested only.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 38c576f..50a2020 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1042,6 +1042,7 @@ static int __init nbd_init(void)
 		return -ENOMEM;
 
 	for (i = 0; i < nbds_max; i++) {
+		struct request_queue *q;
 		struct gendisk *disk = alloc_disk(1 << part_shift);
 		if (!disk)
 			goto out;
@@ -1067,12 +1068,13 @@ static int __init nbd_init(void)
 		 * every gendisk to have its very own request_queue struct.
 		 * These structs are big so we dynamically allocate them.
 		 */
-		disk->queue = blk_mq_init_queue(&nbd_dev[i].tag_set);
-		if (!disk->queue) {
+		q = blk_mq_init_queue(&nbd_dev[i].tag_set);
+		if (IS_ERR(q)) {
 			blk_mq_free_tag_set(&nbd_dev[i].tag_set);
 			put_disk(disk);
 			goto out;
 		}
+		disk->queue = q;
 
 		/*
 		 * Tell the block layer that we are not a rotational device

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

* Re: [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL
  2017-01-09 20:20 [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL Jeff Moyer
@ 2017-01-09 20:27 ` Omar Sandoval
  2017-01-09 20:41   ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Omar Sandoval @ 2017-01-09 20:27 UTC (permalink / raw)
  To: Jeff Moyer
  Cc: axboe, Markus Pargmann, linux-block, nbd-general, linux-kernel,
	Josef Bacik

On Mon, Jan 09, 2017 at 03:20:31PM -0500, Jeff Moyer wrote:
> Additionally, don't assign directly to disk->queue, otherwise
> blk_put_queue (called via put_disk) will choke (panic) on the errno
> stored there.
> 
> Bug found by code inspection after Omar found a similar issue in
> virtio_blk.  Compile-tested only.
> 
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

Reviewed-by: Omar Sandoval <osandov@fb.com>

Compile-reviewed only :) Josef can probably test it if he cares enough,
but it looks right.

> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 38c576f..50a2020 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -1042,6 +1042,7 @@ static int __init nbd_init(void)
>  		return -ENOMEM;
>  
>  	for (i = 0; i < nbds_max; i++) {
> +		struct request_queue *q;
>  		struct gendisk *disk = alloc_disk(1 << part_shift);
>  		if (!disk)
>  			goto out;
> @@ -1067,12 +1068,13 @@ static int __init nbd_init(void)
>  		 * every gendisk to have its very own request_queue struct.
>  		 * These structs are big so we dynamically allocate them.
>  		 */
> -		disk->queue = blk_mq_init_queue(&nbd_dev[i].tag_set);
> -		if (!disk->queue) {
> +		q = blk_mq_init_queue(&nbd_dev[i].tag_set);
> +		if (IS_ERR(q)) {
>  			blk_mq_free_tag_set(&nbd_dev[i].tag_set);
>  			put_disk(disk);
>  			goto out;
>  		}
> +		disk->queue = q;
>  
>  		/*
>  		 * Tell the block layer that we are not a rotational device

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

* Re: [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL
  2017-01-09 20:27 ` Omar Sandoval
@ 2017-01-09 20:41   ` Jens Axboe
  2017-01-09 20:44     ` Josef Bacik
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2017-01-09 20:41 UTC (permalink / raw)
  To: Omar Sandoval, Jeff Moyer
  Cc: Markus Pargmann, linux-block, nbd-general, linux-kernel, Josef Bacik

On 01/09/2017 01:27 PM, Omar Sandoval wrote:
> On Mon, Jan 09, 2017 at 03:20:31PM -0500, Jeff Moyer wrote:
>> Additionally, don't assign directly to disk->queue, otherwise
>> blk_put_queue (called via put_disk) will choke (panic) on the errno
>> stored there.
>>
>> Bug found by code inspection after Omar found a similar issue in
>> virtio_blk.  Compile-tested only.
>>
>> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
> 
> Reviewed-by: Omar Sandoval <osandov@fb.com>
> 
> Compile-reviewed only :) Josef can probably test it if he cares enough,
> but it looks right.

Looks good to me, too. Josef, you want me to queue this up directly?

-- 
Jens Axboe

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

* Re: [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL
  2017-01-09 20:41   ` Jens Axboe
@ 2017-01-09 20:44     ` Josef Bacik
  0 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2017-01-09 20:44 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Omar Sandoval, Jeff Moyer, Markus Pargmann, linux-block,
	nbd-general, linux-kernel

On Mon, Jan 9, 2017 at 3:41 PM, Jens Axboe <axboe@kernel.dk> wrote:
> On 01/09/2017 01:27 PM, Omar Sandoval wrote:
>>  On Mon, Jan 09, 2017 at 03:20:31PM -0500, Jeff Moyer wrote:
>>>  Additionally, don't assign directly to disk->queue, otherwise
>>>  blk_put_queue (called via put_disk) will choke (panic) on the errno
>>>  stored there.
>>> 
>>>  Bug found by code inspection after Omar found a similar issue in
>>>  virtio_blk.  Compile-tested only.
>>> 
>>>  Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
>> 
>>  Reviewed-by: Omar Sandoval <osandov@fb.com>
>> 
>>  Compile-reviewed only :) Josef can probably test it if he cares 
>> enough,
>>  but it looks right.
> 
> Looks good to me, too. Josef, you want me to queue this up directly?

Y'all are hilarious.

Reviewed-by: Josef Bacik <jbacik@fb.com>

Thanks,

Josef

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

end of thread, other threads:[~2017-01-09 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-09 20:20 [patch] nbd: blk_mq_init_queue returns an error code on failure, not NULL Jeff Moyer
2017-01-09 20:27 ` Omar Sandoval
2017-01-09 20:41   ` Jens Axboe
2017-01-09 20:44     ` Josef Bacik

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).