lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250727173542.46680071@jic23-huawei>
Date: Sun, 27 Jul 2025 17:35:42 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Sean Anderson <sean.anderson@...ux.dev>
Cc: 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 6/7] hwmon: iio: Add min/max support

On Mon, 14 Jul 2025 21:20:22 -0400
Sean Anderson <sean.anderson@...ux.dev> wrote:

> Add support for minimum/maximum attributes. Like the _input attribute,
> we just need to call into the IIO API.
> 
> Signed-off-by: Sean Anderson <sean.anderson@...ux.dev>

Similar comments to previous. I'm not keen on the blend of allocation of
attributes and registration.  If we can break that link I think it will give
cleaner code.

>  static int add_device_attr(struct device *dev, struct iio_hwmon_state *st,
>  			   ssize_t (*show)(struct device *dev,
>  					   struct device_attribute *attr,
> @@ -123,6 +171,40 @@ static int add_device_attr(struct device *dev, struct iio_hwmon_state *st,
>  	return 0;
>  }
>  
> +static int add_event_attr(struct device *dev, struct iio_hwmon_state *st,
> +			  int i, enum iio_event_direction dir,
> +			  const char *fmt, ...)
> +{
> +	struct sensor_device_attribute_2 *a;
> +	umode_t mode;
> +	va_list ap;
> +
> +	mode = iio_event_mode(&st->channels[i], IIO_EV_TYPE_THRESH, dir,
> +			      IIO_EV_INFO_VALUE);
> +	if (!mode)
> +		return 0;
> +
> +	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 = iio_hwmon_read_event;
> +	a->dev_attr.store = iio_hwmon_write_event;
> +	a->dev_attr.attr.mode = mode;
> +	a->index = i;
> +	a->nr = dir;
> +
> +	st->attrs[st->num_attrs++] = &a->dev_attr.attr;
similar comment to the previous, though here I think we'd
need to pass in the channel to an iio_hwmon_alloc_event_attr() as ideally we'd
not be messing with st at all in here.  So maybe it doesn't work out.

> +	return 0;
> +}



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