mbox series

[v3,0/5] introduce devm_request_threaded_irq_emsg()

Message ID 20230703090455.62101-1-frank.li@vivo.com
Headers show
Series introduce devm_request_threaded_irq_emsg() | expand

Message

Yangtao Li July 3, 2023, 9:04 a.m. UTC
There are more than 700 calls to the devm_request_threaded_irq method.
Most drivers only request one interrupt resource, and these error
messages are basically the same. If error messages are printed
everywhere, more than 1000 lines of code can be saved by removing the
msg in the driver.

And tglx point out that:

  If we actually look at the call sites of
  devm_request_threaded_irq() then the vast majority of them print more or
  less lousy error messages. A quick grep/sed/awk/sort/uniq revealed

     519 messages total (there are probably more)

     352 unique messages

     323 unique messages after lower casing

         Those 323 are mostly just variants of the same patterns with
         slight modifications in formatting and information provided.

     186 of these messages do not deliver any useful information,
         e.g. "no irq", "

     The most useful one of all is: "could request wakeup irq: %d"

  So there is certainly an argument to be made that this particular
  function should print a well formatted and informative error message.

  It's not a general allocator like kmalloc(). It's specialized and in the
  vast majority of cases failing to request the interrupt causes the
  device probe to fail. So having proper and consistent information why
  the device cannot be used _is_ useful.

So add devm_request_threaded_irq_emsg(), which ensure that all error
handling branches print error information. In this way, when this function
fails, the upper-layer functions can directly return an error code without
missing debugging information. Otherwise, the error message will be
printed redundantly or missing.

Yangtao Li (5):
  genirq/devres: Add devm_request_threaded_irq_emsg()
  thermal/drivers/armada: convert to use
    devm_request_threaded_irq_emsg()
  thermal/drivers/brcmstb_thermal: convert to use
    devm_request_threaded_irq_emsg()
  thermal/drivers/db8500: convert to use
    devm_request_threaded_irq_emsg()
  thermal/drivers/mediatek/lvts_thermal: convert to use
    devm_request_threaded_irq_emsg()

 drivers/thermal/armada_thermal.c           | 13 +++----
 drivers/thermal/broadcom/brcmstb_thermal.c | 12 +++----
 drivers/thermal/db8500_thermal.c           | 16 ++++-----
 drivers/thermal/mediatek/lvts_thermal.c    |  6 ++--
 include/linux/interrupt.h                  |  6 ++++
 kernel/irq/devres.c                        | 42 ++++++++++++++++++++++
 6 files changed, 67 insertions(+), 28 deletions(-)

Comments

Yangtao Li July 3, 2023, 11:47 a.m. UTC | #1
+cc u.kleine-koenig@pengutronix.de, krzysztof.kozlowski@linaro.org

