From 6f14dd6964288ecb4cad7d14b966e6d347ce128b Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 21 Dec 2015 11:18:44 +0100 Subject: gpio: ml-ioh: 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: Feng Tang Cc: Tomoya MORINAGA Signed-off-by: Linus Walleij --- drivers/gpio/gpio-ml-ioh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpio/gpio-ml-ioh.c') diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index 5536108aa9db..7ef704343f05 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c @@ -124,7 +124,7 @@ static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) { struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); - return ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr); + return !!(ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr)); } static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, -- cgit v1.2.3 From 47315578b9894140bef11e2b0fab55d2706e055c Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 7 Dec 2015 10:12:05 +0100 Subject: gpio: ml-ioh: 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: Feng Tang Cc: Tomoya MORINAGA Signed-off-by: Linus Walleij --- drivers/gpio/gpio-ml-ioh.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/gpio/gpio-ml-ioh.c') diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index 7ef704343f05..796a5a4bc4f5 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c @@ -106,7 +106,7 @@ static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12}; static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) { u32 reg_val; - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + struct ioh_gpio *chip = gpiochip_get_data(gpio); unsigned long flags; spin_lock_irqsave(&chip->spinlock, flags); @@ -122,7 +122,7 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) { - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + struct ioh_gpio *chip = gpiochip_get_data(gpio); return !!(ioread32(&chip->reg->regs[chip->ch].pi) & (1 << nr)); } @@ -130,7 +130,7 @@ static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, int val) { - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + struct ioh_gpio *chip = gpiochip_get_data(gpio); u32 pm; u32 reg_val; unsigned long flags; @@ -155,7 +155,7 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) { - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + struct ioh_gpio *chip = gpiochip_get_data(gpio); u32 pm; unsigned long flags; @@ -225,7 +225,7 @@ static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) { - struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); + struct ioh_gpio *chip = gpiochip_get_data(gpio); return chip->irq_base + offset; } @@ -450,7 +450,7 @@ static int ioh_gpio_probe(struct pci_dev *pdev, chip->ch = i; spin_lock_init(&chip->spinlock); ioh_gpio_setup(chip, num_ports[i]); - ret = gpiochip_add(&chip->gpio); + ret = gpiochip_add_data(&chip->gpio, chip); if (ret) { dev_err(&pdev->dev, "IOH gpio: Failed to register GPIO\n"); goto err_gpiochip_add; -- cgit v1.2.3