All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Kevin Hilman <khilman@kernel.org>,
	linux-omap@vger.kernel.org
Subject: Re: [PATCH] gpio: omap: Give unique labels to each GPIO bank/chip
Date: Fri, 29 Dec 2017 15:03:42 +0100	[thread overview]
Message-ID: <20171229140342.GD16993@localhost> (raw)
In-Reply-To: <20171229122812.29743-1-linus.walleij@linaro.org>

On Fri, Dec 29, 2017 at 01:28:12PM +0100, Linus Walleij wrote:
> As we need to add GPIO lookup tables to the OMAP platforms, we
> need to reference each GPIO chip with a unique label. Use the GPIO
> base to name each chip, "gpio-0-31", "gpio-32-63" etc. Also fix
> a small error on the error path of the probe() where the chip
> would not be free()ed proberly under all circumstances.

Since these two changes appear to be entirely unrelated, I suggest
splitting this one up into two patches.

> Cc: Grygorii Strashko <grygorii.strashko@ti.com>
> Cc: Santosh Shilimkar <ssantosh@kernel.org>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: linux-omap@vger.kernel.org
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/gpio/gpio-omap.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index e136d666f1e5..14fc3fb6f96e 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -1059,6 +1059,7 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
>  static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
>  {
>  	static int gpio;
> +	const char *label;
>  	int irq_base = 0;
>  	int ret;
>  
> @@ -1080,7 +1081,11 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
>  			bank->chip.parent = &omap_mpuio_device.dev;
>  		bank->chip.base = OMAP_MPUIO(0);
>  	} else {
> -		bank->chip.label = "gpio";
> +		label = devm_kasprintf(bank->chip.parent, GFP_KERNEL, "gpio-%d-%d",
> +				       gpio, gpio + bank->width - 1);
> +		if (!label)
> +			return -ENOMEM;
> +		bank->chip.label = label;
>  		bank->chip.base = gpio;
>  	}
>  	bank->chip.ngpio = bank->width;
> @@ -1104,7 +1109,8 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
>  					-1, 0, bank->width, 0);
>  	if (irq_base < 0) {
>  		dev_err(bank->chip.parent, "Couldn't allocate IRQ numbers\n");
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto out_err_chip;
>  	}
>  #endif
>  
> @@ -1123,7 +1129,8 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
>  		dev_err(bank->chip.parent,
>  			"Couldn't add irqchip to gpiochip %d\n", ret);
>  		gpiochip_remove(&bank->chip);
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto out_err_chip;

Here it looks like you are now introducing a double free
(gpiochip_remove) instead.

>  	}
>  
>  	gpiochip_set_chained_irqchip(&bank->chip, irqc, bank->irq, NULL);
> @@ -1132,8 +1139,12 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
>  			       omap_gpio_irq_handler,
>  			       0, dev_name(bank->chip.parent), bank);
>  	if (ret)
> -		gpiochip_remove(&bank->chip);
> +		goto out_err_chip;
> +
> +	return ret;

I'd use "return 0" here for readability reasons.

>  
> +out_err_chip:

And name this label after what it does, for example, "err_remove_chip".

> +	gpiochip_remove(&bank->chip);
>  	return ret;
>  }

Johan

      reply	other threads:[~2017-12-29 14:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-29 12:28 [PATCH] gpio: omap: Give unique labels to each GPIO bank/chip Linus Walleij
2017-12-29 14:03 ` Johan Hovold [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171229140342.GD16993@localhost \
    --to=johan@kernel.org \
    --cc=grygorii.strashko@ti.com \
    --cc=khilman@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=ssantosh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.