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] [day] [month] [year] [list]
Message-ID: <0771a9a7-ec49-487e-afaa-46a39f0b8ba2@stanley.mountain>
Date: Fri, 25 Apr 2025 16:18:04 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Gabriel Shahrouzi <gshahrouzi@...il.com>
Cc: andy@...nel.org, dlechner@...libre.com, gregkh@...uxfoundation.org,
	jic23@...nel.org, lars@...afoo.de, linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-staging@...ts.linux.dev,
	Michael.Hennerich@...log.com, nuno.sa@...log.com,
	skhan@...uxfoundation.org, linux-kernel-mentees@...ts.linux.dev
Subject: Re: [PATCH v4 2/2] staging: iio: frequency: ad9832: Refactor
 powerdown control

On Thu, Apr 24, 2025 at 06:32:09PM -0400, Gabriel Shahrouzi wrote:
> Replace custom implementation with out_altvoltage_powerdown ABI. The
> attribute's logic is inverted (1 now enables powerdown) to match the
> standard.
> 
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@...il.com>
> ---
> V3 -> v4:
> 	- Use guard(mutex) for simplified locking.
> 	- Use an extended attribute.
> v2 -> v3:
> v1 -> v2:
> 	Refactor powerdown functionality.
> ---
>  drivers/staging/iio/frequency/ad9832.c | 69 +++++++++++++++++++-------
>  1 file changed, 51 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 2e555084ff98a..b8b52302abf36 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -174,6 +174,32 @@ static int ad9832_write_phase(struct ad9832_state *st,
>  	return spi_sync(st->spi, &st->phase_msg);
>  }
>  
> +static ssize_t ad9832_write_powerdown(struct iio_dev *indio_dev, uintptr_t private,
> +				      const struct iio_chan_spec *chan,
> +				      const char *buf, size_t len)
> +{
> +	struct ad9832_state *st = iio_priv(indio_dev);
> +	int ret;
> +	bool val;

Declare val before ret.  Use reverse Christmas tree order.

	long long long_name;
	medium name;
	short name;

> +
> +	ret = kstrtobool(buf, &val);
> +	if (ret)
> +		return ret;
> +
> +	guard(mutex)(&st->lock);
> +	if (val)
> +		st->ctrl_src |= AD9832_SLEEP;
> +	else
> +		st->ctrl_src &= ~(AD9832_RESET | AD9832_SLEEP |
> +				 AD9832_CLR);
> +
> +	st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SLEEPRESCLR) |
> +					  st->ctrl_src);
> +	ret = spi_sync(st->spi, &st->msg);
> +
> +	return ret ? ret : len;
> +}
> +
>  static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
>  			    const char *buf, size_t len)
>  {
> @@ -185,9 +211,9 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
>  
>  	ret = kstrtoul(buf, 10, &val);
>  	if (ret)
> -		goto error_ret;
> +		return ret;

This is unrelated.  Do this in a separate patch.

>  
> -	mutex_lock(&st->lock);
> +	guard(mutex)(&st->lock);

same.

>  	switch ((u32)this_attr->address) {
>  	case AD9832_FREQ0HM:
>  	case AD9832_FREQ1HM:
> @@ -232,22 +258,9 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
>  						  st->ctrl_fp);
>  		ret = spi_sync(st->spi, &st->msg);
>  		break;
> -	case AD9832_OUTPUT_EN:
> -		if (val)
> -			st->ctrl_src &= ~(AD9832_RESET | AD9832_SLEEP | AD9832_CLR);
> -		else
> -			st->ctrl_src |= FIELD_PREP(AD9832_SLEEP, 1);
> -
> -		st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_SLEEPRESCLR) |
> -						  st->ctrl_src);
> -		ret = spi_sync(st->spi, &st->msg);
> -		break;

This is related.  Keep this.

>  	default:
>  		ret = -ENODEV;
>  	}
> -	mutex_unlock(&st->lock);
> -
> -error_ret:
>  	return ret ? ret : len;

Unrelated.

>  }
>  
> @@ -270,8 +283,6 @@ static IIO_CONST_ATTR_PHASE_SCALE(0, "0.0015339808"); /* 2PI/2^12 rad*/
>  
>  static IIO_DEV_ATTR_PINCONTROL_EN(0, 0200, NULL,
>  				ad9832_write, AD9832_PINCTRL_EN);
> -static IIO_DEV_ATTR_OUT_ENABLE(0, 0200, NULL,
> -				ad9832_write, AD9832_OUTPUT_EN);
>  
>  static struct attribute *ad9832_attributes[] = {
>  	&iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
> @@ -285,7 +296,6 @@ static struct attribute *ad9832_attributes[] = {
>  	&iio_dev_attr_out_altvoltage0_pincontrol_en.dev_attr.attr,
>  	&iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
>  	&iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
> -	&iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
>  	NULL,
>  };
>  
> @@ -293,6 +303,27 @@ static const struct attribute_group ad9832_attribute_group = {
>  	.attrs = ad9832_attributes,
>  };
>  
> +static const struct iio_chan_spec_ext_info ad9832_ext_info[] = {
> +	{
> +		.name = "powerdown",
> +		.shared = IIO_SEPARATE,
> +		.write = ad9832_write_powerdown,
> +	},
> +	{ },
           ^
No comma after a sentinal.

> +};
> +

regards,
dan carpenter


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