From 1f66adfb5eb81428bc1a5700cffd22ba8e772272 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 21 Dec 2015 10:30:02 +0100 Subject: gpio: da9052: Be sure to clamp return value As we want gpio_chip .get() calls to be able to return negative error codes and propagate to drivers, we need to go over all drivers and make sure their return values are clamped to [0,1]. We do this by using the ret = !!(val) design pattern. Cc: Ashish Jangam Signed-off-by: Linus Walleij --- drivers/gpio/gpio-da9052.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/gpio/gpio-da9052.c') diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index 2e9578ec0ca1..38bd8f122bfc 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c @@ -89,15 +89,12 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) DA9052_STATUS_D_REG); if (ret < 0) return ret; - if (ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset))) - return 1; - else - return 0; + return !!(ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset))); case DA9052_OUTPUT_PUSHPULL: if (da9052_gpio_port_odd(offset)) - return ret & DA9052_GPIO_ODD_PORT_MODE; + return !!(ret & DA9052_GPIO_ODD_PORT_MODE); else - return ret & DA9052_GPIO_EVEN_PORT_MODE; + return !!(ret & DA9052_GPIO_EVEN_PORT_MODE); default: return -EINVAL; } -- cgit v1.2.3 From 0f6082d2b811ec56c4f7ecdde80410e17cf04452 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 4 Dec 2015 16:19:52 +0100 Subject: gpio: da9052: use gpiochip data pointer This makes the driver use the data pointer added to the gpio_chip to store a pointer to the state container instead of relying on container_of(). Cc: Ashish Jangam Signed-off-by: Linus Walleij --- drivers/gpio/gpio-da9052.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'drivers/gpio/gpio-da9052.c') diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index 38bd8f122bfc..f9b3247ad14b 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c @@ -51,11 +51,6 @@ struct da9052_gpio { struct gpio_chip gp; }; -static inline struct da9052_gpio *to_da9052_gpio(struct gpio_chip *chip) -{ - return container_of(chip, struct da9052_gpio, gp); -} - static unsigned char da9052_gpio_port_odd(unsigned offset) { return offset % 2; @@ -63,7 +58,7 @@ static unsigned char da9052_gpio_port_odd(unsigned offset) static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) { - struct da9052_gpio *gpio = to_da9052_gpio(gc); + struct da9052_gpio *gpio = gpiochip_get_data(gc); int da9052_port_direction = 0; int ret; @@ -102,7 +97,7 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { - struct da9052_gpio *gpio = to_da9052_gpio(gc); + struct da9052_gpio *gpio = gpiochip_get_data(gc); int ret; if (da9052_gpio_port_odd(offset)) { @@ -128,7 +123,7 @@ static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { - struct da9052_gpio *gpio = to_da9052_gpio(gc); + struct da9052_gpio *gpio = gpiochip_get_data(gc); unsigned char register_value; int ret; @@ -154,7 +149,7 @@ static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset) static int da9052_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { - struct da9052_gpio *gpio = to_da9052_gpio(gc); + struct da9052_gpio *gpio = gpiochip_get_data(gc); unsigned char register_value; int ret; @@ -179,7 +174,7 @@ static int da9052_gpio_direction_output(struct gpio_chip *gc, static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset) { - struct da9052_gpio *gpio = to_da9052_gpio(gc); + struct da9052_gpio *gpio = gpiochip_get_data(gc); struct da9052 *da9052 = gpio->da9052; int irq; @@ -219,7 +214,7 @@ static int da9052_gpio_probe(struct platform_device *pdev) if (pdata && pdata->gpio_base) gpio->gp.base = pdata->gpio_base; - ret = gpiochip_add(&gpio->gp); + ret = gpiochip_add_data(&gpio->gp, gpio); if (ret < 0) { dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); return ret; -- cgit v1.2.3