public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Cc: linux@ew.tq-group.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/5] mfd: tqmx86: make IRQ setup errors non-fatal
Date: Wed, 6 Nov 2024 09:00:27 +0000	[thread overview]
Message-ID: <20241106090027.GI1807686@google.com> (raw)
In-Reply-To: <812ca50b33766b1b528a02a8d5226f21822b2851.1730717841.git.matthias.schiffer@ew.tq-group.com>

On Mon, 04 Nov 2024, Matthias Schiffer wrote:

> GPIO IRQ setup can fail either because an invalid IRQ was passed as a
> parameter, or because the GPIO controller does not support interrupts.
> Neither is severe enough to stop the whole probe; simply disable IRQ
> support in the GPIO resource when setup fails.
> 
> The code is made a bit more robust by introduing a define for the index
> of the IRQ resource in the resource list instead of assuming that it is
> at index 0.
> 
> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
> ---
> 
> v2: no changes (was patch 3/4)
> v3: replace IRQ 0 resource with an empty placeholder to simplify error handling
> v4: no changes
> v5: move placeholder to the end of the resource array, use define for index
> v6: no changes
> 
>  drivers/mfd/tqmx86.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/mfd/tqmx86.c b/drivers/mfd/tqmx86.c
> index 8aa448a67c9a5..1fd2212bf492c 100644
> --- a/drivers/mfd/tqmx86.c
> +++ b/drivers/mfd/tqmx86.c
> @@ -60,6 +60,9 @@ static uint gpio_irq;
>  module_param(gpio_irq, uint, 0);
>  MODULE_PARM_DESC(gpio_irq, "GPIO IRQ number (valid parameters: 7, 9, 12)");
>  
> +/* Index of IRQ placeholder in resource list */
> +#define TQMX86_IRQ_GPIO 1
> +
>  static const struct resource tqmx_i2c_soft_resources[] = {
>  	DEFINE_RES_IO(TQMX86_IOBASE_I2C, TQMX86_IOSIZE_I2C),
>  };
> @@ -68,13 +71,10 @@ static const struct resource tqmx_watchdog_resources[] = {
>  	DEFINE_RES_IO(TQMX86_IOBASE_WATCHDOG, TQMX86_IOSIZE_WATCHDOG),
>  };
>  
> -/*
> - * The IRQ resource must be first, since it is updated with the
> - * configured IRQ in the probe function.
> - */
>  static struct resource tqmx_gpio_resources[] = {
> -	DEFINE_RES_IRQ(0),
>  	DEFINE_RES_IO(TQMX86_IOBASE_GPIO, TQMX86_IOSIZE_GPIO),
> +	/* Placeholder for IRQ resource - filled in by the probe function */

Drop the " - filled in ..." part.  This is a common practice.

> +	[TQMX86_IRQ_GPIO] = {},

Not quite.  What happens if someone comes along and inserts a resource
above this one?  You need to index all of them.  Use an enum.

>  };
>  
>  static struct i2c_board_info tqmx86_i2c_devices[] = {
> @@ -255,13 +255,8 @@ static int tqmx86_probe(struct platform_device *pdev)
>  	if (gpio_irq) {
>  		err = tqmx86_setup_irq(dev, "GPIO", gpio_irq, io_base,
>  				       TQMX86_REG_IO_EXT_INT_GPIO_SHIFT);
> -		if (err)
> -			return err;
> -
> -		/* Assumes the IRQ resource is first. */
> -		tqmx_gpio_resources[0].start = gpio_irq;
> -	} else {
> -		tqmx_gpio_resources[0].flags = 0;
> +		if (!err)
> +			tqmx_gpio_resources[TQMX86_IRQ_GPIO] = DEFINE_RES_IRQ(gpio_irq);

This section just became a lot nicer.

>  	}
>  
>  	ocores_platform_data.clock_khz = tqmx86_board_id_to_clk_rate(dev, board_id);
> -- 
> TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
> Amtsgericht München, HRB 105018
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> https://www.tq-group.com/
> 

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2024-11-06  9:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04 11:13 [PATCH v6 0/5] mfd: tqmx86: new hardware and GPIO/I2C IRQ improvements/additions Matthias Schiffer
2024-11-04 11:13 ` [PATCH v6 1/5] mfd: tqmx86: add board definitions for TQMx120UC, TQMx130UC and TQMxE41S Matthias Schiffer
2024-11-04 11:13 ` [PATCH v6 2/5] mfd: tqmx86: improve gpio_irq module parameter description Matthias Schiffer
2024-11-04 11:13 ` [PATCH v6 3/5] mfd: tqmx86: refactor GPIO IRQ setup Matthias Schiffer
2024-11-04 11:13 ` [PATCH v6 4/5] mfd: tqmx86: make IRQ setup errors non-fatal Matthias Schiffer
2024-11-06  9:00   ` Lee Jones [this message]
2024-11-04 11:13 ` [PATCH v6 5/5] mfd: tqmx86: add I2C IRQ support Matthias Schiffer
2024-11-06  9:01   ` Lee Jones

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=20241106090027.GI1807686@google.com \
    --to=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@ew.tq-group.com \
    --cc=matthias.schiffer@ew.tq-group.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox