aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-08-08 01:36:45 -0400
committerZhang Rui <rui.zhang@intel.com>2012-09-24 02:44:38 -0400
commit204dd1d39c32f39a95bf7a7248f63b372fd137a6 (patch)
treead10d76c086ea993121e959aced2370c6b704f8d /drivers/thermal
parent1e426ffddf2f158367eb6c7b8eb563c814a43283 (diff)
thermal: Fix potential NULL pointer accesses
The type parameter in thermal_zone_device_register and thermal_cooling_device_register can be NULL, indicating that no sysfs attribute for the type should be created. Only call strlen() and strcpy() on type if it is not NULL. This patch addresses Coverity #102180 and #102182: Dereference before null check Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_sys.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 36e6f4d4ec3..47498b87190 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -901,7 +901,7 @@ thermal_cooling_device_register(char *type, void *devdata,
901 struct thermal_zone_device *pos; 901 struct thermal_zone_device *pos;
902 int result; 902 int result;
903 903
904 if (strlen(type) >= THERMAL_NAME_LENGTH) 904 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
905 return ERR_PTR(-EINVAL); 905 return ERR_PTR(-EINVAL);
906 906
907 if (!ops || !ops->get_max_state || !ops->get_cur_state || 907 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
@@ -918,7 +918,7 @@ thermal_cooling_device_register(char *type, void *devdata,
918 return ERR_PTR(result); 918 return ERR_PTR(result);
919 } 919 }
920 920
921 strcpy(cdev->type, type); 921 strcpy(cdev->type, type ? : "");
922 mutex_init(&cdev->lock); 922 mutex_init(&cdev->lock);
923 INIT_LIST_HEAD(&cdev->thermal_instances); 923 INIT_LIST_HEAD(&cdev->thermal_instances);
924 cdev->ops = ops; 924 cdev->ops = ops;
@@ -1344,7 +1344,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1344 int count; 1344 int count;
1345 int passive = 0; 1345 int passive = 0;
1346 1346
1347 if (strlen(type) >= THERMAL_NAME_LENGTH) 1347 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1348 return ERR_PTR(-EINVAL); 1348 return ERR_PTR(-EINVAL);
1349 1349
1350 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) 1350 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
@@ -1366,7 +1366,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1366 return ERR_PTR(result); 1366 return ERR_PTR(result);
1367 } 1367 }
1368 1368
1369 strcpy(tz->type, type); 1369 strcpy(tz->type, type ? : "");
1370 tz->ops = ops; 1370 tz->ops = ops;
1371 tz->device.class = &thermal_class; 1371 tz->device.class = &thermal_class;
1372 tz->devdata = devdata; 1372 tz->devdata = devdata;