Skip to contentSkip to conversation

usb: uas: do not leak error codes from usb_alloc_streams()

PATCH In review Oliver Neukum 4 participants 4 messages Oct 8 – Oct 14

Subsystems (3)
lore
Share & tools
lore

Oliver Neukum

author maintainer
#0 lore raw

PATCH 1/1 usb: uas: do not leak error codes from usb_alloc_streams()

While a UAS device is undergoing a reset not triggered by the SCSI layer there is a short window in the error case of reallocating streams during which internal error codes of the USB layer are exported as nonsensical queue depths.

The error has been noticed by Sashiko in a different context, but it is a general issue.

Fixes 4de7a3735bdc4 ("uas: Fix reset handling for externally triggered reset")
---
 drivers/usb/storage/uas.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/usb/storage/uas.c +5 -3
index 265162981269..3f69e9de9b61 100644
@@ -983,10 +983,12 @@ static int uas_configure_endpoints(struct uas_dev_info *devinfo)
 		devinfo->qdepth = 32;
 		devinfo->use_streams = 0;
 	} else {
-		devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1,
+		r = usb_alloc_streams(devinfo->intf, eps + 1,
 						    3, MAX_CMNDS, GFP_NOIO);
-		if (devinfo->qdepth < 0)
-			return devinfo->qdepth;
+		if (r < 0)
+			return r;
+
+		devinfo->qdepth = r;
 		devinfo->use_streams = 1;
 	}
 
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

While a UAS device is undergoing a reset not triggered by the SCSI layer there is a short window in the error case of reallocating streams during which internal error codes of the USB layer are exported as nonsensical queue depths.

The error has been noticed by Sashiko in a different context, but it is a general issue.

Fixes 4de7a3735bdc4 ("uas: Fix reset handling for externally triggered reset")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Oliver Neukum
Quoted 19 lines · Oliver Neukum

While a UAS device is undergoing a reset not triggered by the SCSI layer there is a short window in the error case of reallocating streams during which internal error codes of the USB layer are exported as nonsensical queue depths.

The error has been noticed by Sashiko in a different context, but it is a general issue.

Fixes 4de7a3735bdc4 ("uas: Fix reset handling for externally triggered reset")
---
 drivers/usb/storage/uas.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/usb/storage/uas.c +0 -0
index 265162981269..3f69e9de9b61 100644

drivers/usb/storage/uas.c static int uas_configure_endpoints(struct uas_dev_info *devinfo) · line 987

Quoted 6 lines
drivers/usb/storage/uas.c +1 -1
@@ -983,10 +983,12 @@ static int uas_configure_endpoints(struct uas_dev_info *devinfo)
 		devinfo->qdepth = 32;
 		devinfo->use_streams = 0;
 	} else {
-		devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1,
+		r = usb_alloc_streams(devinfo->intf, eps + 1,
 						    3, MAX_CMNDS, GFP_NOIO);

This line now needs to be realigned...

[...]

MBR, Sergey

Reviewed-by on v1 1/1
#3 lore raw
In reply to Oliver Neukum

drivers/usb/storage/uas.c static int uas_configure_endpoints(struct uas_dev_info *devinfo) · line 987

Quoted 3 lines · Oliver Neukum
drivers/usb/storage/uas.c +1 -1
-		devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1,
+		r = usb_alloc_streams(devinfo->intf, eps + 1,
 						    3, MAX_CMNDS, GFP_NOIO);

Looks correct to me. Keeping the negative errno out of qdepth by assigning only on success is the right fix.