Commit 54fa38cc authored by Eduardo Valentin's avatar Eduardo Valentin Committed by Zhang Rui

thermal: core: prevent zones with no types to be registered

There are APIs that rely on tz->type. This patch
prevent thermal zones without it to be registered.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
parent 23400ac9
...@@ -1873,6 +1873,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, ...@@ -1873,6 +1873,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
int passive = 0; int passive = 0;
struct thermal_governor *governor; struct thermal_governor *governor;
if (!type || strlen(type) == 0)
return ERR_PTR(-EINVAL);
if (type && strlen(type) >= THERMAL_NAME_LENGTH) if (type && strlen(type) >= THERMAL_NAME_LENGTH)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -1898,7 +1901,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, ...@@ -1898,7 +1901,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
return ERR_PTR(result); return ERR_PTR(result);
} }
strlcpy(tz->type, type ? : "", sizeof(tz->type)); strlcpy(tz->type, type, sizeof(tz->type));
tz->ops = ops; tz->ops = ops;
tz->tzp = tzp; tz->tzp = tzp;
tz->device.class = &thermal_class; tz->device.class = &thermal_class;
...@@ -1918,11 +1921,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, ...@@ -1918,11 +1921,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
} }
/* sys I/F */ /* sys I/F */
if (type) {
result = device_create_file(&tz->device, &dev_attr_type); result = device_create_file(&tz->device, &dev_attr_type);
if (result) if (result)
goto unregister; goto unregister;
}
result = device_create_file(&tz->device, &dev_attr_temp); result = device_create_file(&tz->device, &dev_attr_temp);
if (result) if (result)
...@@ -2071,7 +2072,6 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) ...@@ -2071,7 +2072,6 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
thermal_zone_device_set_polling(tz, 0); thermal_zone_device_set_polling(tz, 0);
if (tz->type[0])
device_remove_file(&tz->device, &dev_attr_type); device_remove_file(&tz->device, &dev_attr_type);
device_remove_file(&tz->device, &dev_attr_temp); device_remove_file(&tz->device, &dev_attr_temp);
if (tz->ops->get_mode) if (tz->ops->get_mode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment