* [PATCH] hwmon: (gsc-hwmon) Switch to flexible array to simplify code
@ 2022-11-20 9:34 Christophe JAILLET
2022-11-20 14:17 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-11-20 9:34 UTC (permalink / raw)
To: Tim Harvey, Jean Delvare, Guenter Roeck
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-hwmon
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>
---
Compile tested only
---
drivers/hwmon/gsc-hwmon.c | 6 ++----
include/linux/platform_data/gsc_hwmon.h | 5 ++---
2 files changed, 4 insertions(+), 7 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)) {
diff --git a/include/linux/platform_data/gsc_hwmon.h b/include/linux/platform_data/gsc_hwmon.h
index 281f499eda97..f2781aa7eff8 100644
--- a/include/linux/platform_data/gsc_hwmon.h
+++ b/include/linux/platform_data/gsc_hwmon.h
@@ -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
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon: (gsc-hwmon) Switch to flexible array to simplify code
2022-11-20 9:34 [PATCH] hwmon: (gsc-hwmon) Switch to flexible array to simplify code Christophe JAILLET
@ 2022-11-20 14:17 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-11-20 14:17 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Tim Harvey, Jean Delvare, linux-kernel, kernel-janitors, linux-hwmon
On Sun, Nov 20, 2022 at 10:34:41AM +0100, Christophe JAILLET wrote:
> 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>
Applied to hwmon-next.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-20 14:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20 9:34 [PATCH] hwmon: (gsc-hwmon) Switch to flexible array to simplify code Christophe JAILLET
2022-11-20 14:17 ` Guenter Roeck
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).