2023-06-27 11:09:54

by 李扬韬

[permalink] [raw]
Subject: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

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.

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.

Signed-off-by: Yangtao Li <[email protected]>
---
kernel/irq/devres.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index f6e5515ee077..fcb946ffb7ec 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -58,8 +58,10 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,

dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
GFP_KERNEL);
- if (!dr)
+ if (!dr) {
+ dev_err(dev, "Failed to allocate device resource data\n");
return -ENOMEM;
+ }

if (!devname)
devname = dev_name(dev);
@@ -67,6 +69,7 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
dev_id);
if (rc) {
+ dev_err_probe(dev, rc, "Failed to request threaded irq%d: %d\n", irq, rc);
devres_free(dr);
return rc;
}
--
2.39.0



2023-06-27 11:51:55

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

Hello,

On Tue, Jun 27, 2023 at 06:12:01PM +0800, Yangtao Li wrote:
> 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.
>
> 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.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> kernel/irq/devres.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
> index f6e5515ee077..fcb946ffb7ec 100644
> --- a/kernel/irq/devres.c
> +++ b/kernel/irq/devres.c
> @@ -58,8 +58,10 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
>
> dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
> GFP_KERNEL);
> - if (!dr)
> + if (!dr) {
> + dev_err(dev, "Failed to allocate device resource data\n");
> return -ENOMEM;
> + }
>
> if (!devname)
> devname = dev_name(dev);
> @@ -67,6 +69,7 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
> dev_id);
> if (rc) {
> + dev_err_probe(dev, rc, "Failed to request threaded irq%d: %d\n", irq, rc);

This changes semantics because dev_err_probe() is only supposed to be
called in probe functions. Not sure about devm_request_threaded_irq, but
its friend request_irq is called in the setup_irq (or open IIRC)
callback of serial drivers.

While I assume changing to dev_err_probe is a result of my concern that
no error should be printed when rc=-EPROBEDEFER, my other concern that
adding an error message to a generic allocation function is a bad idea
still stands.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (2.22 kB)
signature.asc (499.00 B)
Download all attachments

2023-06-30 11:29:56

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

On Tue, Jun 27 2023 at 13:00, Uwe Kleine-König wrote:
> On Tue, Jun 27, 2023 at 06:12:01PM +0800, Yangtao Li wrote:
>
> While I assume changing to dev_err_probe is a result of my concern that
> no error should be printed when rc=-EPROBEDEFER, my other concern that
> adding an error message to a generic allocation function is a bad idea
> still stands.

I agree in general, but if you 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.

Yangtao: The way how this is attempted is not useful at all.

1) The changelog is word salad and provides 0 rationale

Also such series require a cover letter...

2) The dev_err() which is added is not informative at all and cannot
replace actually useful error messages. It's not that hard to
make it useful.

2) Adding the printks unconditionally first will emit two messages
with different content.

This is not how such changes are done.

The proper approach is to create a wrapper function which emits
the error message:

wrapper(....., const char *info)
{
ret = devm_request_threaded_irq(....);
if (ret < 0) {
dev_err(dev, "Failed to request %sinterrupt %u %s %s: %d\n,
thread_fn ? "threaded " : "",
irq, devname, info ? : "", ret);
}
return ret;
}

Then convert the callsites over one by one with proper
changelogs and justification.

See?

Thanks,

tglx

2023-07-03 09:30:06

by 李扬韬

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

Hi,

On 2023/6/30 19:11, Thomas Gleixner wrote:
> On Tue, Jun 27 2023 at 13:00, Uwe Kleine-König wrote:
>> On Tue, Jun 27, 2023 at 06:12:01PM +0800, Yangtao Li wrote:
>>
>> While I assume changing to dev_err_probe is a result of my concern that
>> no error should be printed when rc=-EPROBEDEFER, my other concern that
>> adding an error message to a generic allocation function is a bad idea
>> still stands.
> I agree in general, but if you 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.
>
> Yangtao: The way how this is attempted is not useful at all.
>
> 1) The changelog is word salad and provides 0 rationale
>
> Also such series require a cover letter...
>
> 2) The dev_err() which is added is not informative at all and cannot
> replace actually useful error messages. It's not that hard to
> make it useful.
>
> 2) Adding the printks unconditionally first will emit two messages
> with different content.
>
> This is not how such changes are done.
>
> The proper approach is to create a wrapper function which emits
> the error message:
>
> wrapper(....., const char *info)
> {
> ret = devm_request_threaded_irq(....);
> if (ret < 0) {
> dev_err(dev, "Failed to request %sinterrupt %u %s %s: %d\n,
> thread_fn ? "threaded " : "",
> irq, devname, info ? : "", ret);
> }
> return ret;
> }
>
> Then convert the callsites over one by one with proper
> changelogs and justification.
>
> See?


