Skip to contentSkip to conversation

iio: accel: sca3000: dead code issue

DISCUSSION Colin King (gmail) 5 participants 6 messages Jul 2, 2025 – Jul 3, 2025 IIO

lore
Share & tools
lore
#0 lore raw

Hi,

Static analysis on drivers/iio/accel/sca3000.c on linux-next has detected an issue in the function sca3000_ring_int_process. The issue is described as follows (prefixed by >>>)

static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)

{
        struct sca3000_state *st = iio_priv(indio_dev);
        int ret, i, num_available;

        mutex_lock(&st->lock);

        if (val & SCA3000_REG_INT_STATUS_HALF) {
                ret = spi_w8r8(st->us, 

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the call to spi_w8r8 returns 0 on success or -ve on an error

                if (ret)
                        goto error_ret;
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ret is always zero, at this point, so num_available is zero too

                num_available = ret;
                /*
                 * num_available is the total number of samples available
                 * i.e. number of time points * number of channels.
                 */
                ret = sca3000_read_data(st, SCA3000_REG_RING_OUT_ADDR, 
num_available * 2);
                if (ret)
                        goto error_ret;
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

num_available is zero, so for-loop is never executed.

                for (i = 0; i < num_available / 3; i++) {
                        /*
                         * Dirty hack to cover for 11 bit in fifo, 13 bit
                         * direct reading.
                         *
                         * In theory the bottom two bits are undefined.
                         * In reality they appear to always be 0.
                         */
                        iio_push_to_buffers(indio_dev, st->rx + i * 3 * 2);
                }
        }

I'm not sure what the logic should be to fix this, so I'm reporting this as an issue.

Regards,

Colin

#1 lore raw
Quoted 4 lines · Colin King (gmail)
                ret = spi_w8r8(st->us,

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 1 line
Quoted 1 line
Quoted 1 line

the call to spi_w8r8 returns 0 on success or -ve on an error

Where did you get this from, please? Any link to elixir or Git repo?

Quoted 3 lines
                if (ret)
                        goto error_ret;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 9 lines · On Wed, 2 Jul 2025 15:11:26 +0300 Andy Shevchenko…
Quoted 4 lines · Colin King (gmail)
                ret = spi_w8r8(st->us,

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 1 line
Quoted 1 line
Quoted 1 line

the call to spi_w8r8 returns 0 on success or -ve on an error

Where did you get this from, please? Any link to elixir or Git repo?

Hmm. Just for reference the docs of spi_w8r8 are:

* Return: the (unsigned) eight bit number returned by the
* device, or else a negative error code.

Not 0 on success (well not unless it is zero.

So the check indeed looks wrong as should be if (ret < 0)

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=testing&id=ca66d8208762492df8442a503db568d9aab65f2f
It's in my tree.

I'll drop the patch when I'm on the right machine. Andrew, could you do a new version fixing this up? If not can make the changes but will be at least the weekend before I get a chance.

Looks like there are a couple of instances of this.

Jonathan

Quoted 4 lines
Quoted 3 lines
                if (ret)
                        goto error_ret;  
#3 lore raw
Quoted 24 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 2 Jul 2025 15:11:26 +0300 Andy Shevchenko…
Quoted 4 lines · Colin King (gmail)
                ret = spi_w8r8(st->us,

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 1 line
Quoted 1 line
Quoted 1 line

the call to spi_w8r8 returns 0 on success or -ve on an error

Where did you get this from, please? Any link to elixir or Git repo?

Hmm. Just for reference the docs of spi_w8r8 are:

* Return: the (unsigned) eight bit number returned by the
* device, or else a negative error code.

Not 0 on success (well not unless it is zero.

So the check indeed looks wrong as should be if (ret < 0)

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=testing&id=ca66d8208762492df8442a503db568d9aab65f2f
It's in my tree.

I'll drop the patch when I'm on the right machine. Andrew, could you do a new version fixing this up? If not can make the changes but will be at least the weekend before I get a chance.

Hey, guys! Thanks for pointing this out, I totally missed this problem before. I'll try to fix this tomorrow.

In this case, should I send a new version of the patchset fixing the problem or a single patch following this commit with the fix?

Thanks,
Andrew

#4 lore raw
Quoted 34 lines · On Wed, 2 Jul 2025 23:52:02 -0300 Andrew Ijano <[email protected]> wrote:
Quoted 24 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 2 Jul 2025 15:11:26 +0300 Andy Shevchenko…
Quoted 4 lines · Colin King (gmail)
                ret = spi_w8r8(st->us,

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 1 line
Quoted 1 line
Quoted 1 line

the call to spi_w8r8 returns 0 on success or -ve on an error

Where did you get this from, please? Any link to elixir or Git repo?

Hmm. Just for reference the docs of spi_w8r8 are:

* Return: the (unsigned) eight bit number returned by the
* device, or else a negative error code.

Not 0 on success (well not unless it is zero.

So the check indeed looks wrong as should be if (ret < 0)

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=testing&id=ca66d8208762492df8442a503db568d9aab65f2f
It's in my tree.

I'll drop the patch when I'm on the right machine. Andrew, could you do a new version fixing this up? If not can make the changes but will be at least the weekend before I get a chance.

Quoted 5 lines

Hey, guys! Thanks for pointing this out, I totally missed this problem before. I'll try to fix this tomorrow.

In this case, should I send a new version of the patchset fixing the problem or a single patch following this commit with the fix?

Given there will probably be some fuzz for the later patches, send a new version of the whole series.

Thanks

Jonathan

Quoted 3 lines

Thanks,
Andrew

#5 lore raw
In reply to Jonathan Cameron

Wed, Jul 02, 2025 at 04:40:22PM +0100, Jonathan Cameron kirjoitti:

Quoted 9 lines
Quoted 7 lines · On Wed, 2 Jul 2025 15:11:26 +0300 Andy Shevchenko…
Quoted 4 lines · Colin King (gmail)
                ret = spi_w8r8(st->us,

SCA3000_READ_REG(SCA3000_REG_BUF_COUNT_ADDR));

Quoted 1 line
Quoted 1 line
Quoted 1 line

the call to spi_w8r8 returns 0 on success or -ve on an error

Quoted 8 lines
Quoted 1 line

Where did you get this from, please? Any link to elixir or Git repo?

Hmm. Just for reference the docs of spi_w8r8 are:

* Return: the (unsigned) eight bit number returned by the
* device, or else a negative error code.

Not 0 on success (well not unless it is zero.

Right. My point was that the comment is misleading. With the adjusted comment the rest becomes immediately clear.

Quoted 1 line

So the check indeed looks wrong as should be if (ret < 0)

Exactly. Report is valid, the comment in the analysis is not.

Quoted 2 lines

https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=testing&id=ca66d8208762492df8442a503db568d9aab65f2f
It's in my tree.

I was asking for the link to the spi_w8r8() where it's written like '0 on success and -ve on error'. Not needed anymore as you cited the documentation.

Quoted 8 lines

I'll drop the patch when I'm on the right machine. Andrew, could you do a new version fixing this up? If not can make the changes but will be at least the weekend before I get a chance.

Looks like there are a couple of instances of this.

Quoted 2 lines
Quoted 2 lines
                if (ret)
                        goto error_ret;  
Signature · 2 lines
With Best Regards,
Andy Shevchenko