2023-07-05 03:06:23

by Yu Kuai

[permalink] [raw]
Subject: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

From: Yu Kuai <[email protected]>

Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
make a mess how blk_get_queue() is called, blk_get_queue() returns true
on success while the caller expects it returns 0 on success.

Fix this problem and also add a corresponding error message on failure.

Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
Reported-by: Marc Hartmayer <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Yu Kuai <[email protected]>
---
drivers/scsi/sg.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 89fa046c7158..0d8afffd1683 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1497,9 +1497,10 @@ sg_add_device(struct device *cl_dev)
int error;
unsigned long iflags;

- error = blk_get_queue(scsidp->request_queue);
- if (error)
- return error;
+ if (!blk_get_queue(scsidp->request_queue)) {
+ pr_warn("%s: get scsi_device queue failed\n", __func__);
+ return -ENODEV;
+ }

error = -ENOMEM;
cdev = cdev_alloc();
--
2.39.2



2023-07-05 06:27:28

by Marc Hartmayer

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

On Wed, Jul 05, 2023 at 10:40 AM +0800, Yu Kuai <[email protected]> wrote:
> From: Yu Kuai <[email protected]>
>
> Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> make a mess how blk_get_queue() is called, blk_get_queue() returns true
> on success while the caller expects it returns 0 on success.
>
> Fix this problem and also add a corresponding error message on failure.
>
> Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> Reported-by: Marc Hartmayer <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Yu Kuai <[email protected]>
> ---
> drivers/scsi/sg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 89fa046c7158..0d8afffd1683 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1497,9 +1497,10 @@ sg_add_device(struct device *cl_dev)
> int error;
> unsigned long iflags;
>
> - error = blk_get_queue(scsidp->request_queue);
> - if (error)
> - return error;
> + if (!blk_get_queue(scsidp->request_queue)) {
> + pr_warn("%s: get scsi_device queue failed\n", __func__);
> + return -ENODEV;
> + }
>
> error = -ENOMEM;
> cdev = cdev_alloc();
> --
> 2.39.2

Thanks.

Tested-by: Marc Hartmayer <[email protected]>

2023-07-06 13:08:55

by Christoph Hellwig

[permalink] [raw]

2023-07-07 07:38:20

by Marc Hartmayer

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

On Wed, Jul 05, 2023 at 10:40 AM +0800, Yu Kuai <[email protected]> wrote:
> From: Yu Kuai <[email protected]>
>
> Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> make a mess how blk_get_queue() is called, blk_get_queue() returns true
> on success while the caller expects it returns 0 on success.
>
> Fix this problem and also add a corresponding error message on failure.
>
> Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> Reported-by: Marc Hartmayer <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Yu Kuai <[email protected]>
> ---
> drivers/scsi/sg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 89fa046c7158..0d8afffd1683 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1497,9 +1497,10 @@ sg_add_device(struct device *cl_dev)
> int error;
> unsigned long iflags;
>
> - error = blk_get_queue(scsidp->request_queue);
> - if (error)
> - return error;
> + if (!blk_get_queue(scsidp->request_queue)) {
> + pr_warn("%s: get scsi_device queue failed\n", __func__);
> + return -ENODEV;
> + }
>
> error = -ENOMEM;
> cdev = cdev_alloc();
> --
> 2.39.2

Reviewed-by: Marc Hartmayer <[email protected]>

2023-07-13 12:58:55

by Shinichiro Kawasaki

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

On Jul 05, 2023 / 10:40, Yu Kuai wrote:
> From: Yu Kuai <[email protected]>
>
> Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> make a mess how blk_get_queue() is called, blk_get_queue() returns true
> on success while the caller expects it returns 0 on success.
>
> Fix this problem and also add a corresponding error message on failure.
>
> Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> Reported-by: Marc Hartmayer <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Yu Kuai <[email protected]>

I observed that /dev/sg* files are not created with kernel v6.5-rc1, and it
causes blktests scsi/002 failure. I confirmed this patch fixes it. Thanks.

Tested-by: Shin'ichiro Kawasaki <[email protected]>

2023-07-19 01:39:06

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

Hi, Jens

?? 2023/07/05 10:40, Yu Kuai ะด??:
> From: Yu Kuai <[email protected]>
>
> Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> make a mess how blk_get_queue() is called, blk_get_queue() returns true
> on success while the caller expects it returns 0 on success.
>
> Fix this problem and also add a corresponding error message on failure.
>
> Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
> Reported-by: Marc Hartmayer <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Yu Kuai <[email protected]>

Sorry about the trouble... Can you apply this patch? I notice that the
original patch is applied to stable.

Thanks,
Kuai

> ---
> drivers/scsi/sg.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 89fa046c7158..0d8afffd1683 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1497,9 +1497,10 @@ sg_add_device(struct device *cl_dev)
> int error;
> unsigned long iflags;
>
> - error = blk_get_queue(scsidp->request_queue);
> - if (error)
> - return error;
> + if (!blk_get_queue(scsidp->request_queue)) {
> + pr_warn("%s: get scsi_device queue failed\n", __func__);
> + return -ENODEV;
> + }
>
> error = -ENOMEM;
> cdev = cdev_alloc();
>


2023-07-19 16:51:11

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()

On 7/18/23 7:09?PM, Yu Kuai wrote:
> Hi, Jens
>
> ? 2023/07/05 10:40, Yu Kuai ??:
>> From: Yu Kuai <[email protected]>
>>
>> Commit fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
>> make a mess how blk_get_queue() is called, blk_get_queue() returns true
>> on success while the caller expects it returns 0 on success.
>>
>> Fix this problem and also add a corresponding error message on failure.
>>
>> Fixes: fcaa174a9c99 ("scsi/sg: don't grab scsi host module reference")
>> Reported-by: Marc Hartmayer <[email protected]>
>> Closes: https://lore.kernel.org/all/[email protected]/
>> Signed-off-by: Yu Kuai <[email protected]>
>
> Sorry about the trouble... Can you apply this patch? I notice that the
> original patch is applied to stable.

I can, I had assumed that Martin would pick it up on the SCSI side?

--
Jens Axboe


2023-07-20 04:13:14

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH] scsi/sg: fix checking return value of blk_get_queue()


Jens,

>> Sorry about the trouble... Can you apply this patch? I notice that the
>> original patch is applied to stable.
>
> I can, I had assumed that Martin would pick it up on the SCSI side?

Ah, but since the offending commit went through block I didn't have it
in SCSI until I set up the new trees. Now applied to 6.5/scsi-fixes.

--
Martin K. Petersen Oracle Linux Engineering