Skip to contentSkip to conversation

usb: gadget: f_fs: set req->num_sgs as 0 for sync io mode

PATCH Superseded Peter Chen 2 participants 3 messages Dec 12, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 usb: gadget: f_fs: set req->num_sgs as 0 for sync io mode

The UDC core uses req->num_sgs to judge if scatter buffer list is used.
Eg: usb_gadget_map_request_by_dev. For f_fs sync io mode, the request is re-used for each request, so if the 1st request->length > PAGE_SIZE, and the 2nd request->length is < PAGE_SIZE, the f_fs uses the 1st req->num_sgs for the 2nd request, it causes the UDC core get the wrong req->num_sgs value (The 2nd request doesn't use sg).

We set req->num_sgs as 0 for each request at non-sg transfer case to fix it.

Cc Jun Li <[email protected]>
Cc stable <[email protected]>
Fixes 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather buffers")
---
 drivers/usb/gadget/function/f_fs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/gadget/function/f_fs.c +0 -1
index eedd926cc578..b5a1bfc2fc7e 100644
@@ -1106,7 +1106,6 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
 			req->num_sgs = io_data->sgt.nents;
 		} else {
 			req->buf = data;
-			req->num_sgs = 0;
 		}
 		req->length = data_len;
 
Signature · 1 line
2.17.1
#1 lore raw

Hi,

Quoted 9 lines · Peter Chen

The UDC core uses req->num_sgs to judge if scatter buffer list is used.
Eg: usb_gadget_map_request_by_dev. For f_fs sync io mode, the request is re-used for each request, so if the 1st request->length > PAGE_SIZE, and the 2nd request->length is < PAGE_SIZE, the f_fs uses the 1st req->num_sgs for the 2nd request, it causes the UDC core get the wrong req->num_sgs value (The 2nd request doesn't use sg).

We set req->num_sgs as 0 for each request at non-sg transfer case to fix it.

The patch, however, is *removing* initialization to 0...

Quoted 13 lines
Cc Jun Li <[email protected]>
Cc stable <[email protected]>
Fixes 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather buffers")
---
 drivers/usb/gadget/function/f_fs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/gadget/function/f_fs.c +0 -0
index eedd926cc578..b5a1bfc2fc7e 100644

drivers/usb/gadget/function/f_fs.c static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) · line 1109

Quoted 4 lines
drivers/usb/gadget/function/f_fs.c +0 -1
@@ -1106,7 +1106,6 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
 			req->num_sgs = io_data->sgt.nents;
 		} else {
 			req->buf = data;
-			req->num_sgs = 0;

... this doesn't seem to match your commit log. Care to explain?

Signature · 1 line
balbi
author
#2 lore raw
Quoted 31 lines
Quoted 10 lines · Peter Chen

The UDC core uses req->num_sgs to judge if scatter buffer list is used.
Eg: usb_gadget_map_request_by_dev. For f_fs sync io mode, the request is re-used for each request, so if the 1st request->length > PAGE_SIZE, and the 2nd request->length is < PAGE_SIZE, the f_fs uses the 1st
req->num_sgs for the 2nd request, it causes the UDC core get the wrong req->num_sgs value (The 2nd request doesn't use sg).

We set req->num_sgs as 0 for each request at non-sg transfer case to fix it.

The patch, however, is *removing* initialization to 0...

drivers/usb/gadget/function/f_fs.c static ssize_t ffs_epfile_io(struct file *file, struct

Quoted 15 lines
Cc Jun Li <[email protected]>
Cc stable <[email protected]>
Fixes 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather

buffers")

---
 drivers/usb/gadget/function/f_fs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/gadget/function/f_fs.c +0 -0
index eedd926cc578..b5a1bfc2fc7e 100644
@@ -1106,7 +1106,6 @@ static ssize_t ffs_epfile_io(struct file *file, struct

ffs_io_data *io_data)

Quoted 7 lines

drivers/usb/gadget/function/f_fs.c static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) · line 1109

Quoted 4 lines
drivers/usb/gadget/function/f_fs.c +0 -1
 			req->num_sgs = io_data->sgt.nents;
 		} else {
 			req->buf = data;
-			req->num_sgs = 0;

... this doesn't seem to match your commit log. Care to explain?

Sorry, I did not check the patch when I formatted it. I need to pay more attention to it next time. I will send it again.

Peter