All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Pan Chuang <panchuang@vivo.com>
Cc: <tglx@linutronix.de>, <linux-kernel@vger.kernel.org>,
	<miquel.raynal@bootlin.com>, <u.kleine-koenig@pengutronix.de>,
	<angeg.delregno@collabora.com>, <krzk@kernel.org>,
	<a.fatoum@pengutronix.de>, <frank.li@vivo.com>
Subject: Re: [PATCH v7 1/1] genirq/devres: Add dev_err_probe() in devm_request_threaded_irq() and devm_request_any_context_irq()
Date: Mon, 28 Jul 2025 16:10:50 +0100	[thread overview]
Message-ID: <20250728161050.000018f2@huawei.com> (raw)
In-Reply-To: <20250728123251.384375-2-panchuang@vivo.com>

On Mon, 28 Jul 2025 20:32:51 +0800
Pan Chuang <panchuang@vivo.com> wrote:

> Modify devm_request_thread_irq() and devm_request_any_context_irq(), in
> order to print an error message by default when the request fails.
> 
> Converting drivers to use this API has the following benefits:
> 
>   1.More than 2,000 lines of code can be saved by removing redundant error
>   messages in drivers.
> 
>   2.Upper-layer functions can directly return error codes without missing
>   debugging information.
> 
>   3.Having proper and consistent information about why the device cannot
>   be used is useful.
> 
> Signed-off-by: Pan Chuang <panchuang@vivo.com>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  kernel/irq/devres.c | 78 ++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 74 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
> index eb16a58e0322..a1b934c1ecc8 100644
> --- a/kernel/irq/devres.c
> +++ b/kernel/irq/devres.c
> @@ -31,7 +31,7 @@ static int devm_irq_match(struct device *dev, void *res, void *data)
>  }
>  
>  /**
> - *	devm_request_threaded_irq - allocate an interrupt line for a managed device
> + *	__devm_request_threaded_irq - allocate an interrupt line for a managed device
>   *	@dev: device to request interrupt for
>   *	@irq: Interrupt line to allocate
>   *	@handler: Function to be called when the IRQ occurs
> @@ -49,7 +49,7 @@ static int devm_irq_match(struct device *dev, void *res, void *data)
>   *	If an IRQ allocated with this function needs to be freed
>   *	separately, devm_free_irq() must be used.
>   */
> -int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> +static int __devm_request_threaded_irq(struct device *dev, unsigned int irq,
>  			      irq_handler_t handler, irq_handler_t thread_fn,

Parameters were previously aligned after (
Probably best to realign them to keep that style.

>  			      unsigned long irqflags, const char *devname,
>  			      void *dev_id)
> @@ -78,10 +78,46 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
>  
>  	return 0;
>  }
> +
> +/**
> + * devm_request_threaded_irq - allocate an interrupt line for a managed device with error logging
> + * @dev:	Device to request interrupt for
> + * @irq:	Interrupt line to allocate
> + * @handler:	Function to be called when the IRQ occurs
> + * @thread_fn:	Function to be called in a threaded interrupt context. NULL
> + *		for devices which handle everything in @handler
> + * @irqflags:	Interrupt type flags
> + * @devname:	An ascii name for the claiming device, dev_name(dev) if NULL
> + * @dev_id:	A cookie passed back to the handler function
> + *
> + * This function extends __devm_request_threaded_irq by adding detailed error
> + * logging via dev_err_probe() when the underlying request fails. It ensures the
> + * interrupt is automatically freed on driver detach and provides contextual
> + * information (e.g., IRQ number, handler address, device name) in error messages.
> + *
> + * Return: 0 on success or a negative error number.
> + */
> +int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> +			      irq_handler_t handler, irq_handler_t thread_fn,
> +			      unsigned long irqflags, const char *devname,
> +			      void *dev_id)
> +{
> +	int rc;
> +
> +	rc = __devm_request_threaded_irq(dev, irq, handler, thread_fn, irqflags,
> +					 devname, dev_id);
> +	if (rc < 0) {

I'm in two minds about this.
The internals of __devm_request_threaded_irq() use if (rc)
so we know that will be fine here.

However, given you are passing it to dev_err_probe() locally being sure
that we don't have a value > 0 perhaps makes sense.

> +		return dev_err_probe(dev, rc, "request_irq(%u) %pS %pS %s\n",
> +				     irq, handler, thread_fn,
> +				     devname ? : dev_name(dev));
> +	}
> +
> +	return 0;
> +}
>  EXPORT_SYMBOL(devm_request_threaded_irq);

Same comments apply to remaining code.

Jonathan


  reply	other threads:[~2025-07-28 15:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28 12:32 [PATCH v7 0/1] genirq/devres: Add dev_err_probe() in devm_request_threaded_irq() and devm_request_any_context_irq() Pan Chuang
2025-07-28 12:32 ` [PATCH v7 1/1] " Pan Chuang
2025-07-28 15:10   ` Jonathan Cameron [this message]
2025-07-28 15:26   ` Thomas Gleixner

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=20250728161050.000018f2@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=angeg.delregno@collabora.com \
    --cc=frank.li@vivo.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=panchuang@vivo.com \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /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.