Re: [PATCH v2 5/8] iio: adc: ti-ads1015: Use guard(mutex) and factor out code for INFO_RAW

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/9/25 11:58 AM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> 
> By use of automatic lock release and introducing a new utility
> function to handle the core activity of reading the ADC channel,
> many more complex code flows can be replaced by direct returns.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> Cc: Marek Vasut <marex@xxxxxxx>
> ---

...

>  static int ads1015_read_event_config(struct iio_dev *indio_dev,
> @@ -710,25 +686,19 @@ static int ads1015_read_event_config(struct iio_dev *indio_dev,
>  	enum iio_event_direction dir)
>  {
>  	struct ads1015_data *data = iio_priv(indio_dev);
> -	int ret = 0;
>  
> -	mutex_lock(&data->lock);
> -	if (data->event_channel == chan->address) {
> -		switch (dir) {
> -		case IIO_EV_DIR_RISING:
> -			ret = 1;
> -			break;
> -		case IIO_EV_DIR_EITHER:
> -			ret = (data->comp_mode == ADS1015_CFG_COMP_MODE_WINDOW);
> -			break;
> -		default:
> -			ret = -EINVAL;
> -			break;
> -		}
> -	}
> -	mutex_unlock(&data->lock);
> +	guard(mutex)(&data->lock);
> +	if (data->event_channel != chan->address)
> +		return -EBUSY;

The old code returned 0 in this case instead of -EBUSY, so this seems like an
unrelated or unintentional change.

>  
> -	return ret;
> +	switch (dir) {
> +	case IIO_EV_DIR_RISING:
> +		return 1;
> +	case IIO_EV_DIR_EITHER:
> +		return (data->comp_mode == ADS1015_CFG_COMP_MODE_WINDOW);
> +	default:
> +		return -EINVAL;
> +	}
>  }
>  




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux