linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: Make sysfs attributes of cooling devices default attributes
@ 2015-02-21  2:10 Matthias Kaehlcke
  2015-03-05  5:56 ` Eduardo Valentin
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Kaehlcke @ 2015-02-21  2:10 UTC (permalink / raw)
  To: linux-pm; +Cc: Zhang Rui, Eduardo Valentin, Matthias Kaehlcke

Default attributes are created when the device is registered. Attributes
created after device registration can lead to race conditions, where user space
(e.g. udev) sees the device but not the attributes.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/thermal/thermal_core.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 48491d1..174d3bc 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -899,6 +899,22 @@ thermal_cooling_device_trip_point_show(struct device *dev,
 		return sprintf(buf, "%d\n", instance->trip);
 }
 
+static struct attribute *cooling_device_attrs[] = {
+	&dev_attr_cdev_type.attr,
+	&dev_attr_max_state.attr,
+	&dev_attr_cur_state.attr,
+	NULL,
+};
+
+static const struct attribute_group cooling_device_attr_group = {
+	.attrs = cooling_device_attrs,
+};
+
+static const struct attribute_group *cooling_device_attr_groups[] = {
+	&cooling_device_attr_group,
+	NULL,
+};
+
 /* Device management */
 
 /**
@@ -1130,6 +1146,7 @@ __thermal_cooling_device_register(struct device_node *np,
 	cdev->ops = ops;
 	cdev->updated = false;
 	cdev->device.class = &thermal_class;
+	cdev->device.groups = cooling_device_attr_groups;
 	cdev->devdata = devdata;
 	dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
 	result = device_register(&cdev->device);
@@ -1139,21 +1156,6 @@ __thermal_cooling_device_register(struct device_node *np,
 		return ERR_PTR(result);
 	}
 
-	/* sys I/F */
-	if (type) {
-		result = device_create_file(&cdev->device, &dev_attr_cdev_type);
-		if (result)
-			goto unregister;
-	}
-
-	result = device_create_file(&cdev->device, &dev_attr_max_state);
-	if (result)
-		goto unregister;
-
-	result = device_create_file(&cdev->device, &dev_attr_cur_state);
-	if (result)
-		goto unregister;
-
 	/* Add 'this' new cdev to the global cdev list */
 	mutex_lock(&thermal_list_lock);
 	list_add(&cdev->node, &thermal_cdev_list);
@@ -1163,11 +1165,6 @@ __thermal_cooling_device_register(struct device_node *np,
 	bind_cdev(cdev);
 
 	return cdev;
-
-unregister:
-	release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
-	device_unregister(&cdev->device);
-	return ERR_PTR(result);
 }
 
 /**
-- 
2.2.0.rc0.207.ga3a616c


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] thermal: Make sysfs attributes of cooling devices default attributes
  2015-02-21  2:10 [PATCH] thermal: Make sysfs attributes of cooling devices default attributes Matthias Kaehlcke
@ 2015-03-05  5:56 ` Eduardo Valentin
  0 siblings, 0 replies; 2+ messages in thread
From: Eduardo Valentin @ 2015-03-05  5:56 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: linux-pm, Zhang Rui

[-- Attachment #1: Type: text/plain, Size: 2691 bytes --]

On Fri, Feb 20, 2015 at 06:10:08PM -0800, Matthias Kaehlcke wrote:
> Default attributes are created when the device is registered. Attributes
> created after device registration can lead to race conditions, where user space
> (e.g. udev) sees the device but not the attributes.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

applied into -fixes branch. Thanks.

> ---
>  drivers/thermal/thermal_core.c | 37 +++++++++++++++++--------------------
>  1 file changed, 17 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 48491d1..174d3bc 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -899,6 +899,22 @@ thermal_cooling_device_trip_point_show(struct device *dev,
>  		return sprintf(buf, "%d\n", instance->trip);
>  }
>  
> +static struct attribute *cooling_device_attrs[] = {
> +	&dev_attr_cdev_type.attr,
> +	&dev_attr_max_state.attr,
> +	&dev_attr_cur_state.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group cooling_device_attr_group = {
> +	.attrs = cooling_device_attrs,
> +};
> +
> +static const struct attribute_group *cooling_device_attr_groups[] = {
> +	&cooling_device_attr_group,
> +	NULL,
> +};
> +
>  /* Device management */
>  
>  /**
> @@ -1130,6 +1146,7 @@ __thermal_cooling_device_register(struct device_node *np,
>  	cdev->ops = ops;
>  	cdev->updated = false;
>  	cdev->device.class = &thermal_class;
> +	cdev->device.groups = cooling_device_attr_groups;
>  	cdev->devdata = devdata;
>  	dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
>  	result = device_register(&cdev->device);
> @@ -1139,21 +1156,6 @@ __thermal_cooling_device_register(struct device_node *np,
>  		return ERR_PTR(result);
>  	}
>  
> -	/* sys I/F */
> -	if (type) {
> -		result = device_create_file(&cdev->device, &dev_attr_cdev_type);
> -		if (result)
> -			goto unregister;
> -	}
> -
> -	result = device_create_file(&cdev->device, &dev_attr_max_state);
> -	if (result)
> -		goto unregister;
> -
> -	result = device_create_file(&cdev->device, &dev_attr_cur_state);
> -	if (result)
> -		goto unregister;
> -
>  	/* Add 'this' new cdev to the global cdev list */
>  	mutex_lock(&thermal_list_lock);
>  	list_add(&cdev->node, &thermal_cdev_list);
> @@ -1163,11 +1165,6 @@ __thermal_cooling_device_register(struct device_node *np,
>  	bind_cdev(cdev);
>  
>  	return cdev;
> -
> -unregister:
> -	release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
> -	device_unregister(&cdev->device);
> -	return ERR_PTR(result);
>  }
>  
>  /**
> -- 
> 2.2.0.rc0.207.ga3a616c
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-05  5:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-21  2:10 [PATCH] thermal: Make sysfs attributes of cooling devices default attributes Matthias Kaehlcke
2015-03-05  5:56 ` Eduardo Valentin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).