gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input [Linux 3.16.72]

This Linux kernel change "gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input" is included in the Linux 3.16.72 release. This change is authored by Axel Lin <axel.lin [at]> on Mon Mar 11 21:29:37 2019 +0800. The commit for this change in Linux stable tree is b101a36 (patch) which is from upstream commit c5bc6e5. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream c5bc6e5.

gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input

commit c5bc6e526d3f217ed2cc3681d256dc4a2af4cc2b upstream.

Current code test wrong value so it does not verify if the written
data is correctly read back. Fix it.
Also make it return -EPERM if read value does not match written bit,
just like it done for adnp_gpio_direction_output().

Fixes: 5e969a401a01 ("gpio: Add Avionic Design N-bit GPIO expander support")
Signed-off-by: Axel Lin <>
Reviewed-by: Thierry Reding <>
Signed-off-by: Bartosz Golaszewski <>
Signed-off-by: Ben Hutchings <>

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/gpio/gpio-adnp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-adnp.c b/drivers/gpio/gpio-adnp.c
index b2239d6..f2c0926 100644
--- a/drivers/gpio/gpio-adnp.c
+++ b/drivers/gpio/gpio-adnp.c
@@ -140,8 +140,10 @@ static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
    if (err < 0)
        goto out;

-   if (err & BIT(pos))
-       err = -EACCES;
+   if (value & BIT(pos)) {
+       err = -EPERM;
+       goto out;
+   }

    err = 0;

Leave a Reply

Your email address will not be published. Required fields are marked *