linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: accel: bmi088: Correctly compute the address of the struct spi_device
@ 2023-04-02 20:58 Christophe JAILLET
  2023-04-03 17:28 ` Christophe JAILLET
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-04-02 20:58 UTC (permalink / raw)
  To: Jonathan Cameron, Lars-Peter Clausen, Mike Looijmans, Linus Walleij
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	Jonathan Cameron, linux-iio

bmi088_regmap_spi_write() is said to be similar to the SPI generic write
function.
However, regmap_spi_write() calls to_spi_device() in order to find the
reference to the "struct spi_device", instead of considering that 'context'
is already the correct value.

This works because "struct device	dev" is the first entry of
"struct spi_device".

Align bmi088_regmap_spi_write() and regmap_spi_write() to be more
future proof, should "struct spi_device" be shuffled one day.

Also update bmi088_regmap_spi_read() in the same way.

Fixes: c19ae6be7555 ("iio: accel: Add support for the Bosch-Sensortec BMI088")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: do the same for bmi088_regmap_spi_read()
---
 drivers/iio/accel/bmi088-accel-spi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/bmi088-accel-spi.c b/drivers/iio/accel/bmi088-accel-spi.c
index ee540edd8412..79e4b5392312 100644
--- a/drivers/iio/accel/bmi088-accel-spi.c
+++ b/drivers/iio/accel/bmi088-accel-spi.c
@@ -15,7 +15,8 @@
 
 static int bmi088_regmap_spi_write(void *context, const void *data, size_t count)
 {
-	struct spi_device *spi = context;
+	struct device *dev = context;
+	struct spi_device *spi = to_spi_device(dev);
 
 	/* Write register is same as generic SPI */
 	return spi_write(spi, data, count);
@@ -24,7 +25,8 @@ static int bmi088_regmap_spi_write(void *context, const void *data, size_t count
 static int bmi088_regmap_spi_read(void *context, const void *reg,
 				size_t reg_size, void *val, size_t val_size)
 {
-	struct spi_device *spi = context;
+	struct device *dev = context;
+	struct spi_device *spi = to_spi_device(dev);
 	u8 addr[2];
 
 	addr[0] = *(u8 *)reg;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iio: accel: bmi088: Correctly compute the address of the struct spi_device
  2023-04-02 20:58 [PATCH v2] iio: accel: bmi088: Correctly compute the address of the struct spi_device Christophe JAILLET
@ 2023-04-03 17:28 ` Christophe JAILLET
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2023-04-03 17:28 UTC (permalink / raw)
  To: Jonathan.Cameron, jic23, lars, linus.walleij, mike.looijmans
  Cc: kernel-janitors, linux-iio, linux-kernel

Le 02/04/2023 à 22:58, Christophe JAILLET a écrit :
> bmi088_regmap_spi_write() is said to be similar to the SPI generic write
> function.
> However, regmap_spi_write() calls to_spi_device() in order to find the
> reference to the "struct spi_device", instead of considering that 'context'
> is already the correct value.

Just NACK.
The patch looks just plain wrong.

Sorry for the noise.

CJ


> 
> This works because "struct device	dev" is the first entry of
> "struct spi_device".
> 
> Align bmi088_regmap_spi_write() and regmap_spi_write() to be more
> future proof, should "struct spi_device" be shuffled one day.
> 
> Also update bmi088_regmap_spi_read() in the same way.
> 
> Fixes: c19ae6be7555 ("iio: accel: Add support for the Bosch-Sensortec BMI088")
> Signed-off-by: Christophe JAILLET <christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
> ---
> v2: do the same for bmi088_regmap_spi_read()
> ---
>   drivers/iio/accel/bmi088-accel-spi.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmi088-accel-spi.c b/drivers/iio/accel/bmi088-accel-spi.c
> index ee540edd8412..79e4b5392312 100644
> --- a/drivers/iio/accel/bmi088-accel-spi.c
> +++ b/drivers/iio/accel/bmi088-accel-spi.c
> @@ -15,7 +15,8 @@
>   
>   static int bmi088_regmap_spi_write(void *context, const void *data, size_t count)
>   {
> -	struct spi_device *spi = context;
> +	struct device *dev = context;
> +	struct spi_device *spi = to_spi_device(dev);
>   
>   	/* Write register is same as generic SPI */
>   	return spi_write(spi, data, count);
> @@ -24,7 +25,8 @@ static int bmi088_regmap_spi_write(void *context, const void *data, size_t count
>   static int bmi088_regmap_spi_read(void *context, const void *reg,
>   				size_t reg_size, void *val, size_t val_size)
>   {
> -	struct spi_device *spi = context;
> +	struct device *dev = context;
> +	struct spi_device *spi = to_spi_device(dev);
>   	u8 addr[2];
>   
>   	addr[0] = *(u8 *)reg;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-03 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-02 20:58 [PATCH v2] iio: accel: bmi088: Correctly compute the address of the struct spi_device Christophe JAILLET
2023-04-03 17:28 ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).