[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b72d009a-9d7d-42cd-af2e-80584bba788d@linux.dev>
Date: Tue, 15 Jul 2025 11:55:08 -0400
From: Sean Anderson <sean.anderson@...ux.dev>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
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 7/15/25 04:38, Andy Shevchenko wrote:
> 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.
>
> ...
OK
>> +static int add_device_attr(struct device *dev, struct iio_hwmon_state *st,
>
> This should hint that this is managed:
>
> add_device_managed_attr()
That just makes it more difficult to format the calling code within 80 columns...
>
>> + ssize_t (*show)(struct device *dev,
>> + struct device_attribute *attr,
>> + char *buf),
>> + int i, const char *fmt, ...)
>
> __printf() attribute is missing.
It's static, so I thought the compiler could infer it but I guess not.
>> +{
>> + 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?
It's not ordered as-is, and I don't think this subsystem requires it.
>> 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;
>
--Sean
Powered by blists - more mailing lists