Skip to content

Commit 2a5e76b

Browse files
sebszymanskiJiri Kosina
authored andcommitted
HID: cp2112: fix setter callbacks return value
Since commit 6485543 ("HID: cp2112: use new line value setter callbacks"), setting a GPIO value always fails with error -EBADE. That's because the returned value by the setter callbacks is the returned value by the hid_hw_raw_request() function which is the number of bytes sent on success or a negative value on error. The function gpiochip_set() returns -EBADE if the setter callbacks return a value > 0. Fix this by making the setter callbacks return 0 on success or a negative value on error. While at it, use the returned value by cp2112_gpio_set_unlocked() in the direction_output callback. Fixes: 6485543 ("HID: cp2112: use new line value setter callbacks") Signed-off-by: Sébastien Szymanski <[email protected]> Reviewed-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 8599049 commit 2a5e76b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/hid/hid-cp2112.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,12 @@ static int cp2112_gpio_set_unlocked(struct cp2112_device *dev,
229229
ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf,
230230
CP2112_GPIO_SET_LENGTH, HID_FEATURE_REPORT,
231231
HID_REQ_SET_REPORT);
232-
if (ret < 0)
232+
if (ret != CP2112_GPIO_SET_LENGTH) {
233233
hid_err(hdev, "error setting GPIO values: %d\n", ret);
234+
return ret < 0 ? ret : -EIO;
235+
}
234236

235-
return ret;
237+
return 0;
236238
}
237239

238240
static int cp2112_gpio_set(struct gpio_chip *chip, unsigned int offset,
@@ -309,9 +311,7 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
309311
* Set gpio value when output direction is already set,
310312
* as specified in AN495, Rev. 0.2, cpt. 4.4
311313
*/
312-
cp2112_gpio_set_unlocked(dev, offset, value);
313-
314-
return 0;
314+
return cp2112_gpio_set_unlocked(dev, offset, value);
315315
}
316316

317317
static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number,

0 commit comments

Comments
 (0)