2023-06-13 10:17:20

by 李扬韬

[permalink] [raw]
Subject: [RESEND 1/9] thermal/hwmon: Add error information printing for devm_thermal_add_hwmon_sysfs()

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.

Signed-off-by: Yangtao Li <[email protected]>
---
Resend patchset so that the changes to thermal/hwmon.c are copied to everyone.
drivers/thermal/thermal_hwmon.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index fbe55509e307..a580add5a2f6 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -271,11 +271,14 @@ int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device

ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
GFP_KERNEL);
- if (!ptr)
+ if (!ptr) {
+ dev_err(dev, "Failed to allocate device resource data\n");
return -ENOMEM;
+ }

ret = thermal_add_hwmon_sysfs(tz);
if (ret) {
+ dev_err(dev, "Failed to add hwmon sysfs attributes\n");
devres_free(ptr);
return ret;
}
--
2.39.0



2023-06-13 10:17:43

by 李扬韬

[permalink] [raw]
Subject: [RESEND 7/9] thermal/drivers/qoriq: remove redundant msg in qoriq_tmu_register_tmu_zone()

The upper-layer devm_thermal_add_hwmon_sysfs() function can directly
print error information.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/qoriq_thermal.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index e58756323457..61b68034a82e 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -157,10 +157,7 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
return ret;
}

- if (devm_thermal_add_hwmon_sysfs(dev, tzd))
- dev_warn(dev,
- "Failed to add hwmon sysfs attributes\n");
-
+ devm_thermal_add_hwmon_sysfs(dev, tzd);
}

return 0;
--
2.39.0


2023-06-13 10:18:35

by 李扬韬

[permalink] [raw]
Subject: [RESEND 6/9] thermal/drivers/tegra: remove redundant msg in tegra_tsensor_register_channel()

The upper-layer devm_thermal_add_hwmon_sysfs() function can directly
print error information.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/thermal/tegra/tegra30-tsensor.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c
index cb584a5735ed..c243e9d76d3c 100644
--- a/drivers/thermal/tegra/tegra30-tsensor.c
+++ b/drivers/thermal/tegra/tegra30-tsensor.c
@@ -523,8 +523,7 @@ static int tegra_tsensor_register_channel(struct tegra_tsensor *ts,
return 0;
}

- if (devm_thermal_add_hwmon_sysfs(ts->dev, tsc->tzd))
- dev_warn(ts->dev, "failed to add hwmon sysfs attributes\n");
+ devm_thermal_add_hwmon_sysfs(ts->dev, tsc->tzd);

return 0;
}
--
2.39.0


2023-06-13 10:29:11

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [RESEND 1/9] thermal/hwmon: Add error information printing for devm_thermal_add_hwmon_sysfs()

On 13/06/2023 11:56, 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.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> Resend patchset so that the changes to thermal/hwmon.c are copied to everyone.
> drivers/thermal/thermal_hwmon.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
> index fbe55509e307..a580add5a2f6 100644
> --- a/drivers/thermal/thermal_hwmon.c
> +++ b/drivers/thermal/thermal_hwmon.c
> @@ -271,11 +271,14 @@ int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device
>
> ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
> GFP_KERNEL);
> - if (!ptr)
> + if (!ptr) {
> + dev_err(dev, "Failed to allocate device resource data\n");
> return -ENOMEM;
> + }
>
> ret = thermal_add_hwmon_sysfs(tz);
> if (ret) {
> + dev_err(dev, "Failed to add hwmon sysfs attributes\n");
> devres_free(ptr);
> return ret;
> }

Sorry, I commented to quickly this patch. Please discard my last
comment. I think it is a good improvement.

Can you replace the dev_err to dev_warn ?

Thanks

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-06-13 10:33:42

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [RESEND 1/9] thermal/hwmon: Add error information printing for devm_thermal_add_hwmon_sysfs()

On 13/06/2023 11:56, 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.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> Resend patchset so that the changes to thermal/hwmon.c are copied to everyone.
> drivers/thermal/thermal_hwmon.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
> index fbe55509e307..a580add5a2f6 100644
> --- a/drivers/thermal/thermal_hwmon.c
> +++ b/drivers/thermal/thermal_hwmon.c
> @@ -271,11 +271,14 @@ int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device
>
> ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
> GFP_KERNEL);
> - if (!ptr)
> + if (!ptr) {
> + dev_err(dev, "Failed to allocate device resource data\n");
> return -ENOMEM;
> + }

When an allocation fails, there is a callstack showed. It is not
necessary to print an error in this case.

>
> ret = thermal_add_hwmon_sysfs(tz);
> if (ret) {
> + dev_err(dev, "Failed to add hwmon sysfs attributes\n");
> devres_free(ptr);
> return ret;
> }

That should not display an error. The call site will take care of that.

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-06-13 12:34:02

by 李扬韬

[permalink] [raw]
Subject: Re: [RESEND 1/9] thermal/hwmon: Add error information printing for devm_thermal_add_hwmon_sysfs()

On 2023/6/13 18:20, Daniel Lezcano wrote:

> On 13/06/2023 11:56, 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.
>>
>> Signed-off-by: Yangtao Li <[email protected]>
>> ---
>> Resend patchset so that the changes to thermal/hwmon.c are copied to
>> everyone.
>>   drivers/thermal/thermal_hwmon.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/thermal/thermal_hwmon.c
>> b/drivers/thermal/thermal_hwmon.c
>> index fbe55509e307..a580add5a2f6 100644
>> --- a/drivers/thermal/thermal_hwmon.c
>> +++ b/drivers/thermal/thermal_hwmon.c
>> @@ -271,11 +271,14 @@ int devm_thermal_add_hwmon_sysfs(struct device
>> *dev, struct thermal_zone_device
>>         ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr),
>>                  GFP_KERNEL);
>> -    if (!ptr)
>> +    if (!ptr) {
>> +        dev_err(dev, "Failed to allocate device resource data\n");
>>           return -ENOMEM;
>> +    }
>>         ret = thermal_add_hwmon_sysfs(tz);
>>       if (ret) {
>> +        dev_err(dev, "Failed to add hwmon sysfs attributes\n");
>>           devres_free(ptr);
>>           return ret;
>>       }
>
> Sorry, I commented to quickly this patch. Please discard my last
> comment. I think it is a good improvement.
>
> Can you replace the dev_err to dev_warn ?

Based on the thermal/tuxsuite branch of daniel.lezcano/linux.git, patch
v3 was sent.

Included [1] for cleanup thermal-generic-adc.

[1]
https://patchwork.kernel.org/project/linux-pm/patch/[email protected]/


Thx,

Yangtao


> Thanks
>