Skip to contentSkip to conversation

hwmon: (lm90) Create optional attributes with sysfs_create_group

PATCH Superseded Guenter Roeck 2 participants 6 messages Feb 16, 2014 – Feb 18, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/3 hwmon: (lm90) Create optional attributes with sysfs_create_group

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
 drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +22 -5
index 701e952..c3bb771 100644
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
 	.attrs = lm90_attributes,
 };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
 /*
  * Additional attributes for devices with emergency sensors
  */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 
 static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};
+
 /*
  * Real code
  */
@@ -1404,8 +1422,8 @@ static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
 	if (data->flags & LM90_HAVE_EMERGENCY)
 		sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
 	if (data->flags & LM90_HAVE_OFFSET)
-		device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
-	device_remove_file(dev, &dev_attr_pec);
+		sysfs_remove_group(&dev->kobj, &lm90_temp2_offset_group);
+	sysfs_remove_group(&dev->kobj, &lm90_pec_group);
 	sysfs_remove_group(&dev->kobj, &lm90_group);
 }
 
@@ -1569,13 +1587,12 @@ static int lm90_probe(struct i2c_client *client,
 	if (err)
 		goto exit_restore;
 	if (client->flags & I2C_CLIENT_PEC) {
-		err = device_create_file(dev, &dev_attr_pec);
+		err = sysfs_create_group(&dev->kobj, &lm90_pec_group);
 		if (err)
 			goto exit_remove_files;
 	}
 	if (data->flags & LM90_HAVE_OFFSET) {
-		err = device_create_file(dev,
-					&sensor_dev_attr_temp2_offset.dev_attr);
+		err = sysfs_create_group(&dev->kobj, &lm90_temp2_offset_group);
 		if (err)
 			goto exit_remove_files;
 	}
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#1 lore raw

PATCH 1/3 hwmon: (lm90) Create optional attributes with sysfs_create_group

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
 drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +22 -5
index 701e952..c3bb771 100644
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
 	.attrs = lm90_attributes,
 };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
 /*
  * Additional attributes for devices with emergency sensors
  */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 
 static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};
+
 /*
  * Real code
  */
@@ -1404,8 +1422,8 @@ static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
 	if (data->flags & LM90_HAVE_EMERGENCY)
 		sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
 	if (data->flags & LM90_HAVE_OFFSET)
-		device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
-	device_remove_file(dev, &dev_attr_pec);
+		sysfs_remove_group(&dev->kobj, &lm90_temp2_offset_group);
+	sysfs_remove_group(&dev->kobj, &lm90_pec_group);
 	sysfs_remove_group(&dev->kobj, &lm90_group);
 }
 
@@ -1569,13 +1587,12 @@ static int lm90_probe(struct i2c_client *client,
 	if (err)
 		goto exit_restore;
 	if (client->flags & I2C_CLIENT_PEC) {
-		err = device_create_file(dev, &dev_attr_pec);
+		err = sysfs_create_group(&dev->kobj, &lm90_pec_group);
 		if (err)
 			goto exit_remove_files;
 	}
 	if (data->flags & LM90_HAVE_OFFSET) {
-		err = device_create_file(dev,
-					&sensor_dev_attr_temp2_offset.dev_attr);
+		err = sysfs_create_group(&dev->kobj, &lm90_temp2_offset_group);
 		if (err)
 			goto exit_remove_files;
 	}
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Guenter Roeck

Hi Guenter,

Quoted 14 lines · Guenter Roeck

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
 drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +0 -0
index 701e952..c3bb771 100644

drivers/hwmon/lm90.c static const struct attribute_group lm90_group = { · line 1060

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
 	.attrs = lm90_attributes,
 };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {

Other groups in this driver use the _attributes suffix, please do the same for new groups for consistency.

Quoted 13 lines
drivers/hwmon/lm90.c +8 -0
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
 /*
  * Additional attributes for devices with emergency sensors
  */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 

drivers/hwmon/lm90.c static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, · line 1193

Quoted 10 lines
drivers/hwmon/lm90.c +8 -0
 static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};

I am worried about this. Later in this patch set you'll move the "pec" attribute from the i2c device to the hwmon class device. However this attribute is very SMBus-specific, and has nothing to do with hwmon. I don't think it makes sense to move this attribute, it should stay with the i2c device. Non-hwmon i2c device drivers could implement it too.

Quoted 31 lines
drivers/hwmon/lm90.c +5 -5
+
 /*
  * Real code
  */
@@ -1404,8 +1422,8 @@ static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
 	if (data->flags & LM90_HAVE_EMERGENCY)
 		sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
 	if (data->flags & LM90_HAVE_OFFSET)
-		device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
-	device_remove_file(dev, &dev_attr_pec);
+		sysfs_remove_group(&dev->kobj, &lm90_temp2_offset_group);
+	sysfs_remove_group(&dev->kobj, &lm90_pec_group);
 	sysfs_remove_group(&dev->kobj, &lm90_group);
 }
 
