Skip to content

Commit a3acc69

Browse files
johnkeepingFelipe Balbi
authored andcommitted
usb: f_fs: Force Reserved1=1 in OS_DESC_EXT_COMPAT
The specification says that the Reserved1 field in OS_DESC_EXT_COMPAT must have the value "1", but when this feature was first implemented we rejected any non-zero values. This was adjusted to accept all non-zero values (while now rejecting zero) in commit 5364239 ("usb: gadget: f_fs: Fix wrong check on reserved1 of OS_DESC_EXT_COMPAT"), but that breaks any userspace programs that worked previously by returning EINVAL when Reserved1 == 0 which was previously the only value that succeeded! If we just set the field to "1" ourselves, both old and new userspace programs continue to work correctly and, as a bonus, old programs are now compliant with the specification without having to fix anything themselves. Fixes: 5364239 ("usb: gadget: f_fs: Fix wrong check on reserved1 of OS_DESC_EXT_COMPAT") Cc: <stable@vger.kernel.org> Signed-off-by: John Keeping <john@metanate.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent a4f0927 commit a3acc69

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • drivers/usb/gadget/function

‎drivers/usb/gadget/function/f_fs.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,9 +2282,18 @@ static int __ffs_data_do_os_desc(enum ffs_os_desc_type type,
22822282
int i;
22832283

22842284
if (len < sizeof(*d) ||
2285-
d->bFirstInterfaceNumber >= ffs->interfaces_count ||
2286-
!d->Reserved1)
2285+
d->bFirstInterfaceNumber >= ffs->interfaces_count)
22872286
return -EINVAL;
2287+
if (d->Reserved1 != 1) {
2288+
/*
2289+
* According to the spec, Reserved1 must be set to 1
2290+
* but older kernels incorrectly rejected non-zero
2291+
* values. We fix it here to avoid returning EINVAL
2292+
* in response to values we used to accept.
2293+
*/
2294+
pr_debug("usb_ext_compat_desc::Reserved1 forced to 1\n");
2295+
d->Reserved1 = 1;
2296+
}
22882297
for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i)
22892298
if (d->Reserved2[i])
22902299
return -EINVAL;

0 commit comments

Comments
 (0)