Yes, thanks a lot for the suggestion, and v3 has been sent.


MBR,

Yangtao


>
> Thanks,
>
> tglx

2023-07-03 10:04:53

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

Hello,

On Mon, Jul 03, 2023 at 05:13:29PM +0800, Yangtao Li wrote:
> [...] v3 has been sent.

Please make sure that you send a v3 patch series (at least) to the
people who gave you feedback for v2. If you skip people who had general
concerns about the whole series, this might help you in the short run
because they might miss to also criticise v3, but in the long run it
might result in a loss of trust in you.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (603.00 B)
signature.asc (499.00 B)
Download all attachments

2023-07-03 12:16:11

by 李扬韬

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

Hi Uwe,

On 2023/7/3 17:53, Uwe Kleine-König wrote:
> Hello,
>
> On Mon, Jul 03, 2023 at 05:13:29PM +0800, Yangtao Li wrote:
>> [...] v3 has been sent.
> Please make sure that you send a v3 patch series (at least) to the
> people who gave you feedback for v2. If you skip people who had general
> concerns about the whole series, this might help you in the short run
> because they might miss to also criticise v3, but in the long run it
> might result in a loss of trust in you.


Sorry, I'm a little busy. I just added you and Krzysztof Kozlowski in v3.

If others are interested in the follow-up series, please refer to the
following link:


https://lore.kernel.org/lkml/[email protected]/


Thx,

Yangtao


>
> Best regards
> Uwe
>

2023-07-03 12:29:01

by 李扬韬

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

Hi Krzysztof,

Here. V3 was modified according to tglx's suggestion, if there is any problem, please point out.

Thx,
Yangtao

2023-07-03 12:42:29

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

On 03/07/2023 13:54, Yangtao Li wrote:
> Hi Krzysztof,
>
> On 2023/6/30 19:11, Thomas Gleixner wrote:
>> On Tue, Jun 27 2023 at 13:00, Uwe Kleine-König wrote:
>>> On Tue, Jun 27, 2023 at 06:12:01PM +0800, Yangtao Li wrote:
>>>
>>> While I assume changing to dev_err_probe is a result of my concern that
>>> no error should be printed when rc=-EPROBEDEFER, my other concern that
>>> adding an error message to a generic allocation function is a bad idea
>>> still stands.
>> I agree in general, but if you 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.
>>
>> Yangtao: The way how this is attempted is not useful at all.
>>
>> 1) The changelog is word salad and provides 0 rationale
>>
>> Also such series require a cover letter...
>>
>> 2) The dev_err() which is added is not informative at all and cannot
>> replace actually useful error messages. It's not that hard to
>> make it useful.
>>
>> 2) Adding the printks unconditionally first will emit two messages
>> with different content.
>>
>> This is not how such changes are done.
>>
>> The proper approach is to create a wrapper function which emits
>> the error message:
>>
>> wrapper(....., const char *info)
>> {
>> ret = devm_request_threaded_irq(....);
>> if (ret < 0) {
>> dev_err(dev, "Failed to request %sinterrupt %u %s %s: %d\n,
>> thread_fn ? "threaded " : "",
>> irq, devname, info ? : "", ret);
>> }
>> return ret;
>> }
>
>
> Here.
>
> V3 was modified according to tglx's suggestion, if there is any problem,
> please point out.

The comment was about request_thread_irq, not about devres alloc. Don't
mix the places. Really, since when do we print any errors on ENOMEM?

Best regards,
Krzysztof


2023-07-03 16:55:01

by Ahmad Fatoum

[permalink] [raw]
Subject: Re: [PATCH v2 01/15] genirq/devres: Add error information printing for devm_request_threaded_irq()

On 27.06.23 12:12, Yangtao Li wrote:
> 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.
>
> 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.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> kernel/irq/devres.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
> index f6e5515ee077..fcb946ffb7ec 100644
> --- a/kernel/irq/devres.c
> +++ b/kernel/irq/devres.c
> @@ -58,8 +58,10 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
>
> dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
> GFP_KERNEL);
> - if (!dr)
> + if (!dr) {
> + dev_err(dev, "Failed to allocate device resource data\n");

Why not use dev_err_probe too? Could turn this block into a oneliner.

> return -ENOMEM;
> + }
>
> if (!devname)
> devname = dev_name(dev);
> @@ -67,6 +69,7 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
> dev_id);
> if (rc) {
> + dev_err_probe(dev, rc, "Failed to request threaded irq%d: %d\n", irq, rc);

No need to format rc with %d. dev_err_probe will already do this for you.

> devres_free(dr);
> return rc;
> }

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |