HID: cp2112: fix broken gpio_direction_input callback
authorSébastien Szymanski <sebastien.szymanski@armadeus.com>
Fri, 10 Nov 2017 09:01:43 +0000 (10:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Dec 2017 09:10:22 +0000 (10:10 +0100)
[ Upstream commit 7da85fbf1c87d4f73621e0e7666a3387497075a9 ]

When everything goes smoothly, ret is set to 0 which makes the function
to return EIO error.

Fixes: 8e9faa15469e ("HID: cp2112: fix gpio-callback error handling")
Signed-off-by: Sébastien Szymanski <sebastien.szymanski@armadeus.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-cp2112.c

index 078026f63b6f40999a2aa1feb8023d3905a6044c..4e940a096b2ac2d4cd35c1292180fc716b491050 100644 (file)
@@ -196,6 +196,8 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
                                 HID_REQ_GET_REPORT);
        if (ret != CP2112_GPIO_CONFIG_LENGTH) {
                hid_err(hdev, "error requesting GPIO config: %d\n", ret);
+               if (ret >= 0)
+                       ret = -EIO;
                goto exit;
        }
 
@@ -205,8 +207,10 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
        ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
                                 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
                                 HID_REQ_SET_REPORT);
-       if (ret < 0) {
+       if (ret != CP2112_GPIO_CONFIG_LENGTH) {
                hid_err(hdev, "error setting GPIO config: %d\n", ret);
+               if (ret >= 0)
+                       ret = -EIO;
                goto exit;
        }
 
@@ -214,7 +218,7 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
 
 exit:
        mutex_unlock(&dev->lock);
-       return ret < 0 ? ret : -EIO;
+       return ret;
 }
 
 static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value)