[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aHYTcAO7sHsyevDH@smile.fi.intel.com>
Date: Tue, 15 Jul 2025 11:38:08 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Sean Anderson <sean.anderson@...ux.dev>
Cc: Jonathan Cameron <jic23@...nel.org>, Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>, linux-iio@...r.kernel.org,
linux-hwmon@...r.kernel.org, Andy Shevchenko <andy@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
linux-kernel@...r.kernel.org, David Lechner <dlechner@...libre.com>
Subject: Re: [PATCH 5/7] hwmon: iio: Add helper function for creating
attributes
On Mon, Jul 14, 2025 at 09:20:21PM -0400, Sean Anderson wrote:
> Add a helper function to create attributes and initialize their fields.
> This reduces repetition when creating several attributes per channel.
...
> + * @num_attrs: length of @attrs
Other lines use TABs.
...
> +static int add_device_attr(struct device *dev, struct iio_hwmon_state *st,
This should hint that this is managed:
add_device_managed_attr()
?
> + ssize_t (*show)(struct device *dev,
> + struct device_attribute *attr,
> + char *buf),
> + int i, const char *fmt, ...)
__printf() attribute is missing.
> +{
> + struct sensor_device_attribute *a;
> + va_list ap;
> +
> + a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL);
> + if (!a)
> + return -ENOMEM;
> +
> + sysfs_attr_init(&a->dev_attr.attr);
> + va_start(ap, fmt);
> + a->dev_attr.attr.name = devm_kvasprintf(dev, GFP_KERNEL, fmt, ap);
> + va_end(ap);
> + if (!a->dev_attr.attr.name)
> + return -ENOMEM;
> +
> + a->dev_attr.show = show;
> + a->dev_attr.attr.mode = 0444;
> + a->index = i;
> +
> + st->attrs[st->num_attrs++] = &a->dev_attr.attr;
> + return 0;
> +}
...
> struct device *dev = &pdev->dev;
> struct iio_hwmon_state *st;
> - struct sensor_device_attribute *a;
> - int ret, i, attr = 0;
> + int ret, i;
Also move it a bit to make it more of a reversed xmas tree ordering?
> int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1;
> enum iio_chan_type type;
> struct iio_channel *channels;
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists