Skip to content

Commit

Permalink
thermal/core: cooling device duplicate creation check
Browse files Browse the repository at this point in the history
Because creating a cooling device may have duplicate names.
When creating, first check thermal_cdev_list whether
there is a device with the same name. If it has the same name,
it returns a reference to the cooling device.

Signed-off-by: huangqibo <huangqibo@xiaomi.com>
  • Loading branch information
huangqibo authored and intel-lab-lkp committed Oct 26, 2022
1 parent 4bb7f6c commit b9ffa61
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions drivers/thermal/thermal_core.c
Expand Up @@ -873,6 +873,12 @@ __thermal_cooling_device_register(struct device_node *np,
!ops->set_cur_state)
return ERR_PTR(-EINVAL);

if (type)
cdev = thermal_cdev_get_zone_by_name(type);

if (!IS_ERR_OR_NULL(cdev))
return cdev;

cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
if (!cdev)
return ERR_PTR(-ENOMEM);
Expand Down Expand Up @@ -1435,6 +1441,34 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
}
EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);

struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name)
{
struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
unsigned int found = 0;

if (!name)
goto exit;

mutex_lock(&thermal_list_lock);
list_for_each_entry(pos, &thermal_cdev_list, node)
if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) {
found++;
ref = pos;
}
mutex_unlock(&thermal_list_lock);

/* nothing has been found, thus an error code for it */
if (found == 0)
ref = ERR_PTR(-ENODEV);
else if (found > 1)
/* Success only when an unique zone is found */
ref = ERR_PTR(-EEXIST);

exit:
return ref;
}
EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name);

static int thermal_pm_notify(struct notifier_block *nb,
unsigned long mode, void *_unused)
{
Expand Down

0 comments on commit b9ffa61

Please sign in to comment.