On 2023/7/3 17:04, Yangtao Li wrote:
> There are more than 700 calls to the devm_request_threaded_irq method.
> Most drivers only request one interrupt resource, and these error
> messages are basically the same. If error messages are printed
> everywhere, more than 1000 lines of code can be saved by removing the
> msg in the driver.
>
> And tglx point out that:
>
>    If we actually look at the call sites of
>    devm_request_threaded_irq() then the vast majority of them print more or
>    less lousy error messages. A quick grep/sed/awk/sort/uniq revealed
>
>       519 messages total (there are probably more)
>
>       352 unique messages
>
>       323 unique messages after lower casing
>
>           Those 323 are mostly just variants of the same patterns with
>           slight modifications in formatting and information provided.
>
>       186 of these messages do not deliver any useful information,
>           e.g. "no irq", "
>
>       The most useful one of all is: "could request wakeup irq: %d"
>
>    So there is certainly an argument to be made that this particular
>    function should print a well formatted and informative error message.
>
>    It's not a general allocator like kmalloc(). It's specialized and in the
>    vast majority of cases failing to request the interrupt causes the
>    device probe to fail. So having proper and consistent information why
>    the device cannot be used _is_ useful.
>
> So add devm_request_threaded_irq_emsg(), which ensure that all error
> handling branches print error information. In this way, when this function
> fails, the upper-layer functions can directly return an error code without
> missing debugging information. Otherwise, the error message will be
> printed redundantly or missing.
>
> Yangtao Li (5):
>    genirq/devres: Add devm_request_threaded_irq_emsg()
>    thermal/drivers/armada: convert to use
>      devm_request_threaded_irq_emsg()
>    thermal/drivers/brcmstb_thermal: convert to use
>      devm_request_threaded_irq_emsg()
>    thermal/drivers/db8500: convert to use
>      devm_request_threaded_irq_emsg()
>    thermal/drivers/mediatek/lvts_thermal: convert to use
>      devm_request_threaded_irq_emsg()
>
>   drivers/thermal/armada_thermal.c           | 13 +++----
>   drivers/thermal/broadcom/brcmstb_thermal.c | 12 +++----
>   drivers/thermal/db8500_thermal.c           | 16 ++++-----
>   drivers/thermal/mediatek/lvts_thermal.c    |  6 ++--
>   include/linux/interrupt.h                  |  6 ++++
>   kernel/irq/devres.c                        | 42 ++++++++++++++++++++++
>   6 files changed, 67 insertions(+), 28 deletions(-)
>
Krzysztof Kozlowski July 3, 2023, 12:31 p.m. UTC | #2
On 03/07/2023 11:04, Yangtao Li wrote:
> There are more than 700 calls to the devm_request_threaded_irq method.
> Most drivers only request one interrupt resource, and these error
> messages are basically the same. If error messages are printed
> everywhere, more than 1000 lines of code can be saved by removing the
> msg in the driver.


...

> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
> +				   irq_handler_t handler, irq_handler_t thread_fn,
> +				   unsigned long irqflags, const char *devname,
> +				   void *dev_id, const char *emsg)
> +{
> +	int rc;
> +
> +	rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
> +				       devname, dev_id);
> +	if (rc && rc != -EPROBE_DEFER) {
> +		dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
> +			thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
> +			emsg ? : "", ERR_PTR(rc));

It is open-coding dev_err_probe(). Just use dev_err_probe instead.

Best regards,
Krzysztof
Krzysztof Kozlowski July 3, 2023, 1:37 p.m. UTC | #3
On 03/07/2023 15:24, Yangtao Li wrote:
> 
> On 2023/7/3 20:31, Krzysztof Kozlowski wrote:
>> [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
>>
>> On 03/07/2023 11:04, Yangtao Li wrote:
>>> There are more than 700 calls to the devm_request_threaded_irq method.
>>> Most drivers only request one interrupt resource, and these error
>>> messages are basically the same. If error messages are printed
>>> everywhere, more than 1000 lines of code can be saved by removing the
>>> msg in the driver.
>>
>> ...
>>
>>> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>>> +                                irq_handler_t handler, irq_handler_t thread_fn,
>>> +                                unsigned long irqflags, const char *devname,
>>> +                                void *dev_id, const char *emsg)
>>> +{
>>> +     int rc;
>>> +
>>> +     rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>>> +                                    devname, dev_id);
>>> +     if (rc && rc != -EPROBE_DEFER) {
>>> +             dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
>>> +                     thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
>>> +                     emsg ? : "", ERR_PTR(rc));
>> It is open-coding dev_err_probe(). Just use dev_err_probe instead.
> 
> 
> How about the following? If possible, I would like to start modifying 
> more drivers in the next version.
> 
> 
> int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>                                     irq_handler_t handler, irq_handler_t 
> thread_fn,
>                                     unsigned long irqflags, const char 
> *devname,
>                                     void *dev_id, const char *emsg)
> {
>          int rc;
> 
>          rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>                                         devname, dev_id);
>          if (rc) {
>                  dev_err_probe(dev, rc, "Failed to request %sinterrupt 
> %u %s %s\n",
>                                thread_fn ? "threaded " : "", irq, 
> devname ? : dev_name(dev),
>                                emsg ? : "");

That's not the syntax already used - see existing code with `git grep`.
Instead - return dev_err_probe().


Best regards,
Krzysztof
Krzysztof Kozlowski July 4, 2023, 8:48 a.m. UTC | #4
On 03/07/2023 19:43, Uwe Kleine-König wrote:
> Hello Krzysztof,
> 
> On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:
>> On 03/07/2023 11:04, Yangtao Li wrote:
>>> There are more than 700 calls to the devm_request_threaded_irq method.
>>> Most drivers only request one interrupt resource, and these error
>>> messages are basically the same. If error messages are printed
>>> everywhere, more than 1000 lines of code can be saved by removing the
>>> msg in the driver.
>>
>>
>> ...
>>
>>> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>>> +				   irq_handler_t handler, irq_handler_t thread_fn,
>>> +				   unsigned long irqflags, const char *devname,
>>> +				   void *dev_id, const char *emsg)
>>> +{
>>> +	int rc;
>>> +
>>> +	rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>>> +				       devname, dev_id);
>>> +	if (rc && rc != -EPROBE_DEFER) {
>>> +		dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
>>> +			thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
>>> +			emsg ? : "", ERR_PTR(rc));
>>
>> It is open-coding dev_err_probe(). Just use dev_err_probe instead.
> 
> dev_err_probe is supposed to be only called in probe functions, while
> devm_request_threaded_irq might be called in other contexts (e.g. when a
> device is opened). That's why I asked to not use dev_err_probe() in v2

