Skip to contentSkip to conversation

scsi: bsg: fix errno when scsi_bsg_register_queue fails

PATCH In review Jackie Liu 3 participants 7 messages Oct 22, 2021 – Dec 23, 2021 SCSI

lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH v2 1/1 scsi: bsg: fix errno when scsi_bsg_register_queue fails

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
v1->v2:
resend to linux-scsi mail list.

 drivers/scsi/scsi_sysfs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 			 * We're treating error on bsg register as non-fatal, so
 			 * pretend nothing went wrong.
 			 */
+			error = PTR_ERR(sdev->bsg_dev);
 			sdev_printk(KERN_INFO, sdev,
 				    "Failed to register bsg queue, errno=%d\n",
 				    error);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Jackie Liu

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

The comment above the changed code says:

"
We're treating error on bsg register as non-fatal, so pretend nothing went wrong. "

With this patch in place, "error" is returned to the caller, and the code no longer pretends that nothing is wrong. Also, the message is a dev_info message, not dev_err, suggesting that ignoring the error was indeed on purpose. Assuming the comment is correct, this patch is plain wrong; the message should have printed PTR_ERR(sdev->bsg_dev) instead and not set the 'error' variable.

Guenter

Quoted 27 lines
Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
v1->v2:
resend to linux-scsi mail list.

 drivers/scsi/scsi_sysfs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 			 * We're treating error on bsg register as non-fatal, so
 			 * pretend nothing went wrong.
 			 */
+			error = PTR_ERR(sdev->bsg_dev);
 			sdev_printk(KERN_INFO, sdev,
 				    "Failed to register bsg queue, errno=%d\n",
 				    error);
Signature · 1 line
2.25.1
author
#2 lore raw

Hi Guenter.

