Skip to content

Commit b66437c

Browse files
Sanman Pradhangroeck
authored andcommitted
hwmon: (powerz) Fix missing usb_kill_urb() on signal interrupt
wait_for_completion_interruptible_timeout() returns -ERESTARTSYS when interrupted. This needs to abort the URB and return an error. No data has been received from the device so any reads from the transfer buffer are invalid. The original code tests !ret, which only catches the timeout case (0). On signal delivery (-ERESTARTSYS), !ret is false so the function skips usb_kill_urb() and falls through to read from the unfilled transfer buffer. Fix by capturing the return value into a long (matching the function return type) and handling signal (negative) and timeout (zero) cases with separate checks that both call usb_kill_urb() before returning. Fixes: 4381a36 ("hwmon: add POWER-Z driver") Cc: stable@vger.kernel.org Signed-off-by: Sanman Pradhan <psanman@juniper.net> Link: https://lore.kernel.org/r/20260410002521.422645-3-sanman.pradhan@hpe.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 08e57f5 commit b66437c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/hwmon/powerz.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static void powerz_usb_cmd_complete(struct urb *urb)
106106

107107
static int powerz_read_data(struct usb_device *udev, struct powerz_priv *priv)
108108
{
109+
long rc;
109110
int ret;
110111

111112
if (!priv->urb)
@@ -127,8 +128,14 @@ static int powerz_read_data(struct usb_device *udev, struct powerz_priv *priv)
127128
if (ret)
128129
return ret;
129130

130-
if (!wait_for_completion_interruptible_timeout
131-
(&priv->completion, msecs_to_jiffies(5))) {
131+
rc = wait_for_completion_interruptible_timeout(&priv->completion,
132+
msecs_to_jiffies(5));
133+
if (rc < 0) {
134+
usb_kill_urb(priv->urb);
135+
return rc;
136+
}
137+
138+
if (rc == 0) {
132139
usb_kill_urb(priv->urb);
133140
return -EIO;
134141
}

0 commit comments

Comments
 (0)