linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* scsi: bsg-lib: drop device reference on error path
@ 2019-04-17  3:11 Pan Bian
  2019-04-17  9:18 ` Chaitanya Kulkarni
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2019-04-17  3:11 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, Pan Bian

The function put_device is not called to drop the device reference taken
by get_device on error paths. This patch fixes the bug.

Fixes: cd2f076f1d7("bsg: convert to use blk-mq")
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 block/bsg-lib.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 005e2b7..fe9e0cc 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -281,21 +281,24 @@ static blk_status_t bsg_queue_rq(struct blk_mq_hw_ctx *hctx,
 	struct bsg_set *bset =
 		container_of(q->tag_set, struct bsg_set, tag_set);
 	int ret;
+	blk_status_t status = BLK_STS_IOERR;
 
 	blk_mq_start_request(req);
 
 	if (!get_device(dev))
-		return BLK_STS_IOERR;
+		return status;
 
 	if (!bsg_prepare_job(dev, req))
-		return BLK_STS_IOERR;
+		goto out;
 
 	ret = bset->job_fn(blk_mq_rq_to_pdu(req));
 	if (ret)
-		return BLK_STS_IOERR;
+		goto out;
 
+	status = BLK_STS_OK;
+out:
 	put_device(dev);
-	return BLK_STS_OK;
+	return status;
 }
 
 /* called right after the request is allocated for the request_queue */
-- 
2.7.4



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

* Re: scsi: bsg-lib: drop device reference on error path
  2019-04-17  3:11 scsi: bsg-lib: drop device reference on error path Pan Bian
@ 2019-04-17  9:18 ` Chaitanya Kulkarni
  0 siblings, 0 replies; 2+ messages in thread
From: Chaitanya Kulkarni @ 2019-04-17  9:18 UTC (permalink / raw)
  To: Pan Bian, Jens Axboe; +Cc: linux-block, linux-kernel

Hi Pan,

Thanks for the patch, purely cosmetics comments below.

On 4/16/19 8:27 PM, Pan Bian wrote:
> The function put_device is not called to drop the device reference taken
> by get_device on error paths. This patch fixes the bug.
> 
> Fixes: cd2f076f1d7("bsg: convert to use blk-mq")
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>   block/bsg-lib.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/block/bsg-lib.c b/block/bsg-lib.c
> index 005e2b7..fe9e0cc 100644
> --- a/block/bsg-lib.c
> +++ b/block/bsg-lib.c
> @@ -281,21 +281,24 @@ static blk_status_t bsg_queue_rq(struct blk_mq_hw_ctx *hctx,
>   	struct bsg_set *bset =
>   		container_of(q->tag_set, struct bsg_set, tag_set);
>   	int ret;
> +	blk_status_t status = BLK_STS_IOERR;
>   
Not sure if we need status variable as the code written here pretty 
straight forward.
>   	blk_mq_start_request(req);
>   
>   	if (!get_device(dev))
> -		return BLK_STS_IOERR;
> +		return status;
>   
Also if we are still considering having status variable then we should 
add "err:" label at the end of function just before return and use that 
for an error instead of having multiple returns.
>   	if (!bsg_prepare_job(dev, req))
> -		return BLK_STS_IOERR;
> +		goto out;
>   
>   	ret = bset->job_fn(blk_mq_rq_to_pdu(req));
>   	if (ret)
> -		return BLK_STS_IOERR;
> +		goto out;
>   
> +	status = BLK_STS_OK;
> +out:
>   	put_device(dev);
> -	return BLK_STS_OK;
> +	return status;
>   }
>   
>   /* called right after the request is allocated for the request_queue */
> 


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

end of thread, other threads:[~2019-04-17  9:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17  3:11 scsi: bsg-lib: drop device reference on error path Pan Bian
2019-04-17  9:18 ` Chaitanya Kulkarni

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