True, but then all the callers of this function will forget to set
deferred probe reason.

Best regards,
Krzysztof
Yangtao Li July 4, 2023, 9:06 a.m. UTC | #5
On 2023/7/4 16:48, Krzysztof Kozlowski wrote:

> [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
>
> On 03/07/2023 19:43, Uwe Kleine-König wrote:
>> Hello Krzysztof,
>>
>> On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:
>>> On 03/07/2023 11:04, Yangtao Li wrote:
>>>> There are more than 700 calls to the devm_request_threaded_irq method.
>>>> Most drivers only request one interrupt resource, and these error
>>>> messages are basically the same. If error messages are printed
>>>> everywhere, more than 1000 lines of code can be saved by removing the
>>>> msg in the driver.
>>>
>>> ...
>>>
>>>> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>>>> +                              irq_handler_t handler, irq_handler_t thread_fn,
>>>> +                              unsigned long irqflags, const char *devname,
>>>> +                              void *dev_id, const char *emsg)
>>>> +{
>>>> +   int rc;
>>>> +
>>>> +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>>>> +                                  devname, dev_id);
>>>> +   if (rc && rc != -EPROBE_DEFER) {
>>>> +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
>>>> +                   thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
>>>> +                   emsg ? : "", ERR_PTR(rc));
>>> It is open-coding dev_err_probe(). Just use dev_err_probe instead.
>> dev_err_probe is supposed to be only called in probe functions, while
>> devm_request_threaded_irq might be called in other contexts (e.g. when a
>> device is opened). That's why I asked to not use dev_err_probe() in v2
> True, but then all the callers of this function will forget to set
> deferred probe reason.


So let's use dev_err_probe?


BTW, any suggestions for names here, keep using 
devm_request_threaded_irq_emsg or change to a new name?

I am afraid that after more drivers are changed in the follow-up series, 
the name will need to be changed again.


Thx,

Yangtao


>
> Best regards,
> Krzysztof
>
Uwe Kleine-König July 4, 2023, 2:19 p.m. UTC | #6
Hello,

