Re: [PATCH v5 2/3] iio: accel: sca3000: replace usages of internal read data helpers by spi helpers

From: Andy Shevchenko
Date: Thu Jun 12 2025 - 09:27:06 EST


On Wed, Jun 11, 2025 at 04:39:20PM -0300, Andrew Ijano wrote:
> Remove usages of sca3000_read_data() and sca3000_read_data_short()
> functions, replacing it by spi_w8r8() and spi_w8r16be() helpers. Just
> one case that reads large buffers is left using an internal helper.
>
> This is an old driver that was not making full use of the newer
> infrastructure.

...

> + ret |= (mode & SCA3000_REG_MODE_MODE_MASK);

Unneeded parentheses.

...

> + ret = spi_w8r16be(st->us,
> + SCA3000_READ_REG(SCA3000_REG_TEMP_MSB_ADDR));

Make it simply one line. The above formatting is ugly.

...

> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct sca3000_state *st = iio_priv(indio_dev);
> - int len = 0, ret, val;
> + int len = 0, ret;

Ideally it's better to split them and len should never be signed.
Moreover, the function should be switched to sysfs_emit_at() if this is part
of ABI.

> mutex_lock(&st->lock);
> - ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
> - val = st->rx[0];
> + ret = spi_w8r8(st->us, SCA3000_READ_REG(SCA3000_REG_MODE_ADDR));
> mutex_unlock(&st->lock);
> if (ret)
> return ret;

...

> }, {
> .len = len,
> - .rx_buf = rx,
> + .rx_buf = st->rx,
> }
> };

> -

Stray change. Doesn't checkpatch complain on this?

> - (st->rx[0] | SCA3000_REG_MODE_RING_BUF_ENABLE));
> + (ret | SCA3000_REG_MODE_RING_BUF_ENABLE));

> - (st->rx[0] & ~SCA3000_REG_MODE_RING_BUF_ENABLE));
> + (ret & ~SCA3000_REG_MODE_RING_BUF_ENABLE));

In the original code and still now too many parentheses.

--
With Best Regards,
Andy Shevchenko