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: <20250330180114.637e1a21@jic23-huawei>
Date: Sun, 30 Mar 2025 18:01:14 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Angelo Dureghello <adureghello@...libre.com>
Cc: Nuno Sá <nuno.sa@...log.com>, Lars-Peter Clausen
 <lars@...afoo.de>, Jonathan Corbet <corbet@....net>, Olivier Moysan
 <olivier.moysan@...s.st.com>, Michael Hennerich
 <Michael.Hennerich@...log.com>, linux-iio@...r.kernel.org,
 linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/4] iio: dac: ad3552r-hs: add support for internal ramp

On Fri, 21 Mar 2025 21:28:51 +0100
Angelo Dureghello <adureghello@...libre.com> wrote:

> From: Angelo Dureghello <adureghello@...libre.com>
> 
> The ad3552r can be feeded from the HDL controller by an internally
> generated 16bit ramp, useful for debug pourposes. Add debugfs a file
> to enable or disable it.
> 
> Signed-off-by: Angelo Dureghello <adureghello@...libre.com>
> ---
>  drivers/iio/dac/ad3552r-hs.c | 106 ++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 100 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad3552r-hs.c b/drivers/iio/dac/ad3552r-hs.c
> index 37397e188f225a8099745ec03f7c604da76960b1..41fe78d982a68980db059b095fc27b37ea1a461b 100644
> --- a/drivers/iio/dac/ad3552r-hs.c
> +++ b/drivers/iio/dac/ad3552r-hs.c
> @@ -7,6 +7,7 @@
>   */
>  
>  #include <linux/bitfield.h>
> +#include <linux/debugfs.h>
>  #include <linux/delay.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/iio/backend.h>
> @@ -65,6 +66,18 @@ static int ad3552r_hs_reg_read(struct ad3552r_hs_state *st, u32 reg, u32 *val,
>  	return st->data->bus_reg_read(st->back, reg, val, xfer_size);
>  }
>  
> +static int ad3552r_hs_set_data_source(struct ad3552r_hs_state *st,
> +				      enum iio_backend_data_source type)
> +{
> +	int ret;
> +
> +	ret = iio_backend_data_source_set(st->back, 0, type);
> +	if (ret)
> +		return ret;
> +
> +	return iio_backend_data_source_set(st->back, 1, type);
> +}
> +
>  static int ad3552r_hs_update_reg_bits(struct ad3552r_hs_state *st, u32 reg,
>  				      u32 mask, u32 val, size_t xfer_size)
>  {
> @@ -483,6 +496,66 @@ static int ad3552r_hs_reg_access(struct iio_dev *indio_dev, unsigned int reg,
>  	return st->data->bus_reg_write(st->back, reg, writeval, 1);
>  }
>  
> +static ssize_t ad3552r_hs_show_data_source(struct file *f, char __user *userbuf,
> +					   size_t count, loff_t *ppos)
> +{
> +	struct ad3552r_hs_state *st = file_inode(f)->i_private;
> +	enum iio_backend_data_source type;
> +	int ret;
> +
> +	ret = iio_backend_data_source_get(st->back, 0, &type);
> +	if (ret)
> +		return ret;
> +
> +	switch (type) {
> +	case IIO_BACKEND_INTERNAL_RAMP_16BIT:
> +		return simple_read_from_buffer(userbuf, count, ppos,
> +					       "backend-ramp-generator", 22);

Probably better to use a const string and then you can use strlen() to get
the length from that.  I don't much like counting characters!

> +	case IIO_BACKEND_EXTERNAL:
> +		return simple_read_from_buffer(userbuf, count, ppos,
> +					       "iio-buffer", 10);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static ssize_t ad3552r_hs_write_data_source(struct file *f,
> +					    const char __user *userbuf,
> +					    size_t count, loff_t *ppos)
> +{
> +	struct ad3552r_hs_state *st = file_inode(f)->i_private;
> +	char buf[64];
> +	int ret;
> +
> +	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
> +				     count);
> +	if (ret < 0)
> +		return ret;
> +
> +	buf[count] = 0;
> +
> +	if (count == 10 && !strncmp(buf, "iio-buffer", 10)) {
> +		ret = ad3552r_hs_set_data_source(st, IIO_BACKEND_EXTERNAL);
> +		if (ret)
> +			return ret;
> +	} else if (count == 22 && !strncmp(buf, "backend-ramp-generator", 22)) {

As above, I'd like to see some strlen() on const strings for this.
FWIW strncmp doesn't care about NULL terminators as such so just ensure you only
compare the characters.


> +		ret = ad3552r_hs_set_data_source(st,
> +			IIO_BACKEND_INTERNAL_RAMP_16BIT);
> +		if (ret)
> +			return ret;
> +	} else {
> +		return -EINVAL;
> +	}
> +
> +	return count;
> +}
...

Thanks,

Jonathan



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