@@ -1569,13 +1587,12 @@ static int lm90_probe(struct i2c_client *client,
 	if (err)
 		goto exit_restore;
 	if (client->flags & I2C_CLIENT_PEC) {
-		err = device_create_file(dev, &dev_attr_pec);
+		err = sysfs_create_group(&dev->kobj, &lm90_pec_group);
 		if (err)
 			goto exit_remove_files;
 	}
 	if (data->flags & LM90_HAVE_OFFSET) {
-		err = device_create_file(dev,
-					&sensor_dev_attr_temp2_offset.dev_attr);
+		err = sysfs_create_group(&dev->kobj, &lm90_temp2_offset_group);
 		if (err)
 			goto exit_remove_files;
 	}
Signature · 7 lines
Jean Delvare
Suse L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#3 lore raw
In reply to Guenter Roeck
Quoted 40 lines · Jean Delvare

Hi Guenter,

Quoted 14 lines · Guenter Roeck

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
  drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
  1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +0 -0
index 701e952..c3bb771 100644

drivers/hwmon/lm90.c static const struct attribute_group lm90_group = { · line 1060

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
  	.attrs = lm90_attributes,
  };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {

Other groups in this driver use the _attributes suffix, please do the same for new groups for consistency.

Quoted 15 lines
drivers/hwmon/lm90.c +8 -0
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
  /*
   * Additional attributes for devices with emergency sensors
   */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 
  static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
Quoted 15 lines

drivers/hwmon/lm90.c static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, · line 1193

Quoted 8 lines
drivers/hwmon/lm90.c +8 -0
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};

I am worried about this. Later in this patch set you'll move the "pec" attribute from the i2c device to the hwmon class device. However this attribute is very SMBus-specific, and has nothing to do with hwmon. I don't think it makes sense to move this attribute, it should stay with the i2c device. Non-hwmon i2c device drivers could implement it too.

It is specifically mentioned in Documentation/hwmon/lm90, though. If I separate it to the i2c device, I'll have to come up with some text explaining where to find the attribute. Is that ok ?

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
In reply to Guenter Roeck
Quoted 56 lines · Guenter Roeck
Quoted 40 lines · Jean Delvare

Hi Guenter,

Quoted 14 lines · Guenter Roeck

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
  drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
  1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +0 -0
index 701e952..c3bb771 100644

drivers/hwmon/lm90.c static const struct attribute_group lm90_group = { · line 1060

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
  	.attrs = lm90_attributes,
  };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {

Other groups in this driver use the _attributes suffix, please do the same for new groups for consistency.

Quoted 15 lines
drivers/hwmon/lm90.c +8 -0
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
  /*
   * Additional attributes for devices with emergency sensors
   */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 
  static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
Quoted 14 lines

drivers/hwmon/lm90.c static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, · line 1193

Quoted 8 lines
drivers/hwmon/lm90.c +8 -0
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};

I am worried about this. Later in this patch set you'll move the "pec" attribute from the i2c device to the hwmon class device. However this attribute is very SMBus-specific, and has nothing to do with hwmon. I don't think it makes sense to move this attribute, it should stay with the i2c device. Non-hwmon i2c device drivers could implement it too.

Quoted 3 lines

It is specifically mentioned in Documentation/hwmon/lm90, though. If I separate it to the i2c device, I'll have to come up with some text explaining where to find the attribute. Is that ok ?

Well I don't even see the current wording as problematic, as it doesn't say where to find the file and nobody complained. So you could leave the text untouched, that would be equally fine with me. But if you want to clarify the documentation, sure, go ahead!

Signature · 7 lines
Jean Delvare
Suse L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#5 lore raw
In reply to Guenter Roeck
Quoted 57 lines · Jean Delvare
Quoted 56 lines · Guenter Roeck
Quoted 54 lines · Jean Delvare

Hi Guenter,

Quoted 14 lines · Guenter Roeck

With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API.

---
   drivers/hwmon/lm90.c |   27 ++++++++++++++++++++++-----
   1 file changed, 22 insertions(+), 5 deletions(-)
drivers/hwmon/lm90.c +0 -0
index 701e952..c3bb771 100644

drivers/hwmon/lm90.c static const struct attribute_group lm90_group = { · line 1060

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1057,6 +1057,15 @@ static const struct attribute_group lm90_group = {
   	.attrs = lm90_attributes,
   };
 
+static struct attribute *lm90_temp2_offset_attrs[] = {

Other groups in this driver use the _attributes suffix, please do the same for new groups for consistency.

Quoted 13 lines
drivers/hwmon/lm90.c +8 -0
+	&sensor_dev_attr_temp2_offset.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_temp2_offset_group = {
+	.attrs = lm90_temp2_offset_attrs,
+};
+
   /*
    * Additional attributes for devices with emergency sensors
    */
@@ -1174,6 +1183,15 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
 

drivers/hwmon/lm90.c static ssize_t set_pec(struct device *dev, struct device_attribute *dummy, · line 1193

Quoted 10 lines
drivers/hwmon/lm90.c +8 -0
   static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
 
+static struct attribute *lm90_pec_attrs[] = {
+	&dev_attr_pec.attr,
+	NULL
+};
+
+static const struct attribute_group lm90_pec_group = {
+	.attrs = lm90_pec_attrs,
+};

I am worried about this. Later in this patch set you'll move the "pec" attribute from the i2c device to the hwmon class device. However this attribute is very SMBus-specific, and has nothing to do with hwmon. I don't think it makes sense to move this attribute, it should stay with the i2c device. Non-hwmon i2c device drivers could implement it too.

Quoted 7 lines
Quoted 3 lines

It is specifically mentioned in Documentation/hwmon/lm90, though. If I separate it to the i2c device, I'll have to come up with some text explaining where to find the attribute. Is that ok ?

Well I don't even see the current wording as problematic, as it doesn't say where to find the file and nobody complained. So you could leave the text untouched, that would be equally fine with me. But if you want

Fine with me. I'll leave it as is.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors