From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Mikhael Abdallah de Oliveira Pinto <mikhael_abdallah@usp.br>
Cc: <jic23@kernel.org>, Augusto Bernarde <augustomb@usp.br>,
<linux-iio@vger.kernel.org>
Subject: Re: [PATCH] iio: proximity: sx9500: Deduplicate buffer managing functions
Date: Tue, 29 Apr 2025 16:07:10 +0100 [thread overview]
Message-ID: <20250429160710.00004a1b@huawei.com> (raw)
In-Reply-To: <20250429093923.347370-1-mikhael_abdallah@usp.br>
On Tue, 29 Apr 2025 06:39:23 -0300
Mikhael Abdallah de Oliveira Pinto <mikhael_abdallah@usp.br> wrote:
> Refactor to share logic between buffer enable/disable handlers.
>
> Signed-off-by: Mikhael Abdallah de Oliveira Pinto <mikhael_abdallah@usp.br>
> Co-developed-by: Augusto Bernarde <augustomb@usp.br>
> Signed-off-by: Augusto Bernarde <augustomb@usp.br>
> ---
> drivers/iio/proximity/sx9500.c | 50 ++++++++++++++++------------------
In my view this isn't a significant enough reduction to justify the more complex code.
Particularly in the error paths.
Jonathan
> 1 file changed, 23 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
> index c4e94d0fb163..75459c85116b 100644
> --- a/drivers/iio/proximity/sx9500.c
> +++ b/drivers/iio/proximity/sx9500.c
> @@ -674,52 +674,48 @@ static irqreturn_t sx9500_trigger_handler(int irq, void *private)
> return IRQ_HANDLED;
> }
>
> -static int sx9500_buffer_postenable(struct iio_dev *indio_dev)
> +static int sx9500_buffer_manage_chan_users(struct iio_dev *indio_dev, bool enable_channels)
> {
> struct sx9500_data *data = iio_priv(indio_dev);
> int ret = 0, i;
>
> mutex_lock(&data->mutex);
>
> - for (i = 0; i < SX9500_NUM_CHANNELS; i++)
> + for (i = 0; i < SX9500_NUM_CHANNELS; i++) {
> if (test_bit(i, indio_dev->active_scan_mask)) {
> - ret = sx9500_inc_chan_users(data, i);
> + if (enable_channels)
> + ret = sx9500_inc_chan_users(data, i);
> + else
> + ret = sx9500_dec_chan_users(data, i);
> if (ret)
> break;
> }
> + }
>
> - if (ret)
> - for (i = i - 1; i >= 0; i--)
> - if (test_bit(i, indio_dev->active_scan_mask))
> - sx9500_dec_chan_users(data, i);
> + if (ret) {
> + for (i = i - 1; i >= 0; i--) {
> + if (test_bit(i, indio_dev->active_scan_mask)) {
> + if (enable_channels)
> + sx9500_dec_chan_users(data, i);
> + else
> + sx9500_inc_chan_users(data, i);
> + }
> + }
> + }
>
> mutex_unlock(&data->mutex);
>
> return ret;
> }
>
> -static int sx9500_buffer_predisable(struct iio_dev *indio_dev)
> +static int sx9500_buffer_postenable(struct iio_dev *indio_dev)
> {
> - struct sx9500_data *data = iio_priv(indio_dev);
> - int ret = 0, i;
> -
> - mutex_lock(&data->mutex);
> -
> - for (i = 0; i < SX9500_NUM_CHANNELS; i++)
> - if (test_bit(i, indio_dev->active_scan_mask)) {
> - ret = sx9500_dec_chan_users(data, i);
> - if (ret)
> - break;
> - }
> -
> - if (ret)
> - for (i = i - 1; i >= 0; i--)
> - if (test_bit(i, indio_dev->active_scan_mask))
> - sx9500_inc_chan_users(data, i);
> -
> - mutex_unlock(&data->mutex);
> + return sx9500_buffer_manage_chan_users(indio_dev, true);
> +}
>
> - return ret;
> +static int sx9500_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + return sx9500_buffer_manage_chan_users(indio_dev, false);
> }
>
> static const struct iio_buffer_setup_ops sx9500_buffer_setup_ops = {
next prev parent reply other threads:[~2025-04-29 15:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 9:39 [PATCH] iio: proximity: sx9500: Deduplicate buffer managing functions Mikhael Abdallah de Oliveira Pinto
2025-04-29 15:07 ` Jonathan Cameron [this message]
2025-05-01 18:23 ` Mikhael Abdallah de Oliveira Pinto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250429160710.00004a1b@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=augustomb@usp.br \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=mikhael_abdallah@usp.br \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox