2019-07-10 11:50:18

by Amit Kucheria

[permalink] [raw]
Subject: [PATCH] thermal: Add some error messages

When registering a thermal zone device, we currently return -EINVAL in
four cases. This makes it a little hard to debug the real cause of the
failure.

Print some error messages to make it easier for developer to figure out
what happened.

Signed-off-by: Amit Kucheria <[email protected]>
---
drivers/thermal/thermal_core.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 46cfb7de4eb28..95c3a4c649cf8 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1238,17 +1238,26 @@ thermal_zone_device_register(const char *type, int trips, int mask,
int count;
struct thermal_governor *governor;

- if (!type || strlen(type) == 0)
+ if (!type || strlen(type) == 0) {
+ pr_err("Error: No thermal zone type defined");
return ERR_PTR(-EINVAL);
+ }

- if (type && strlen(type) >= THERMAL_NAME_LENGTH)
+ if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
+ pr_err("Error: Thermal zone name (%s) too long, should be under %d chars",
+ type, THERMAL_NAME_LENGTH);
return ERR_PTR(-EINVAL);
+ }

- if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
+ if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
+ pr_err("Error: Incorrect number of thermal trips");
return ERR_PTR(-EINVAL);
+ }

- if (!ops)
+ if (!ops) {
+ pr_err("Error: Thermal zone device ops not defined");
return ERR_PTR(-EINVAL);
+ }

if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
return ERR_PTR(-EINVAL);
--
2.17.1


2019-07-11 00:34:57

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] thermal: Add some error messages

On Wed, 2019-07-10 at 17:16 +0530, Amit Kucheria wrote:
> When registering a thermal zone device, we currently return -EINVAL in
> four cases. This makes it a little hard to debug the real cause of the
> failure.
>
> Print some error messages to make it easier for developer to figure out
> what happened.
[]
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
[]
> @@ -1238,17 +1238,26 @@ thermal_zone_device_register(const char *type, int trips, int mask,
> int count;
> struct thermal_governor *governor;
>
> - if (!type || strlen(type) == 0)
> + if (!type || strlen(type) == 0) {
> + pr_err("Error: No thermal zone type defined");

Please use terminating newlines like:

pr_err("Error: No thermal zone type defined\n");

[]
> + pr_err("Error: Thermal zone name (%s) too long, should be under %d chars",

etc...