Skip to content

Commit acb3dac

Browse files
dpenklergregkh
authored andcommitted
usb: usbtmc: Fix read_stb function and get_stb ioctl
The usbtmc488_ioctl_read_stb function relied on a positive return from usbtmc_get_stb to reset the srq condition in the driver. The USBTMC_IOCTL_GET_STB case tested for a positive return to return the stb to the user. Commit: <cac01bd178d6> ("usb: usbtmc: Fix erroneous get_stb ioctl error returns") changed the return value of usbtmc_get_stb to 0 on success instead of returning the value of usb_control_msg which is positive in the normal case. This change caused the function usbtmc488_ioctl_read_stb and the USBTMC_IOCTL_GET_STB ioctl to no longer function correctly. Change the test in usbtmc488_ioctl_read_stb to test for failure first and return the failure code immediately. Change the test for the USBTMC_IOCTL_GET_STB ioctl to test for 0 instead of a positive value. Fixes: cac01bd ("usb: usbtmc: Fix erroneous get_stb ioctl error returns") Cc: [email protected] Signed-off-by: Dave Penkler <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3335a1b commit acb3dac

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/usb/class/usbtmc.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,15 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data,
563563

564564
rv = usbtmc_get_stb(file_data, &stb);
565565

566-
if (rv > 0) {
567-
srq_asserted = atomic_xchg(&file_data->srq_asserted,
568-
srq_asserted);
569-
if (srq_asserted)
570-
stb |= 0x40; /* Set RQS bit */
566+
if (rv < 0)
567+
return rv;
568+
569+
srq_asserted = atomic_xchg(&file_data->srq_asserted, srq_asserted);
570+
if (srq_asserted)
571+
stb |= 0x40; /* Set RQS bit */
572+
573+
rv = put_user(stb, (__u8 __user *)arg);
571574

572-
rv = put_user(stb, (__u8 __user *)arg);
573-
}
574575
return rv;
575576

576577
}
@@ -2199,7 +2200,7 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
21992200

22002201
case USBTMC_IOCTL_GET_STB:
22012202
retval = usbtmc_get_stb(file_data, &tmp_byte);
2202-
if (retval > 0)
2203+
if (!retval)
22032204
retval = put_user(tmp_byte, (__u8 __user *)arg);
22042205
break;
22052206

0 commit comments

Comments
 (0)