From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read()
Date: Mon, 21 Apr 2025 11:59:24 +0100 [thread overview]
Message-ID: <20250421115924.682f52ee@jic23-huawei> (raw)
In-Reply-To: <20250418-iio-amplifiers-ada4250-simplify-data-buffer-in-init-v1-1-7e7bd6dad423@baylibre.com>
On Fri, 18 Apr 2025 13:16:13 -0500
David Lechner <dlechner@baylibre.com> wrote:
> Use DMA-safe memory instead of stack-allocated memory for the call to
> regmap_bulk_read() in the ada4250_init() function as this could be used
> directly by a SPI controller.
>
> Also remove unnecessary use of get_unaligned_le16() and explicitly
> include linux/types.h e.g. for __le16 while we are fixing this up.
>
> Fixes: 28b4c30bfa5f ("iio: amplifiers: ada4250: add support for ADA4250")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
Let's wait and see if Mark has a view on this. The switch to an __le16 is
good either way.
Jonathan
> ---
> drivers/iio/amplifiers/ada4250.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/amplifiers/ada4250.c b/drivers/iio/amplifiers/ada4250.c
> index 74f8429d652b17b4d1f38366e23ce6a2b3e9b218..f81438460aa51ce30f8f605c60ee5be5c8c251d3 100644
> --- a/drivers/iio/amplifiers/ada4250.c
> +++ b/drivers/iio/amplifiers/ada4250.c
> @@ -13,8 +13,7 @@
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
> -
> -#include <linux/unaligned.h>
> +#include <linux/types.h>
>
> /* ADA4250 Register Map */
> #define ADA4250_REG_GAIN_MUX 0x00
> @@ -63,6 +62,7 @@ struct ada4250_state {
> u8 gain;
> int offset_uv;
> bool refbuf_en;
> + __le16 reg_val_16 __aligned(IIO_DMA_MINALIGN);
> };
>
> /* ADA4250 Current Bias Source Settings: Disabled, Bandgap Reference, AVDD */
> @@ -301,7 +301,6 @@ static int ada4250_init(struct ada4250_state *st)
> {
> int ret;
> u16 chip_id;
> - u8 data[2] __aligned(8) = {};
> struct spi_device *spi = st->spi;
>
> st->refbuf_en = device_property_read_bool(&spi->dev, "adi,refbuf-enable");
> @@ -326,11 +325,12 @@ static int ada4250_init(struct ada4250_state *st)
> if (ret)
> return ret;
>
> - ret = regmap_bulk_read(st->regmap, ADA4250_REG_CHIP_ID, data, 2);
> + ret = regmap_bulk_read(st->regmap, ADA4250_REG_CHIP_ID, &st->reg_val_16,
> + sizeof(st->reg_val_16));
> if (ret)
> return ret;
>
> - chip_id = get_unaligned_le16(data);
> + chip_id = le16_to_cpu(st->reg_val_16);
>
> if (chip_id != ADA4250_CHIP_ID) {
> dev_err(&spi->dev, "Invalid chip ID.\n");
>
> ---
> base-commit: aff301f37e220970c2f301b5c65a8bfedf52058e
> change-id: 20250418-iio-amplifiers-ada4250-simplify-data-buffer-in-init-93ebb1344295
>
> Best regards,
prev parent reply other threads:[~2025-04-21 10:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 18:16 [PATCH] iio: amplifiers: ada4250: use DMA-safe memory for regmap_bulk_read() David Lechner
[not found] ` <CAHp75Vdxdbqu6qkbuo5y4jADOH_h9Re6m8icSj3Je4hnVsha0g@mail.gmail.com>
2025-04-18 19:09 ` David Lechner
2025-04-19 15:03 ` Andy Shevchenko
2025-04-19 18:07 ` David Lechner
2025-04-21 10:57 ` Jonathan Cameron
2025-04-21 13:00 ` Nuno Sá
2025-04-21 13:56 ` Jonathan Cameron
2025-05-25 17:31 ` Jonathan Cameron
2025-04-21 10:59 ` 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=20250421115924.682f52ee@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=dlechner@baylibre.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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