Skip to contentSkip to conversation

hwmon: (pmbus) simplify allocation slightly

PATCH In review Rosen Penev 2 participants 2 messages Mar 30 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (pmbus) simplify allocation slightly

Use a flexible array member to combine kzalloc and kcalloc.

---
 drivers/hwmon/pmbus/pmbus_core.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +4 -8
index e8fdd799c71c..c55ca3095975 100644
@@ -106,7 +106,6 @@ struct pmbus_data {
 	int max_attributes;
 	int num_attributes;
 	struct attribute_group group;
-	const struct attribute_group **groups;
 
 	struct pmbus_sensor *sensors;
 
@@ -127,6 +126,8 @@ struct pmbus_data {
 	int vout_high[PMBUS_PAGES];	/* voltage high margin */
 
 	ktime_t next_access_backoff;	/* Wait until at least this time */
+
+	const struct attribute_group *groups[];
 };
 
 struct pmbus_debugfs_entry {
@@ -3726,17 +3727,12 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
 				     | I2C_FUNC_SMBUS_WORD_DATA))
 		return -ENODEV;
 
-	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
 	if (info->groups)
 		while (info->groups[groups_num])
 			groups_num++;
 
-	data->groups = devm_kcalloc(dev, groups_num + 2, sizeof(void *),
-				    GFP_KERNEL);
-	if (!data->groups)
+	data = devm_kzalloc(dev, struct_size(data, groups, groups_num + 2), GFP_KERNEL);
+	if (!data)
 		return -ENOMEM;
 
 	i2c_set_clientdata(client, data);
Signature · 1 line
2.53.0
maintainer
#1 lore raw

Hi,

Quoted 3 lines · Rosen Penev

Use a flexible array member to combine kzalloc and kcalloc.

Please refrain from making cosmetic / personal preference changes like this in the hardware monitoring subsystem.

Thanks,
Guenter

Quoted 45 lines
---
  drivers/hwmon/pmbus/pmbus_core.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +4 -8
index e8fdd799c71c..c55ca3095975 100644
@@ -106,7 +106,6 @@ struct pmbus_data {
  	int max_attributes;
  	int num_attributes;
  	struct attribute_group group;
-	const struct attribute_group **groups;
 
  	struct pmbus_sensor *sensors;
 
@@ -127,6 +126,8 @@ struct pmbus_data {
  	int vout_high[PMBUS_PAGES];	/* voltage high margin */
 
  	ktime_t next_access_backoff;	/* Wait until at least this time */
+
+	const struct attribute_group *groups[];
  };
 
  struct pmbus_debugfs_entry {
@@ -3726,17 +3727,12 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info)
  				     | I2C_FUNC_SMBUS_WORD_DATA))
  		return -ENODEV;
 
-	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
  	if (info->groups)
  		while (info->groups[groups_num])
  			groups_num++;
 
-	data->groups = devm_kcalloc(dev, groups_num + 2, sizeof(void *),
-				    GFP_KERNEL);
-	if (!data->groups)
+	data = devm_kzalloc(dev, struct_size(data, groups, groups_num + 2), GFP_KERNEL);
+	if (!data)
  		return -ENOMEM;
 
  	i2c_set_clientdata(client, data);