Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Schiller <david.schiller@jku.at>
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <michael.hennerich@analog.com>
Subject: Re: [PATCH] staging: iio: ad5933: fix type mismatch regression
Date: Sat, 27 Jan 2024 16:06:00 +0000	[thread overview]
Message-ID: <20240127160600.3d76e013@jic23-huawei> (raw)
In-Reply-To: <20240122134916.2137957-1-david.schiller@jku.at>

On Mon, 22 Jan 2024 14:49:17 +0100
David Schiller <david.schiller@jku.at> wrote:

> Commit 4c3577db3e4f ("Staging: iio: impedance-analyzer: Fix sparse
> warning") fixed a compiler warning, but introduced a bug that resulted
> in one of the two 16 bit IIO channels always being zero (when both are
> enabled).

> 
> This is because int is 32 bits wide on most architectures and in the
> case of a little-endian machine the two most significant bytes would
> occupy the buffer for the second channel as 'val' is being passed as a
> void pointer to 'iio_push_to_buffers()'.
> 
> Fix by defining 'val' as u16. Tested working on ARM64.
> 
> Fixes: 4c3577db3e4f ("Staging: iio: impedance-analyzer: Fix sparse warning")
> Signed-off-by: David Schiller <david.schiller@jku.at>

Applied to the fixes-togreg branch of iio.git and marked for stable.

Note that if you happen to fancy doing some cleanup of this driver, it should
just be returning them big endian (and describing the channels
as such) which would simplify the code and remove the need for this
temporary buffer.

> ---
> So apparently this has gone unnoticed for over eight years. It appears
> that I'm one of only a handful of Linux people with access to AD5933:
> https://lore.kernel.org/linux-iio/20230606113013.00000530@Huawei.com/

I would love us to have emulation in place for devices like this but
even if say roadtest lands upstream, it will be a while before we
have enough tests in place to pick up this sort of error in a little used
(as you've discovered) driver.

Thanks,

Jonathan



> 
>  drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
> index 793918e1c45f..b682d0f94b0b 100644
> --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> @@ -608,7 +608,7 @@ static void ad5933_work(struct work_struct *work)
>  		struct ad5933_state, work.work);
>  	struct iio_dev *indio_dev = i2c_get_clientdata(st->client);
>  	__be16 buf[2];
> -	int val[2];
> +	u16 val[2];
>  	unsigned char status;
>  	int ret;
>  


      reply	other threads:[~2024-01-27 16:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 13:49 [PATCH] staging: iio: ad5933: fix type mismatch regression David Schiller
2024-01-27 16:06 ` Jonathan Cameron [this message]

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=20240127160600.3d76e013@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=david.schiller@jku.at \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    /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