block: return NULL in blk_alloc_queue() on error
diff mbox series

Message ID 20200328182734.5585-1-chaitanya.kulkarni@wdc.com
State New
Headers show
Series
  • block: return NULL in blk_alloc_queue() on error
Related show

Commit Message

Chaitanya Kulkarni March 28, 2020, 6:27 p.m. UTC
This patch fixes follwoing warning:

block/blk-core.c: In function ‘blk_alloc_queue’:
block/blk-core.c:558:10: warning: returning ‘int’ from a function with return type ‘struct request_queue *’ makes pointer from integer without a cast [-Wint-conversion]
   return -EINVAL;

Fixes: 3d745ea5b095a ("block: simplify queue allocation")
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guoqing Jiang March 28, 2020, 9:32 p.m. UTC | #1
On 3/28/20 7:27 PM, Chaitanya Kulkarni wrote:
> This patch fixes follwoing warning:
> 
> block/blk-core.c: In function ‘blk_alloc_queue’:
> block/blk-core.c:558:10: warning: returning ‘int’ from a function with return type ‘struct request_queue *’ makes pointer from integer without a cast [-Wint-conversion]
>     return -EINVAL;
> 
> Fixes: 3d745ea5b095a ("block: simplify queue allocation")
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>   block/blk-core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 18b8c09d093e..7e4a1da0715e 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -555,7 +555,7 @@ struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
>   	struct request_queue *q;
>   
>   	if (WARN_ON_ONCE(!make_request))
> -		return -EINVAL;
> +		return NULL;

Maybe return ERR_PTR(-EINVAL) is better.

Thanks,
Guoqing
Chaitanya Kulkarni March 28, 2020, 11:42 p.m. UTC | #2
On 03/28/2020 02:32 PM, Guoqing Jiang wrote:
>> >diff --git a/block/blk-core.c b/block/blk-core.c
>> >index 18b8c09d093e..7e4a1da0715e 100644
>> >--- a/block/blk-core.c
>> >+++ b/block/blk-core.c
>> >@@ -555,7 +555,7 @@ struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
>> >   	struct request_queue *q;
>> >
>> >   	if (WARN_ON_ONCE(!make_request))
>> >-		return -EINVAL;
>> >+		return NULL;
> Maybe return ERR_PTR(-EINVAL) is better.
>

Initially I used that, what if existing callers are reallying on
NULL vs !NULL return value ? Use of NULL just makes the code
consistent with existing return value.

If Jens is okay with ERR_PTR(), I'll send V2.

> Thanks,
> Guoqing
>
Christoph Hellwig March 29, 2020, 12:09 p.m. UTC | #3
On Sat, Mar 28, 2020 at 11:27:34AM -0700, Chaitanya Kulkarni wrote:
> This patch fixes follwoing warning:
> 
> block/blk-core.c: In function ‘blk_alloc_queue’:
> block/blk-core.c:558:10: warning: returning ‘int’ from a function with return type ‘struct request_queue *’ makes pointer from integer without a cast [-Wint-conversion]
>    return -EINVAL;
> 
> Fixes: 3d745ea5b095a ("block: simplify queue allocation")
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

Oops.  Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Christoph Hellwig March 29, 2020, 12:10 p.m. UTC | #4
On Sat, Mar 28, 2020 at 11:42:17PM +0000, Chaitanya Kulkarni wrote:
> >> >@@ -555,7 +555,7 @@ struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
> >> >   	struct request_queue *q;
> >> >
> >> >   	if (WARN_ON_ONCE(!make_request))
> >> >-		return -EINVAL;
> >> >+		return NULL;
> > Maybe return ERR_PTR(-EINVAL) is better.
> >
> 
> Initially I used that, what if existing callers are reallying on
> NULL vs !NULL return value ? Use of NULL just makes the code
> consistent with existing return value.
> 
> If Jens is okay with ERR_PTR(), I'll send V2.

The callers can't handle an ERR_PTR, so v1 is correct.
Jens Axboe March 29, 2020, 4:08 p.m. UTC | #5
On 3/28/20 12:27 PM, Chaitanya Kulkarni wrote:
> This patch fixes follwoing warning:
> 
> block/blk-core.c: In function ‘blk_alloc_queue’:
> block/blk-core.c:558:10: warning: returning ‘int’ from a function with return type ‘struct request_queue *’ makes pointer from integer without a cast [-Wint-conversion]
>    return -EINVAL;

Applied, thanks.

Patch
diff mbox series

diff --git a/block/blk-core.c b/block/blk-core.c
index 18b8c09d093e..7e4a1da0715e 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -555,7 +555,7 @@  struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
 	struct request_queue *q;
 
 	if (WARN_ON_ONCE(!make_request))
-		return -EINVAL;
+		return NULL;
 
 	q = __blk_alloc_queue(node_id);
 	if (!q)