On Tue, Jul 04, 2023 at 05:06:12PM +0800, Yangtao Li wrote:
> On 2023/7/4 16:48, Krzysztof Kozlowski wrote:
> 
> > [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
> > 
> > On 03/07/2023 19:43, Uwe Kleine-König wrote:
> > > Hello Krzysztof,
> > > 
> > > On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:
> > > > On 03/07/2023 11:04, Yangtao Li wrote:
> > > > > There are more than 700 calls to the devm_request_threaded_irq method.
> > > > > Most drivers only request one interrupt resource, and these error
> > > > > messages are basically the same. If error messages are printed
> > > > > everywhere, more than 1000 lines of code can be saved by removing the
> > > > > msg in the driver.
> > > > 
> > > > ...
> > > > 
> > > > > +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
> > > > > +                              irq_handler_t handler, irq_handler_t thread_fn,
> > > > > +                              unsigned long irqflags, const char *devname,
> > > > > +                              void *dev_id, const char *emsg)
> > > > > +{
> > > > > +   int rc;
> > > > > +
> > > > > +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
> > > > > +                                  devname, dev_id);
> > > > > +   if (rc && rc != -EPROBE_DEFER) {
> > > > > +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
> > > > > +                   thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
> > > > > +                   emsg ? : "", ERR_PTR(rc));
> > > > It is open-coding dev_err_probe(). Just use dev_err_probe instead.
> > > dev_err_probe is supposed to be only called in probe functions, while
> > > devm_request_threaded_irq might be called in other contexts (e.g. when a
> > > device is opened). That's why I asked to not use dev_err_probe() in v2
> > True, but then all the callers of this function will forget to set
> > deferred probe reason.

That's another reason for letting the driver issue the error message and
not the request_irq function.
 
> So let's use dev_err_probe?
> 
> BTW, any suggestions for names here, keep using
> devm_request_threaded_irq_emsg or change to a new name?

I would have called it devm_request_threaded_irq_verbose() which I
consider easier to understand. But maybe that is just my (green)
bikeshed.

Best regards
Uwe
Jonathan Cameron July 5, 2023, 2:15 a.m. UTC | #7
On Tue, 4 Jul 2023 16:19:54 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> Hello,
> 
> On Tue, Jul 04, 2023 at 05:06:12PM +0800, Yangtao Li wrote:
> > On 2023/7/4 16:48, Krzysztof Kozlowski wrote:
> >   
> > > [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
> > > 
> > > On 03/07/2023 19:43, Uwe Kleine-König wrote:  
> > > > Hello Krzysztof,
> > > > 
> > > > On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:  
> > > > > On 03/07/2023 11:04, Yangtao Li wrote:  
> > > > > > There are more than 700 calls to the devm_request_threaded_irq method.
> > > > > > Most drivers only request one interrupt resource, and these error
> > > > > > messages are basically the same. If error messages are printed
> > > > > > everywhere, more than 1000 lines of code can be saved by removing the
> > > > > > msg in the driver.  
> > > > > 
> > > > > ...
> > > > >   
> > > > > > +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
> > > > > > +                              irq_handler_t handler, irq_handler_t thread_fn,
> > > > > > +                              unsigned long irqflags, const char *devname,
> > > > > > +                              void *dev_id, const char *emsg)
> > > > > > +{
> > > > > > +   int rc;
> > > > > > +
> > > > > > +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
> > > > > > +                                  devname, dev_id);
> > > > > > +   if (rc && rc != -EPROBE_DEFER) {
> > > > > > +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
> > > > > > +                   thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
> > > > > > +                   emsg ? : "", ERR_PTR(rc));  
> > > > > It is open-coding dev_err_probe(). Just use dev_err_probe instead.  
> > > > dev_err_probe is supposed to be only called in probe functions, while
> > > > devm_request_threaded_irq might be called in other contexts (e.g. when a
> > > > device is opened). That's why I asked to not use dev_err_probe() in v2  
> > > True, but then all the callers of this function will forget to set
> > > deferred probe reason.  
> 
> That's another reason for letting the driver issue the error message and
> not the request_irq function.
>  
> > So let's use dev_err_probe?
> > 
> > BTW, any suggestions for names here, keep using
> > devm_request_threaded_irq_emsg or change to a new name?  
> 
> I would have called it devm_request_threaded_irq_verbose() which I
> consider easier to understand. But maybe  is just my (green)
> bikeshed.

If going to use dev_err_probe() internally maybe can just use
devm_request_threaded_irq_probe() thus reflecting that and making
it different to the devm_request_threaded_irq()?

I'm not sure we need to call out the fact it prints an error message in
the naming.  Maybe the fact it should probably only be used in probe()
is the more relevant information?

Bikesheds should all be red!

Jonathan

> 
> Best regards
> Uwe
>
Uwe Kleine-König July 5, 2023, 7:30 a.m. UTC | #8
Hello,

On Wed, Jul 05, 2023 at 10:15:37AM +0800, Jonathan Cameron wrote:
> On Tue, 4 Jul 2023 16:19:54 +0200
> Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> 
> > Hello,
> > 
> > On Tue, Jul 04, 2023 at 05:06:12PM +0800, Yangtao Li wrote:
> > > On 2023/7/4 16:48, Krzysztof Kozlowski wrote:
> > >   
> > > > [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
> > > > 
> > > > On 03/07/2023 19:43, Uwe Kleine-König wrote:  
> > > > > Hello Krzysztof,
> > > > > 
> > > > > On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:  
> > > > > > On 03/07/2023 11:04, Yangtao Li wrote:  
> > > > > > > There are more than 700 calls to the devm_request_threaded_irq method.
> > > > > > > Most drivers only request one interrupt resource, and these error
> > > > > > > messages are basically the same. If error messages are printed
> > > > > > > everywhere, more than 1000 lines of code can be saved by removing the
> > > > > > > msg in the driver.  
> > > > > > 
> > > > > > ...
> > > > > >   
> > > > > > > +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
> > > > > > > +                              irq_handler_t handler, irq_handler_t thread_fn,
> > > > > > > +                              unsigned long irqflags, const char *devname,
> > > > > > > +                              void *dev_id, const char *emsg)
> > > > > > > +{
> > > > > > > +   int rc;
> > > > > > > +
> > > > > > > +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
> > > > > > > +                                  devname, dev_id);
> > > > > > > +   if (rc && rc != -EPROBE_DEFER) {
> > > > > > > +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
> > > > > > > +                   thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
> > > > > > > +                   emsg ? : "", ERR_PTR(rc));  
> > > > > > It is open-coding dev_err_probe(). Just use dev_err_probe instead.  
> > > > > dev_err_probe is supposed to be only called in probe functions, while
> > > > > devm_request_threaded_irq might be called in other contexts (e.g. when a
> > > > > device is opened). That's why I asked to not use dev_err_probe() in v2  
> > > > True, but then all the callers of this function will forget to set
> > > > deferred probe reason.  
> > 
> > That's another reason for letting the driver issue the error message and
> > not the request_irq function.
> >  
> > > So let's use dev_err_probe?
> > > 
> > > BTW, any suggestions for names here, keep using
> > > devm_request_threaded_irq_emsg or change to a new name?  
> > 
> > I would have called it devm_request_threaded_irq_verbose() which I
> > consider easier to understand. But maybe  is just my (green)
> > bikeshed.
> 
> If going to use dev_err_probe() internally maybe can just use
> devm_request_threaded_irq_probe() thus reflecting that and making
> it different to the devm_request_threaded_irq()?