Before commit ead09dd3aed5c ("scsi: bsg: Simplify device registration", the errno need return to the caller, I restore the old logic, and print this errno.

--
Jackie Liu

Quoted 49 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

The comment above the changed code says:

"
We're treating error on bsg register as non-fatal, so pretend nothing went wrong. "

With this patch in place, "error" is returned to the caller, and the code no longer pretends that nothing is wrong. Also, the message is a dev_info message, not dev_err, suggesting that ignoring the error was indeed on purpose. Assuming the comment is correct, this patch is plain wrong; the message should have printed PTR_ERR(sdev->bsg_dev) instead and not set the 'error' variable.

Guenter

Quoted 27 lines
Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
v1->v2:
resend to linux-scsi mail list.

  drivers/scsi/scsi_sysfs.c | 1 +
  1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
  			 * We're treating error on bsg register as non-fatal, so
  			 * pretend nothing went wrong.
  			 */
+			error = PTR_ERR(sdev->bsg_dev);
  			sdev_printk(KERN_INFO, sdev,
  				    "Failed to register bsg queue, errno=%d\n",
  				    error);
Signature · 1 line
2.25.1
#3 lore raw
Quoted 5 lines · Jackie Liu

Hi Guenter.

Before commit ead09dd3aed5c ("scsi: bsg: Simplify device registration", the errno need return to the caller, I restore the old logic, and print this errno.

The comment associated with the code says "We're treating error on bsg register as non-fatal, so pretend nothing went wrong." Your commit does not explain why that is wrong, and why the error should be returned to the caller. In the current code, the comment is still there, but the error is not ignored, and it is printed as informational message, not as error message. At the very least that is misleading, and the code no longer matches the comment. Also, the description in your commit does not match the change made: It sounds like a change with no functional impact ("Here, we should be print the correct error code when scsi_bsg_register_queue fails") when in reality it does introduce a functional change (the error is not only printed but also returned to the caller).

Guenter

Quoted 53 lines
Signature · 1 line
Jackie Liu
Quoted 49 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

The comment above the changed code says:

"
We're treating error on bsg register as non-fatal, so pretend nothing went wrong. "

With this patch in place, "error" is returned to the caller, and the code no longer pretends that nothing is wrong. Also, the message is a dev_info message, not dev_err, suggesting that ignoring the error was indeed on purpose. Assuming the comment is correct, this patch is plain wrong; the message should have printed PTR_ERR(sdev->bsg_dev) instead and not set the 'error' variable.

Guenter

Quoted 27 lines
Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
  v1->v2:
  resend to linux-scsi mail list.

  drivers/scsi/scsi_sysfs.c | 1 +

  1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
                * We're treating error on bsg register as non-fatal, so
                * pretend nothing went wrong.
                */
+            error = PTR_ERR(sdev->bsg_dev);
               sdev_printk(KERN_INFO, sdev,
                       "Failed to register bsg queue, errno=%d\n",
                       error);
Signature · 1 line
2.25.1
author
#4 lore raw
Quoted 20 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

Hi Guenter.

Before commit ead09dd3aed5c ("scsi: bsg: Simplify device registration", the errno need return to the caller, I restore the old logic, and print this errno.

The comment associated with the code says "We're treating error on bsg register as non-fatal, so pretend nothing went wrong." Your commit does not explain why that is wrong, and why the error should be returned to the caller. In the current code, the comment is still there, but the error is not ignored, and it is printed as informational message, not as error message. At the very least that is misleading, and the code no longer matches the comment. Also, the description in your commit does not match the change made: It sounds like a change with no functional impact ("Here, we should be print the correct error code when scsi_bsg_register_queue fails") when in reality it does introduce a functional change (the error is not only printed but also returned to the caller).

Quoted 1 line

Guenter

I see, Thanks for point out, after commit ee37e09d81a4 ("[SCSI] fix duplicate removal on error path in scsi_sysfs_add_sdev"), Before this errno will be forced to return 0.

After:

[1] error = device_create_file(&sdev->sdev_gendev,

                           sdev->host->hostt->sdev_attrs[i]);

Then:

with 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier") delete code [1], so we force return errno.

I don’t know if I should restore the original logic or delete this comment information. Guenter and Christoph, What do you think? I can send another patch based on this.

--
Jackie Liu

Quoted 55 lines
Quoted 54 lines
Signature · 2 lines
-- 
Jackie Liu
Quoted 49 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

The comment above the changed code says:

"
We're treating error on bsg register as non-fatal, so pretend nothing went wrong. "

With this patch in place, "error" is returned to the caller, and the code no longer pretends that nothing is wrong. Also, the message is a dev_info message, not dev_err, suggesting that ignoring the error was indeed on purpose. Assuming the comment is correct, this patch is plain wrong; the message should have printed PTR_ERR(sdev->bsg_dev) instead and not set the 'error' variable.

Guenter

Quoted 27 lines
Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
  v1->v2:
  resend to linux-scsi mail list.

  drivers/scsi/scsi_sysfs.c | 1 +

  1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
                * We're treating error on bsg register as non-fatal, so
                * pretend nothing went wrong.
                */
+            error = PTR_ERR(sdev->bsg_dev);
               sdev_printk(KERN_INFO, sdev,
                       "Failed to register bsg queue, errno=%d\n",
                       error);
Signature · 1 line
2.25.1
author Reviewed-by
#5 lore raw
Quoted 34 lines · Jackie Liu
Quoted 20 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

Hi Guenter.

Before commit ead09dd3aed5c ("scsi: bsg: Simplify device registration", the errno need return to the caller, I restore the old logic, and print this errno.

The comment associated with the code says "We're treating error on bsg register as non-fatal, so pretend nothing went wrong." Your commit does not explain why that is wrong, and why the error should be returned to the caller. In the current code, the comment is still there, but the error is not ignored, and it is printed as informational message, not as error message. At the very least that is misleading, and the code no longer matches the comment. Also, the description in your commit does not match the change made: It sounds like a change with no functional impact ("Here, we should be print the correct error code when scsi_bsg_register_queue fails") when in reality it does introduce a functional change (the error is not only printed but also returned to the caller).

Quoted 1 line

Guenter

I see, Thanks for point out, after commit ee37e09d81a4 ("[SCSI] fix duplicate removal on error path in scsi_sysfs_add_sdev"), Before this errno will be forced to return 0.

After:

[1] error = device_create_file(&sdev->sdev_gendev, sdev->host->hostt->sdev_attrs[i]);

Quoted 8 lines

Then:

with 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier") delete code [1], so we force return errno.

I don’t know if I should restore the original logic or delete this comment information. Guenter and Christoph, What do you think? I can send another patch based on this.

Hi, Guenter

I saw that you have already posted a fix patch, I suggest that the
analysis I mentioned can be added to the description. I think the Fixes tag should be 92c4b58b15c5 instead of my patch.

In any case, if you are interested in re-sending a patch, you can add my review tag.

My broken mailbox couldn’t receive the mail from the mailing list, so I sent it from here.

--
Jackie Liu

Quoted 60 lines
Signature · 2 lines
-- 
Jackie Liu
Quoted 56 lines
Quoted 55 lines
Signature · 2 lines
-- 
Jackie Liu
Quoted 50 lines · Guenter Roeck
Quoted 5 lines · Jackie Liu

From: Jackie Liu <[email protected]>

When the value of error is printed, it will always be 0. Here, we should be print the correct error code when scsi_bsg_register_queue fails.

The comment above the changed code says:

"
We're treating error on bsg register as non-fatal, so pretend nothing went wrong. "

With this patch in place, "error" is returned to the caller, and the code no longer pretends that nothing is wrong. Also, the message is a dev_info message, not dev_err, suggesting that ignoring the error was indeed on purpose. Assuming the comment is correct, this patch is plain wrong; the message should have printed PTR_ERR(sdev->bsg_dev) instead and not set the 'error' variable.

Guenter

Quoted 28 lines
Fixes ead09dd3aed5 ("scsi: bsg: Simplify device registration")
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
  v1->v2:
  resend to linux-scsi mail list.

  drivers/scsi/scsi_sysfs.c | 1 +

  1 file changed, 1 insertion(+)
drivers/scsi/scsi_sysfs.c +1 -0
index 86793259e541..d8789f6cda62 100644
@@ -1379,6 +1379,7 @@ int scsi_sysfs_add_sdev(struct scsi_device 
 *sdev)
                * We're treating error on bsg register as non-fatal, so
                * pretend nothing went wrong.
                */
+            error = PTR_ERR(sdev->bsg_dev);
               sdev_printk(KERN_INFO, sdev,
                       "Failed to register bsg queue, errno=%d\n",

                      error);

Signature · 1 line
2.25.1
#6 lore raw
In reply to Jackie Liu
Quoted 9 lines · Jackie Liu

I see, Thanks for point out, after commit ee37e09d81a4 ("[SCSI] fix duplicate removal on error path in scsi_sysfs_add_sdev"), Before this errno will be forced to return 0.

After:

[1] error = device_create_file(&sdev->sdev_gendev,

                           sdev->host->hostt->sdev_attrs[i]);
Quoted 8 lines

Then:

with 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier") delete code [1], so we force return errno.

I don’t know if I should restore the original logic or delete this comment information. Guenter and Christoph, What do you think? I can send another patch based on this.

I think we should just handle the error properly and remove the comment. There's no good reason to ignore bsg registration errors.