2023-07-10 10:23:49

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 01/21] genirq/devres: Add devm_request_threaded_irq_probe() and devm_request_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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_probe() and devm_request_irq_probe(),
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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
include/linux/interrupt.h | 15 +++++++++++++++
kernel/irq/devres.c | 40 +++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a92bce40b04b..91ab9e501b3d 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -201,6 +201,21 @@ extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);

struct device;

+extern int __must_check
+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);
+
+static inline int __must_check
+devm_request_irq_probe(struct device *dev, unsigned int irq,
+ irq_handler_t handler, unsigned long irqflags,
+ const char *devname, void *dev_id, const char *info)
+{
+ return devm_request_threaded_irq_probe(dev, irq, handler, NULL, irqflags,
+ devname, dev_id, info);
+}
+
extern int __must_check
devm_request_threaded_irq(struct device *dev, unsigned int irq,
irq_handler_t handler, irq_handler_t thread_fn,
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index f6e5515ee077..43a40d6e2e0b 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -79,6 +79,46 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
}
EXPORT_SYMBOL(devm_request_threaded_irq);

+/**
+ * devm_request_threaded_irq_probe - 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
+ * @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
+ * @info: Optional additional error log
+ *
+ * This is a variant of the devm_request_threaded_irq function.
+ * It will print an error message by default when the request fails,
+ * and the consumer can add a special error msg.
+ *
+ * Except for the extra @dev argument, this function takes the
+ * same arguments and performs the same function as
+ * request_threaded_irq(). IRQs requested with this function will be
+ * automatically freed on driver detach.
+ *
+ * If an IRQ allocated with this function needs to be freed
+ * separately, devm_free_irq() must be used.
+ */
+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);
+
/**
* devm_request_any_context_irq - allocate an interrupt line for a managed device
* @dev: device to request interrupt for
--
2.39.0



2023-07-10 10:24:56

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 18/21] thermal/drivers/qcom/tsens-v0_1: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/qcom/tsens.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 98c356acfe98..d4528d36c085 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1171,21 +1171,18 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname,
} else {
/* VER_0 interrupt is TRIGGER_RISING, VER_0_1 and up is ONESHOT */
if (tsens_version(priv) == VER_0)
- ret = devm_request_threaded_irq(&pdev->dev, irq,
- thread_fn, NULL,
- IRQF_TRIGGER_RISING,
- dev_name(&pdev->dev),
- priv);
+ ret = devm_request_threaded_irq_probe(&pdev->dev, irq,
+ thread_fn, NULL,
+ IRQF_TRIGGER_RISING,
+ dev_name(&pdev->dev),
+ priv, NULL);
else
- ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
- thread_fn, IRQF_ONESHOT,
- dev_name(&pdev->dev),
- priv);
+ ret = devm_request_threaded_irq_probe(&pdev->dev, irq, NULL,
+ thread_fn, IRQF_ONESHOT,
+ dev_name(&pdev->dev),
+ priv, NULL);

- if (ret)
- dev_err(&pdev->dev, "%s: failed to get irq\n",
- __func__);
- else
+ if (!ret)
enable_irq_wake(irq);
}

--
2.39.0


2023-07-10 10:28:57

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 19/21] thermal: qcom-spmi-adc-tm5: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
index 5ddc39b2be32..90d46dc60806 100644
--- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
+++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
@@ -1044,8 +1044,9 @@ static int adc_tm5_probe(struct platform_device *pdev)
return ret;
}

- return devm_request_threaded_irq(dev, irq, NULL, adc_tm->data->isr,
- IRQF_ONESHOT, adc_tm->data->irq_name, adc_tm);
+ return devm_request_threaded_irq_probe(dev, irq, NULL, adc_tm->data->isr,
+ IRQF_ONESHOT, adc_tm->data->irq_name,
+ adc_tm, NULL);
}

static const struct of_device_id adc_tm5_match_table[] = {
--
2.39.0


2023-07-10 10:29:13

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 14/21] thermal/drivers/mediatek/lvts_thermal: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/mediatek/lvts_thermal.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index b693fac2d677..1e12410820df 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -1148,10 +1148,10 @@ static int lvts_probe(struct platform_device *pdev)
* At this point the LVTS is initialized and enabled. We can
* safely enable the interrupt.
*/
- ret = devm_request_threaded_irq(dev, irq, NULL, lvts_irq_handler,
- IRQF_ONESHOT, dev_name(dev), lvts_td);
+ ret = devm_request_threaded_irq_probe(dev, irq, NULL, lvts_irq_handler,
+ IRQF_ONESHOT, dev_name(dev), lvts_td, NULL);
if (ret)
- return dev_err_probe(dev, ret, "Failed to request interrupt\n");
+ return ret;

platform_set_drvdata(pdev, lvts_td);

--
2.39.0


2023-07-10 10:29:41

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 06/21] thermal/drivers/db8500: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/db8500_thermal.c | 16 ++++++----------
drivers/thermal/qcom/lmh.c | 7 +++----
2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c
index fca5c2c93bf9..0ef8fc2eb4a1 100644
--- a/drivers/thermal/db8500_thermal.c
+++ b/drivers/thermal/db8500_thermal.c
@@ -164,25 +164,21 @@ static int db8500_thermal_probe(struct platform_device *pdev)
if (low_irq < 0)
return low_irq;

- ret = devm_request_threaded_irq(dev, low_irq, NULL,
+ ret = devm_request_threaded_irq_probe(dev, low_irq, NULL,
prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
- "dbx500_temp_low", th);
- if (ret < 0) {
- dev_err(dev, "failed to allocate temp low irq\n");
+ "dbx500_temp_low", th, "temp low");
+ if (ret < 0)
return ret;
- }

high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
if (high_irq < 0)
return high_irq;

- ret = devm_request_threaded_irq(dev, high_irq, NULL,
+ ret = devm_request_threaded_irq_probe(dev, high_irq, NULL,
prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
- "dbx500_temp_high", th);
- if (ret < 0) {
- dev_err(dev, "failed to allocate temp high irq\n");
+ "dbx500_temp_high", th, "temp high");
+ if (ret < 0)
return ret;
- }

/* register of thermal sensor and get info from DT */
th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c
index f6edb12ec004..48a14d7e8bf5 100644
--- a/drivers/thermal/qcom/lmh.c
+++ b/drivers/thermal/qcom/lmh.c
@@ -207,11 +207,10 @@ static int lmh_probe(struct platform_device *pdev)

/* Disable the irq and let cpufreq enable it when ready to handle the interrupt */
irq_set_status_flags(lmh_data->irq, IRQ_NOAUTOEN);
- ret = devm_request_irq(dev, lmh_data->irq, lmh_handle_irq,
- IRQF_ONESHOT | IRQF_NO_SUSPEND,
- "lmh-irq", lmh_data);
+ ret = devm_request_irq_probe(dev, lmh_data->irq, lmh_handle_irq,
+ IRQF_ONESHOT | IRQF_NO_SUSPEND,
+ "lmh-irq", lmh_data, NULL);
if (ret) {
- dev_err(dev, "Error %d registering irq %x\n", ret, lmh_data->irq);
irq_domain_remove(lmh_data->domain);
return ret;
}
--
2.39.0


2023-07-10 10:29:46

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 07/21] thermal/drivers/rcar: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/rcar_thermal.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index b8571f7090aa..56f3983dcd5f 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -446,12 +446,10 @@ static int rcar_thermal_probe(struct platform_device *pdev)
idle = 0; /* polling delay is not needed */
}

- ret = devm_request_irq(dev, irq, rcar_thermal_irq,
- IRQF_SHARED, dev_name(dev), common);
- if (ret) {
- dev_err(dev, "irq request failed\n ");
+ ret = devm_request_irq_probe(dev, irq, rcar_thermal_irq,
+ IRQF_SHARED, dev_name(dev), common, NULL);
+ if (ret)
goto error_unregister;
- }

/* update ENR bits */
if (chip->irq_per_ch)
--
2.39.0


2023-07-10 10:29:52

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 03/21] thermal/drivers/armada: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
Acked-by: Miquel Raynal <[email protected]>
---
drivers/thermal/armada_thermal.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 9f6dc4fc9112..b7f549b6f825 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -913,15 +913,12 @@ static int armada_thermal_probe(struct platform_device *pdev)

/* The overheat interrupt feature is not mandatory */
if (irq > 0) {
- ret = devm_request_threaded_irq(&pdev->dev, irq,
- armada_overheat_isr,
- armada_overheat_isr_thread,
- 0, NULL, priv);
- if (ret) {
- dev_err(&pdev->dev, "Cannot request threaded IRQ %d\n",
- irq);
+ ret = devm_request_threaded_irq_probe(&pdev->dev, irq,
+ armada_overheat_isr,
+ armada_overheat_isr_thread,
+ 0, NULL, priv, NULL);
+ if (ret)
return ret;
- }
}

/*
--
2.39.0


2023-07-10 10:30:23

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 12/21] thermal/drivers/rockchip: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/rockchip_thermal.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index 77231a9d28ff..11061f6ef323 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -1577,13 +1577,12 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
"failed to register sensor[%d].\n", i);
}

- error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
- &rockchip_thermal_alarm_irq_thread,
- IRQF_ONESHOT,
- "rockchip_thermal", thermal);
+ error = devm_request_threaded_irq_probe(&pdev->dev, irq, NULL,
+ &rockchip_thermal_alarm_irq_thread,
+ IRQF_ONESHOT,
+ "rockchip_thermal", thermal, "tsadc");
if (error)
- return dev_err_probe(&pdev->dev, error,
- "failed to request tsadc irq.\n");
+ return error;

thermal->chip->control(thermal->regs, true);

--
2.39.0


2023-07-10 10:30:26

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 08/21] thermal/drivers/qcom/temp-alarm: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
index 0e8ebfcd84c5..1b4a7eca181e 100644
--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
+++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
@@ -455,8 +455,8 @@ static int qpnp_tm_probe(struct platform_device *pdev)

devm_thermal_add_hwmon_sysfs(&pdev->dev, chip->tz_dev);

- ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr,
- IRQF_ONESHOT, node->name, chip);
+ ret = devm_request_threaded_irq_probe(&pdev->dev, irq, NULL, qpnp_tm_isr,
+ IRQF_ONESHOT, node->name, chip, NULL);
if (ret < 0)
return ret;

--
2.39.0


2023-07-10 10:43:23

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 04/21] thermal/drivers/broadcom: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/broadcom/brcmstb_thermal.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
index 72d1dbe60b8f..ea37e7ee688a 100644
--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -349,14 +349,12 @@ static int brcmstb_thermal_probe(struct platform_device *pdev)

irq = platform_get_irq_optional(pdev, 0);
if (irq >= 0) {
- ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
- brcmstb_tmon_irq_thread,
- IRQF_ONESHOT,
- DRV_NAME, priv);
- if (ret < 0) {
- dev_err(&pdev->dev, "could not request IRQ: %d\n", ret);
+ ret = devm_request_threaded_irq_probe(&pdev->dev, irq, NULL,
+ brcmstb_tmon_irq_thread,
+ IRQF_ONESHOT,
+ DRV_NAME, priv, NULL);
+ if (ret < 0)
return ret;
- }
}

dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n");
--
2.39.0


2023-07-10 10:56:45

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 11/21] thermal/drivers/hisi: convert to use devm_request*_irq_probe()

There are more than 700 calls to devm_request_threaded_irq method and
more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.

Cc: Thomas Gleixner <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/hisi_thermal.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 3f09ef8be41a..ee5f50fb2b68 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -576,14 +576,12 @@ static int hisi_thermal_probe(struct platform_device *pdev)
if (ret < 0)
return ret;

- ret = devm_request_threaded_irq(dev, ret, NULL,
- hisi_thermal_alarm_irq_thread,
- IRQF_ONESHOT, sensor->irq_name,
- sensor);
- if (ret < 0) {
- dev_err(dev, "Failed to request alarm irq: %d\n", ret);
+ ret = devm_request_threaded_irq_probe(dev, ret, NULL,
+ hisi_thermal_alarm_irq_thread,
+ IRQF_ONESHOT, sensor->irq_name,
+ sensor, "alarm");
+ if (ret < 0)
return ret;
- }

ret = data->ops->enable_sensor(sensor);
if (ret) {
--
2.39.0


2023-07-10 11:27:46

by Heiko Stuebner

[permalink] [raw]
Subject: Re: [PATCH v4 12/21] thermal/drivers/rockchip: convert to use devm_request*_irq_probe()

Am Montag, 10. Juli 2023, 11:59:16 CEST schrieb Yangtao Li:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-K?nig" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>

Acked-by: Heiko Stuebner <[email protected]>



2023-07-10 11:45:07

by Dmitry Baryshkov

[permalink] [raw]
Subject: Re: [PATCH v4 08/21] thermal/drivers/qcom/temp-alarm: convert to use devm_request*_irq_probe()

On 10/07/2023 12:59, Yangtao Li wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Dmitry Baryshkov <[email protected]>

--
With best wishes
Dmitry


2023-07-10 11:51:10

by Dmitry Baryshkov

[permalink] [raw]
Subject: Re: [PATCH v4 18/21] thermal/drivers/qcom/tsens-v0_1: convert to use devm_request*_irq_probe()

On 10/07/2023 12:59, Yangtao Li wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/thermal/qcom/tsens.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)

Reviewed-by: Dmitry Baryshkov <[email protected]>

--
With best wishes
Dmitry


2023-07-10 11:51:33

by Dmitry Baryshkov

[permalink] [raw]
Subject: Re: [PATCH v4 19/21] thermal: qcom-spmi-adc-tm5: convert to use devm_request*_irq_probe()

On 10/07/2023 12:59, Yangtao Li wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Dmitry Baryshkov <[email protected]>

--
With best wishes
Dmitry


2023-07-10 11:56:10

by Dmitry Baryshkov

[permalink] [raw]
Subject: Re: [PATCH v4 06/21] thermal/drivers/db8500: convert to use devm_request*_irq_probe()

On 10/07/2023 12:59, Yangtao Li wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/thermal/db8500_thermal.c | 16 ++++++----------
> drivers/thermal/qcom/lmh.c | 7 +++----

Please split LMH to a separate driver.

> 2 files changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c
> index fca5c2c93bf9..0ef8fc2eb4a1 100644
> --- a/drivers/thermal/db8500_thermal.c
> +++ b/drivers/thermal/db8500_thermal.c
> @@ -164,25 +164,21 @@ static int db8500_thermal_probe(struct platform_device *pdev)
> if (low_irq < 0)
> return low_irq;
>
> - ret = devm_request_threaded_irq(dev, low_irq, NULL,
> + ret = devm_request_threaded_irq_probe(dev, low_irq, NULL,
> prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
> - "dbx500_temp_low", th);
> - if (ret < 0) {
> - dev_err(dev, "failed to allocate temp low irq\n");
> + "dbx500_temp_low", th, "temp low");
> + if (ret < 0)
> return ret;
> - }
>
> high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
> if (high_irq < 0)
> return high_irq;
>
> - ret = devm_request_threaded_irq(dev, high_irq, NULL,
> + ret = devm_request_threaded_irq_probe(dev, high_irq, NULL,
> prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
> - "dbx500_temp_high", th);
> - if (ret < 0) {
> - dev_err(dev, "failed to allocate temp high irq\n");
> + "dbx500_temp_high", th, "temp high");
> + if (ret < 0)
> return ret;
> - }
>
> /* register of thermal sensor and get info from DT */
> th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
> diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c
> index f6edb12ec004..48a14d7e8bf5 100644
> --- a/drivers/thermal/qcom/lmh.c
> +++ b/drivers/thermal/qcom/lmh.c
> @@ -207,11 +207,10 @@ static int lmh_probe(struct platform_device *pdev)
>
> /* Disable the irq and let cpufreq enable it when ready to handle the interrupt */
> irq_set_status_flags(lmh_data->irq, IRQ_NOAUTOEN);
> - ret = devm_request_irq(dev, lmh_data->irq, lmh_handle_irq,
> - IRQF_ONESHOT | IRQF_NO_SUSPEND,
> - "lmh-irq", lmh_data);
> + ret = devm_request_irq_probe(dev, lmh_data->irq, lmh_handle_irq,
> + IRQF_ONESHOT | IRQF_NO_SUSPEND,
> + "lmh-irq", lmh_data, NULL);
> if (ret) {
> - dev_err(dev, "Error %d registering irq %x\n", ret, lmh_data->irq);
> irq_domain_remove(lmh_data->domain);
> return ret;
> }

--
With best wishes
Dmitry


2023-07-10 11:58:22

by Dmitry Baryshkov

[permalink] [raw]
Subject: Re: [PATCH v4 06/21] thermal/drivers/db8500: convert to use devm_request*_irq_probe()

On Mon, 10 Jul 2023 at 14:30, Yangtao Li <[email protected]> wrote:
>
> Hi Dmitry,
>
> On 2023/7/10 19:25, Dmitry Baryshkov wrote:
>
> > On 10/07/2023 12:59, Yangtao Li wrote:
> >> There are more than 700 calls to devm_request_threaded_irq method and
> >> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
> >>
> >> Cc: Thomas Gleixner <[email protected]>
> >> Cc: Krzysztof Kozlowski <[email protected]>
> >> Cc: "Uwe Kleine-König" <[email protected]>
> >> Cc: Jonathan Cameron <[email protected]>
> >> Cc: AngeloGioacchino Del Regno <[email protected]>
> >> Signed-off-by: Yangtao Li <[email protected]>
> >> ---
> >> drivers/thermal/db8500_thermal.c | 16 ++++++----------
> >> drivers/thermal/qcom/lmh.c | 7 +++----
> >
> > Please split LMH to a separate driver.
>
>
> Sorry for mixing these two patches together,
>
> can I add your Reviewed-by tag when the patch is resubmitted for the
> next version?

Yes, please add it to the LMH patch.

>
>
> Thx,
>
> Yangtao
>
> >
> >> 2 files changed, 9 insertions(+), 14 deletions(-)
> >>
> >> diff --git a/drivers/thermal/db8500_thermal.c
> >> b/drivers/thermal/db8500_thermal.c
> >> index fca5c2c93bf9..0ef8fc2eb4a1 100644
> >> --- a/drivers/thermal/db8500_thermal.c
> >> +++ b/drivers/thermal/db8500_thermal.c
> >> @@ -164,25 +164,21 @@ static int db8500_thermal_probe(struct
> >> platform_device *pdev)
> >> if (low_irq < 0)
> >> return low_irq;
> >> - ret = devm_request_threaded_irq(dev, low_irq, NULL,
> >> + ret = devm_request_threaded_irq_probe(dev, low_irq, NULL,
> >> prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
> >> - "dbx500_temp_low", th);
> >> - if (ret < 0) {
> >> - dev_err(dev, "failed to allocate temp low irq\n");
> >> + "dbx500_temp_low", th, "temp low");
> >> + if (ret < 0)
> >> return ret;
> >> - }
> >> high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
> >> if (high_irq < 0)
> >> return high_irq;
> >> - ret = devm_request_threaded_irq(dev, high_irq, NULL,
> >> + ret = devm_request_threaded_irq_probe(dev, high_irq, NULL,
> >> prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
> >> - "dbx500_temp_high", th);
> >> - if (ret < 0) {
> >> - dev_err(dev, "failed to allocate temp high irq\n");
> >> + "dbx500_temp_high", th, "temp high");
> >> + if (ret < 0)
> >> return ret;
> >> - }
> >> /* register of thermal sensor and get info from DT */
> >> th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
> >> diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c
> >> index f6edb12ec004..48a14d7e8bf5 100644
> >> --- a/drivers/thermal/qcom/lmh.c
> >> +++ b/drivers/thermal/qcom/lmh.c
> >> @@ -207,11 +207,10 @@ static int lmh_probe(struct platform_device *pdev)
> >> /* Disable the irq and let cpufreq enable it when ready to
> >> handle the interrupt */
> >> irq_set_status_flags(lmh_data->irq, IRQ_NOAUTOEN);
> >> - ret = devm_request_irq(dev, lmh_data->irq, lmh_handle_irq,
> >> - IRQF_ONESHOT | IRQF_NO_SUSPEND,
> >> - "lmh-irq", lmh_data);
> >> + ret = devm_request_irq_probe(dev, lmh_data->irq, lmh_handle_irq,
> >> + IRQF_ONESHOT | IRQF_NO_SUSPEND,
> >> + "lmh-irq", lmh_data, NULL);
> >> if (ret) {
> >> - dev_err(dev, "Error %d registering irq %x\n", ret,
> >> lmh_data->irq);
> >> irq_domain_remove(lmh_data->domain);
> >> return ret;
> >> }
> >



--
With best wishes
Dmitry

2023-07-10 12:10:23

by 李扬韬

[permalink] [raw]
Subject: Re: [PATCH v4 06/21] thermal/drivers/db8500: convert to use devm_request*_irq_probe()

Hi Dmitry,

On 2023/7/10 19:25, Dmitry Baryshkov wrote:

> On 10/07/2023 12:59, Yangtao Li wrote:
>> There are more than 700 calls to devm_request_threaded_irq method and
>> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>>
>> Cc: Thomas Gleixner <[email protected]>
>> Cc: Krzysztof Kozlowski <[email protected]>
>> Cc: "Uwe Kleine-König" <[email protected]>
>> Cc: Jonathan Cameron <[email protected]>
>> Cc: AngeloGioacchino Del Regno <[email protected]>
>> Signed-off-by: Yangtao Li <[email protected]>
>> ---
>>   drivers/thermal/db8500_thermal.c | 16 ++++++----------
>>   drivers/thermal/qcom/lmh.c       |  7 +++----
>
> Please split LMH to a separate driver.


Sorry for mixing these two patches together,

can I add your Reviewed-by tag when the patch is resubmitted for the
next version?


Thx,

Yangtao

>
>>   2 files changed, 9 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/thermal/db8500_thermal.c
>> b/drivers/thermal/db8500_thermal.c
>> index fca5c2c93bf9..0ef8fc2eb4a1 100644
>> --- a/drivers/thermal/db8500_thermal.c
>> +++ b/drivers/thermal/db8500_thermal.c
>> @@ -164,25 +164,21 @@ static int db8500_thermal_probe(struct
>> platform_device *pdev)
>>       if (low_irq < 0)
>>           return low_irq;
>>   -    ret = devm_request_threaded_irq(dev, low_irq, NULL,
>> +    ret = devm_request_threaded_irq_probe(dev, low_irq, NULL,
>>           prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
>> -        "dbx500_temp_low", th);
>> -    if (ret < 0) {
>> -        dev_err(dev, "failed to allocate temp low irq\n");
>> +        "dbx500_temp_low", th, "temp low");
>> +    if (ret < 0)
>>           return ret;
>> -    }
>>         high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
>>       if (high_irq < 0)
>>           return high_irq;
>>   -    ret = devm_request_threaded_irq(dev, high_irq, NULL,
>> +    ret = devm_request_threaded_irq_probe(dev, high_irq, NULL,
>>           prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
>> -        "dbx500_temp_high", th);
>> -    if (ret < 0) {
>> -        dev_err(dev, "failed to allocate temp high irq\n");
>> +        "dbx500_temp_high", th, "temp high");
>> +    if (ret < 0)
>>           return ret;
>> -    }
>>         /* register of thermal sensor and get info from DT */
>>       th->tz = devm_thermal_of_zone_register(dev, 0, th, &thdev_ops);
>> diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c
>> index f6edb12ec004..48a14d7e8bf5 100644
>> --- a/drivers/thermal/qcom/lmh.c
>> +++ b/drivers/thermal/qcom/lmh.c
>> @@ -207,11 +207,10 @@ static int lmh_probe(struct platform_device *pdev)
>>         /* Disable the irq and let cpufreq enable it when ready to
>> handle the interrupt */
>>       irq_set_status_flags(lmh_data->irq, IRQ_NOAUTOEN);
>> -    ret = devm_request_irq(dev, lmh_data->irq, lmh_handle_irq,
>> -                   IRQF_ONESHOT | IRQF_NO_SUSPEND,
>> -                   "lmh-irq", lmh_data);
>> +    ret = devm_request_irq_probe(dev, lmh_data->irq, lmh_handle_irq,
>> +                     IRQF_ONESHOT | IRQF_NO_SUSPEND,
>> +                     "lmh-irq", lmh_data, NULL);
>>       if (ret) {
>> -        dev_err(dev, "Error %d registering irq %x\n", ret,
>> lmh_data->irq);
>>           irq_domain_remove(lmh_data->domain);
>>           return ret;
>>       }
>