I like devm_request_threaded_irq_probe(), thanks for that suggestion
(even though it's red :-)

Best regards
Uwe
Yangtao Li July 5, 2023, 7:43 a.m. UTC | #9
On 2023/7/5 15:30, Uwe Kleine-König wrote:

> Hello,
>
> On Wed, Jul 05, 2023 at 10:15:37AM +0800, Jonathan Cameron wrote:
>> On Tue, 4 Jul 2023 16:19:54 +0200
>> Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
>>
>>> Hello,
>>>
>>> On Tue, Jul 04, 2023 at 05:06:12PM +0800, Yangtao Li wrote:
>>>> On 2023/7/4 16:48, Krzysztof Kozlowski wrote:
>>>>    
>>>>> [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
>>>>>
>>>>> On 03/07/2023 19:43, Uwe Kleine-König wrote:
>>>>>> Hello Krzysztof,
>>>>>>
>>>>>> On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:
>>>>>>> On 03/07/2023 11:04, Yangtao Li wrote:
>>>>>>>> There are more than 700 calls to the devm_request_threaded_irq method.
>>>>>>>> Most drivers only request one interrupt resource, and these error
>>>>>>>> messages are basically the same. If error messages are printed
>>>>>>>> everywhere, more than 1000 lines of code can be saved by removing the
>>>>>>>> msg in the driver.
>>>>>>> ...
>>>>>>>    
>>>>>>>> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>>>>>>>> +                              irq_handler_t handler, irq_handler_t thread_fn,
>>>>>>>> +                              unsigned long irqflags, const char *devname,
>>>>>>>> +                              void *dev_id, const char *emsg)
>>>>>>>> +{
>>>>>>>> +   int rc;
>>>>>>>> +
>>>>>>>> +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>>>>>>>> +                                  devname, dev_id);
>>>>>>>> +   if (rc && rc != -EPROBE_DEFER) {
>>>>>>>> +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
>>>>>>>> +                   thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev),
>>>>>>>> +                   emsg ? : "", ERR_PTR(rc));
>>>>>>> It is open-coding dev_err_probe(). Just use dev_err_probe instead.
>>>>>> dev_err_probe is supposed to be only called in probe functions, while
>>>>>> devm_request_threaded_irq might be called in other contexts (e.g. when a
>>>>>> device is opened). That's why I asked to not use dev_err_probe() in v2
>>>>> True, but then all the callers of this function will forget to set
>>>>> deferred probe reason.
>>> That's another reason for letting the driver issue the error message and
>>> not the request_irq function.
>>>   
>>>> So let's use dev_err_probe?
>>>>
>>>> BTW, any suggestions for names here, keep using
>>>> devm_request_threaded_irq_emsg or change to a new name?
>>> I would have called it devm_request_threaded_irq_verbose() which I
>>> consider easier to understand. But maybe  is just my (green)
>>> bikeshed.
>> If going to use dev_err_probe() internally maybe can just use
>> devm_request_threaded_irq_probe() thus reflecting that and making
>> it different to the devm_request_threaded_irq()?
> I like devm_request_threaded_irq_probe(), thanks for that suggestion
> (even though it's red :-)


devm_request_threaded_irq_probe() also sounds good to me, :-) If there 
is no objection, I think it's time to start working on switching the api.

int devm_request_threaded_irq_probe(struct device *dev, unsigned int 
irq, irq_handler_t handler, irq_handler_t thread_fn, unsigned long 
irqflags, const char *devname, void *dev_id, const char *info) { int rc; 
rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, 
devname, dev_id); if (rc) return dev_err_probe(dev, rc, "Failed to 
request %sinterrupt %u %s %s\n", thread_fn ? "threaded " : "", irq, 
devname ? : dev_name(dev), info ? : ""); return 0; } 
EXPORT_SYMBOL(devm_request_threaded_irq_probe); MBR, Yangtao


>
> Best regards
> Uwe
>
AngeloGioacchino Del Regno July 5, 2023, 10:14 a.m. UTC | #10
Il 05/07/23 09:43, Yangtao Li ha scritto:
> On 2023/7/5 15:30, Uwe Kleine-König wrote:
> 
>> Hello,
>>
>> On Wed, Jul 05, 2023 at 10:15:37AM +0800, Jonathan Cameron wrote:
>>> On Tue, 4 Jul 2023 16:19:54 +0200
>>> Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
>>>
>>>> Hello,
>>>>
>>>> On Tue, Jul 04, 2023 at 05:06:12PM +0800, Yangtao Li wrote:
>>>>> On 2023/7/4 16:48, Krzysztof Kozlowski wrote:
>>>>>> [你通常不会收到来自 krzk@kernel.org 的电子邮件。请访问 https://aka.ms 
>>>>>> /LearnAboutSenderIdentification,以了解这一点为什么很重要]
>>>>>>
>>>>>> On 03/07/2023 19:43, Uwe Kleine-König wrote:
>>>>>>> Hello Krzysztof,
>>>>>>>
>>>>>>> On Mon, Jul 03, 2023 at 02:31:59PM +0200, Krzysztof Kozlowski wrote:
>>>>>>>> On 03/07/2023 11:04, Yangtao Li wrote:
>>>>>>>>> There are more than 700 calls to the devm_request_threaded_irq method.
>>>>>>>>> Most drivers only request one interrupt resource, and these error
>>>>>>>>> messages are basically the same. If error messages are printed
>>>>>>>>> everywhere, more than 1000 lines of code can be saved by removing the
>>>>>>>>> msg in the driver.
>>>>>>>> ...
>>>>>>>>> +int devm_request_threaded_irq_emsg(struct device *dev, unsigned int irq,
>>>>>>>>> +                              irq_handler_t handler, irq_handler_t 
>>>>>>>>> thread_fn,
>>>>>>>>> +                              unsigned long irqflags, const char *devname,
>>>>>>>>> +                              void *dev_id, const char *emsg)
>>>>>>>>> +{
>>>>>>>>> +   int rc;
>>>>>>>>> +
>>>>>>>>> +   rc = devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
>>>>>>>>> +                                  devname, dev_id);
>>>>>>>>> +   if (rc && rc != -EPROBE_DEFER) {
>>>>>>>>> +           dev_err(dev, "Failed to request %sinterrupt %u %s %s: %pe\n",
>>>>>>>>> +                   thread_fn ? "threaded " : "", irq, devname ? : 
>>>>>>>>> dev_name(dev),
>>>>>>>>> +                   emsg ? : "", ERR_PTR(rc));
>>>>>>>> It is open-coding dev_err_probe(). Just use dev_err_probe instead.
>>>>>>> dev_err_probe is supposed to be only called in probe functions, while
>>>>>>> devm_request_threaded_irq might be called in other contexts (e.g. when a
>>>>>>> device is opened). That's why I asked to not use dev_err_probe() in v2
>>>>>> True, but then all the callers of this function will forget to set
>>>>>> deferred probe reason.
>>>> That's another reason for letting the driver issue the error message and
>>>> not the request_irq function.
>>>>> So let's use dev_err_probe?
>>>>>
>>>>> BTW, any suggestions for names here, keep using
>>>>> devm_request_threaded_irq_emsg or change to a new name?
>>>> I would have called it devm_request_threaded_irq_verbose() which I
>>>> consider easier to understand. But maybe  is just my (green)
>>>> bikeshed.
>>> If going to use dev_err_probe() internally maybe can just use
>>> devm_request_threaded_irq_probe() thus reflecting that and making
>>> it different to the devm_request_threaded_irq()?
>> I like devm_request_threaded_irq_probe(), thanks for that suggestion
>> (even though it's red :-)
> 
> 
> devm_request_threaded_irq_probe() also sounds good to me, :-) If there is no 
> objection, I think it's time to start working on switching the api.
> 

+1 on devm_request_threaded_irq_probe() name, makes sense to me, as it'd be
using the same error logic as dev_err_probe() (no prints if -EPROBE_DEFER),
and also.. this is a function that's anyway used in .probe() callbacks at
least in the *vast* majority of the cases.

Cheers,
Angelo

> int devm_request_threaded_irq_probe(struct device *dev, unsigned int irq, 
> irq_handler_t handler, irq_handler_t thread_fn, unsigned long irqflags, const char 
> *devname, void *dev_id, const char *info) { int rc; rc = 
> devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, devname, dev_id); if 
> (rc) return dev_err_probe(dev, rc, "Failed to request %sinterrupt %u %s %s\n", 
> thread_fn ? "threaded " : "", irq, devname ? : dev_name(dev), info ? : ""); return 
> 0; } EXPORT_SYMBOL(devm_request_threaded_irq_probe); MBR, Yangtao
> 
> 
>>
>> Best regards
>> Uwe
>>