Skip to contentSkip to conversation

docs: driver-api: usb: Document USBDEVFS_BULK return value and short reads

PATCH In review Malaya Kumar Rout 2 participants 2 messages Mar 5 – Mar 11 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs: driver-api: usb: Document USBDEVFS_BULK return value and short reads

Remove a longstanding FIXME comment in the USBDEVFS_BULK documentation by properly documenting the return value behavior. The ioctl returns the actual number of bytes transferred on success, which naturally handles short reads (where fewer bytes are read than requested) by returning a value less than the requested length.

This information was verified by examining the implementation in drivers/usb/core/devio.c:do_proc_bulk(), which returns the actual transfer length on success.

---
 Documentation/driver-api/usb/usb.rst | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/driver-api/usb/usb.rst +6 -0
index 7f2f41e80c1c..a01d72af479b 100644
@@ -539,6 +539,12 @@ USBDEVFS_BULK
     kernels support requests up to about 128KBytes. *FIXME say how read
     length is returned, and how short reads are handled.*.
 
+    kernels support requests up to about 128KBytes. On success, the
+    ioctl returns the number of bytes actually transferred. Short reads
+    are supported; if fewer bytes are received than requested, only the
+    actual number of bytes received are copied to the buffer and that
+    count is returned. On error, a negative error code is returned.
+
 USBDEVFS_CLEAR_HALT
     Clears endpoint halt (stall) and resets the endpoint toggle. This is
     only meaningful for bulk or interrupt endpoints. The ioctl parameter
Signature · 1 line
2.53.0
#1 lore raw
Quoted 9 lines · Malaya Kumar Rout

Remove a longstanding FIXME comment in the USBDEVFS_BULK documentation by properly documenting the return value behavior. The ioctl returns the actual number of bytes transferred on success, which naturally handles short reads (where fewer bytes are read than requested) by returning a value less than the requested length.

This information was verified by examining the implementation in drivers/usb/core/devio.c:do_proc_bulk(), which returns the actual transfer length on success.

Good effort, Malaya! As far as I can tell, you've done a good job formatting this patch and sending it out to the right people. You've done a lot right with this patch. However, these changes aren't quite suitable for inclusion upstream.

Documentation/driver-api/usb/usb.rst USBDEVFS_BULK · line 540

Quoted 11 lines
---
 Documentation/driver-api/usb/usb.rst | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/driver-api/usb/usb.rst +0 -0
index 7f2f41e80c1c..a01d72af479b 100644
@@ -539,6 +539,12 @@ USBDEVFS_BULK
     kernels support requests up to about 128KBytes. *FIXME say how read
     length is returned, and how short reads are handled.*.

You prepared this patch with intent to address this FIXME, but you didn't remove the FIXME.

Documentation/driver-api/usb/usb.rst USBDEVFS_BULK · line 542

Quoted 2 lines
Documentation/driver-api/usb/usb.rst +1 -0
+    kernels support requests up to about 128KBytes. On success, the

This line directly duplicates information already in the previous paragraph.

Documentation/driver-api/usb/usb.rst USBDEVFS_BULK · line 546

Quoted 4 lines
Documentation/driver-api/usb/usb.rst +4 -0
+    ioctl returns the number of bytes actually transferred. Short reads
+    are supported; if fewer bytes are received than requested, only the
+    actual number of bytes received are copied to the buffer and that
+    count is returned. On error, a negative error code is returned.

The FIXME says that documentation should "say how read length is returned". Is it returned by overwriting the len member of the struct that is passed in? Or is it returned via the integer return value of the ioctl call itself? Your patch doesn't communicate _how_ read length is returned.

Documentation/driver-api/usb/usb.rst USBDEVFS_BULK · line 550

Quoted 4 lines
Documentation/driver-api/usb/usb.rst +1 -0
+
 USBDEVFS_CLEAR_HALT
     Clears endpoint halt (stall) and resets the endpoint toggle. This is
     only meaningful for bulk or interrupt endpoints. The ioctl parameter

These small documentation fixes are a great way to get started with kernel development, but they're also difficult to get right. This is just a suggestion, but you may find more success checking out docs-next and looking for documentation compilation warnings that need to be addressed. Fix whatever issue is causing the warning and it will go away. Those types of changes are easier for maintainers to verify for correctness.

- Brigham

Signature · 1 line
Brigham Campbell <[email protected]>