2023-07-10 12:29:18

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v4 01/21] genirq/devres: Add devm_request_threaded_irq_probe() and devm_request_irq_probe()

Hi Yangtao,

On Mon, Jul 10, 2023 at 12:05 PM Yangtao Li <[email protected]> wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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_probe() and devm_request_irq_probe(),
> 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>

Thanks for your patch!

> --- a/include/linux/interrupt.h
> +++ b/include/linux/interrupt.h
> @@ -201,6 +201,21 @@ extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);
>
> struct device;
>
> +extern int __must_check
> +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);
> +
> +static inline int __must_check
> +devm_request_irq_probe(struct device *dev, unsigned int irq,
> + irq_handler_t handler, unsigned long irqflags,
> + const char *devname, void *dev_id, const char *info)
> +{
> + return devm_request_threaded_irq_probe(dev, irq, handler, NULL, irqflags,
> + devname, dev_id, info);
> +}
> +
> extern int __must_check
> devm_request_threaded_irq(struct device *dev, unsigned int irq,
> irq_handler_t handler, irq_handler_t thread_fn,
> diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
> index f6e5515ee077..43a40d6e2e0b 100644
> --- a/kernel/irq/devres.c
> +++ b/kernel/irq/devres.c
> @@ -79,6 +79,46 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> }
> EXPORT_SYMBOL(devm_request_threaded_irq);
>
> +/**
> + * devm_request_threaded_irq_probe - 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
> + * @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
> + * @info: Optional additional error log
> + *
> + * This is a variant of the devm_request_threaded_irq function.
> + * It will print an error message by default when the request fails,
> + * and the consumer can add a special error msg.
> + *
> + * Except for the extra @dev argument, this function takes the

... extra @dev and @info arguments, ...

> + * same arguments and performs the same function as
> + * request_threaded_irq(). IRQs requested with this function will be

But probably you want to compare with devm_request_threaded_irq()
instead of with request_threaded_irq()?
I.e. "... extra @info argument..." above.

> + * automatically freed on driver detach.
> + *
> + * If an IRQ allocated with this function needs to be freed
> + * separately, devm_free_irq() must be used.
> + */
> +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);
> +
> /**
> * devm_request_any_context_irq - allocate an interrupt line for a managed device
> * @dev: device to request interrupt for

With the above fixed:
Reviewed-by: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-07-10 12:38:19

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v4 07/21] thermal/drivers/rcar: convert to use devm_request*_irq_probe()

On Mon, Jul 10, 2023 at 12:07 PM Yangtao Li <[email protected]> wrote:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>

Reviewed-by: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-07-10 13:02:31

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v4 01/21] genirq/devres: Add devm_request_threaded_irq_probe() and devm_request_irq_probe()

On Mon, 10 Jul 2023 14:25:24 +0200
Geert Uytterhoeven <[email protected]> wrote:

> Hi Yangtao,
>
> On Mon, Jul 10, 2023 at 12:05 PM Yangtao Li <[email protected]> wrote:
> > There are more than 700 calls to devm_request_threaded_irq method and
> > more than 1000 calls to devm_request_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 2000 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_probe() and devm_request_irq_probe(),
> > 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.
> >
> > Cc: Thomas Gleixner <[email protected]>
> > Cc: Krzysztof Kozlowski <[email protected]>
> > Cc: "Uwe Kleine-König" <[email protected]>
> > Cc: Jonathan Cameron <[email protected]>
> > Cc: AngeloGioacchino Del Regno <[email protected]>
> > Signed-off-by: Yangtao Li <[email protected]>
>
> Thanks for your patch!
>
> > --- a/include/linux/interrupt.h
> > +++ b/include/linux/interrupt.h
> > @@ -201,6 +201,21 @@ extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);
> >
> > struct device;
> >
> > +extern int __must_check
> > +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);
> > +
> > +static inline int __must_check
> > +devm_request_irq_probe(struct device *dev, unsigned int irq,
> > + irq_handler_t handler, unsigned long irqflags,
> > + const char *devname, void *dev_id, const char *info)
> > +{
> > + return devm_request_threaded_irq_probe(dev, irq, handler, NULL, irqflags,
> > + devname, dev_id, info);
> > +}
> > +
> > extern int __must_check
> > devm_request_threaded_irq(struct device *dev, unsigned int irq,
> > irq_handler_t handler, irq_handler_t thread_fn,
> > diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
> > index f6e5515ee077..43a40d6e2e0b 100644
> > --- a/kernel/irq/devres.c
> > +++ b/kernel/irq/devres.c
> > @@ -79,6 +79,46 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
> > }
> > EXPORT_SYMBOL(devm_request_threaded_irq);
> >
> > +/**
> > + * devm_request_threaded_irq_probe - allocate an interrupt line for a managed device
It's awkward for the short description to be identical to devm_request_threaded_irq
but I can't think of a sensible and short way to differentiate it.

> > + * @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
> > + * @info: Optional additional error log
> > + *
> > + * This is a variant of the devm_request_threaded_irq function.
> > + * It will print an error message by default when the request fails,
> > + * and the consumer can add a special error msg.
> > + *
> > + * Except for the extra @dev argument, this function takes the
>
> ... extra @dev and @info arguments, ...
>
> > + * same arguments and performs the same function as
> > + * request_threaded_irq(). IRQs requested with this function will be
>
> But probably you want to compare with devm_request_threaded_irq()
> instead of with request_threaded_irq()?
> I.e. "... extra @info argument..." above.
>
> > + * automatically freed on driver detach.
> > + *
> > + * If an IRQ allocated with this function needs to be freed
> > + * separately, devm_free_irq() must be used.
> > + */
> > +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);
> > +
> > /**
> > * devm_request_any_context_irq - allocate an interrupt line for a managed device
> > * @dev: device to request interrupt for
>
> With the above fixed:
> Reviewed-by: Geert Uytterhoeven <[email protected]>

Likewise, lgtm
Reviewed-by: Jonathan Cameron <[email protected]>

I'd aim to get this upstream in one cycle with a few example drover changes
but if you plan to do mass changes, leave them for the following cycle to
make it really easy for maintainers to pick them up.

Jonathan


>
> Gr{oetje,eeting}s,
>
> Geert
>


Subject: Re: [PATCH v4 14/21] thermal/drivers/mediatek/lvts_thermal: convert to use devm_request*_irq_probe()

Il 10/07/23 11:59, Yangtao Li ha scritto:
> There are more than 700 calls to devm_request_threaded_irq method and
> more than 1000 calls to devm_request_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 2000 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 convert to use devm_request*_irq_probe() API, 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.
>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: "Uwe Kleine-König" <[email protected]>
> Cc: Jonathan Cameron <[email protected]>
> Cc: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>