usb: usbtmc: Fix read/get_stb and timeout in get_stb
Subsystems (2)
cover usb: usbtmc: Fix read/get_stb and timeout in get_stb
Patch 1: Fixes a regression introduced by a previous commit where the
changed return value of usbtmc_get_stb caused usbtmc488_ioctl_read_stb and the USBTMC_IOCTL_GET_STB ioctl to fail.
Patch 2: Fixes the units of the timeout value passed to
wait_event_interruptible_timeout in usbtmc_get_stb.
Dave Penkler (2):
usb: usbtmc: Fix read_stb function and get_stb ioctl
usb: usbtmc: Fix timeout value in get_stb
drivers/usb/class/usbtmc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Signature · 1 line
2.49.0
cover usb: usbtmc Fix read/get_stb and timeout in get_stb
Patch 1: Fixes a regression introduced by a previous commit where the
changed return value of usbtmc_get_stb caused usbtmc488_ioctl_read_stb and the USBTMC_IOCTL_GET_STB ioctl to fail.
Patch 2: Fixes the units of the timeout value passed to
wait_event_interruptible_timeout in usbtmc_get_stb.
Dave Penkler (2):
usb: usbtmc: Fix read_stb function and get_stb ioctl
usb: usbtmc: Fix timeout value in get_stb
drivers/usb/class/usbtmc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/2 usb: usbtmc: Fix read_stb function and get_stb ioctl
In reply to Dave PenklerThe 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.
--- drivers/usb/class/usbtmc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/class/usbtmc.c +9 -8
@@ -563,14 +563,15 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, rv =usbtmc_get_stb (file_data, &stb); -if (rv >0 ) { - srq_asserted =atomic_xchg (&file_data->srq_asserted, - srq_asserted); -if (srq_asserted) - stb |=0x40 ;/* Set RQS bit */ +if (rv <0 ) +return rv; + + srq_asserted =atomic_xchg (&file_data->srq_asserted, srq_asserted); +if (srq_asserted) + stb |=0x40 ;/* Set RQS bit */ + + rv =put_user (stb, (__u8 __user *)arg); - rv =put_user (stb, (__u8 __user *)arg); - }return rv; }
@@ -2199,7 +2200,7 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case USBTMC_IOCTL_GET_STB : retval =usbtmc_get_stb (file_data, &tmp_byte); -if (retval >0 ) +if (!retval) retval =put_user (tmp_byte, (__u8 __user *)arg);break ;
Signature · 1 line
2.49.0
PATCH 2/2 usb: usbtmc: Fix timeout value in get_stb
In reply to Dave Penklerwait_event_interruptible_timeout requires a timeout argument in units of jiffies. It was being called in usbtmc_get_stb with the usb timeout value which is in units of milliseconds.
Pass the timeout argument converted to jiffies.
--- drivers/usb/class/usbtmc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/class/usbtmc.c +3 -1
@@ -483,6 +483,7 @@ static int usbtmc_get_stb(struct usbtmc_file_data *file_data, __u8 *stb)u8 tag;int rv;long wait_rv; +unsigned long expire;dev_dbg (dev,"Enter ioctl_read_stb iin_ep_present: %d\n" , data->iin_ep_present);
@@ -512,10 +513,11 @@ static int usbtmc_get_stb(struct usbtmc_file_data *file_data, __u8 *stb) }if (data->iin_ep_present) { + expire =msecs_to_jiffies (file_data->timeout); wait_rv =wait_event_interruptible_timeout ( data->waitq,atomic_read (&data->iin_data_valid) !=0 , - file_data->timeout); + expire);if (wait_rv <0 ) {dev_dbg (dev,"wait interrupted %ld\n" , wait_rv); rv = wait_rv;
Signature · 1 line
2.49.0