]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (gsc-hwmon) Switch to flexible array to simplify code
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 20 Nov 2022 09:34:41 +0000 (10:34 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 5 Dec 2022 00:45:03 +0000 (16:45 -0800)
Using flexible array is more straight forward. It
  - saves 1 pointer in the 'gsc_hwmon_platform_data' structure
  - saves an indirection when using this array
  - saves some LoC and avoids some always spurious pointer arithmetic

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/61a23e1d642397cfcecc4ac3bb0ab485d257987d.1668936855.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/gsc-hwmon.c
include/linux/platform_data/gsc_hwmon.h

index b60ec95b5edbf248da1d4abfd1abff494180beaa..73e5d92b200b0c348c627ebb91d1372a6e2b8809 100644 (file)
@@ -257,13 +257,10 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
        if (nchannels == 0)
                return ERR_PTR(-ENODEV);
 
-       pdata = devm_kzalloc(dev,
-                            sizeof(*pdata) + nchannels * sizeof(*ch),
+       pdata = devm_kzalloc(dev, struct_size(pdata, channels, nchannels),
                             GFP_KERNEL);
        if (!pdata)
                return ERR_PTR(-ENOMEM);
-       ch = (struct gsc_hwmon_channel *)(pdata + 1);
-       pdata->channels = ch;
        pdata->nchannels = nchannels;
 
        /* fan controller base address */
@@ -277,6 +274,7 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
 
        of_node_put(fan);
 
+       ch = pdata->channels;
        /* allocate structures for channels and count instances of each type */
        device_for_each_child_node(dev, child) {
                if (fwnode_property_read_string(child, "label", &ch->name)) {
index 281f499eda9790b877ac99e188a5210fdc0ce233..f2781aa7eff85f6b6f3d3c7a52ef94ebec15f234 100644 (file)
@@ -29,18 +29,17 @@ struct gsc_hwmon_channel {
 
 /**
  * struct gsc_hwmon_platform_data - platform data for gsc_hwmon driver
- * @channels:  pointer to array of gsc_hwmon_channel structures
- *             describing channels
  * @nchannels: number of elements in @channels array
  * @vreference: voltage reference (mV)
  * @resolution: ADC bit resolution
  * @fan_base: register base for FAN controller
+ * @channels:  array of gsc_hwmon_channel structures describing channels
  */
 struct gsc_hwmon_platform_data {
-       const struct gsc_hwmon_channel *channels;
        int nchannels;
        unsigned int resolution;
        unsigned int vreference;
        unsigned int fan_base;
+       struct gsc_hwmon_channel channels[];
 };
 #endif