diff options
author | Christophe JAILLET <christophe.jaillet@wanadoo.fr> | 2022-11-20 12:34:41 +0300 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2022-12-05 03:45:03 +0300 |
commit | 59882c7f6714141300882af3d39ca6ffecf54ec2 (patch) | |
tree | 1c5cec48e3f73f3435f51143b2b6b5c3c92b314a /drivers/hwmon | |
parent | ef9948dfe1056a89f699edc8eb691a8ed99eda5e (diff) | |
download | linux-59882c7f6714141300882af3d39ca6ffecf54ec2.tar.xz |
hwmon: (gsc-hwmon) Switch to flexible array to simplify code
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>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/gsc-hwmon.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/hwmon/gsc-hwmon.c b/drivers/hwmon/gsc-hwmon.c index b60ec95b5edb..73e5d92b200b 100644 --- a/drivers/hwmon/gsc-hwmon.c +++ b/drivers/hwmon/gsc-hwmon.c @@ -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)) { |