linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] spi: struct spi_device constification
@ 2023-03-13 10:58 Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void * Geert Uytterhoeven
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

	Hi all,

After noticing new cases of casting away constness, I went over all
spi_get_*() functions and their callers, and made the following changes:
  1. Make all pointer parameters const where possible,
  2. Remove unneeded casts, some not even related to constness.

Patches 1-5 do not have any dependencies.
Patch 6 depends on patch 5 (and current spi/for-next).

Thanks for your comments!

Geert Uytterhoeven (6):
  mfd: rsmu_spi: Remove unneeded casts of void *
  spi: fsl-dspi: Remove unneeded cast to same type
  spi: Constify spi_get_ctldata()'s spi parameter
  spi: Constify spi_get_drvdata()'s spi parameter
  spi: Constify spi parameters of chip select APIs
  spi: sh-msiof: Remove casts to drop constness

 drivers/mfd/rsmu_spi.c     | 4 ++--
 drivers/spi/spi-fsl-dspi.c | 2 +-
 drivers/spi/spi-sh-msiof.c | 4 ++--
 include/linux/spi/spi.h    | 8 ++++----
 4 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.34.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

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

* [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void *
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-16 16:13   ` Lee Jones
  2023-03-13 10:58 ` [PATCH 2/6] spi: fsl-dspi: Remove unneeded cast to same type Geert Uytterhoeven
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

There is no need to cast a "void *" to a different type of pointer.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/mfd/rsmu_spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/rsmu_spi.c b/drivers/mfd/rsmu_spi.c
index d2f3d8f1e05af054..2428aaa9aaed9e43 100644
--- a/drivers/mfd/rsmu_spi.c
+++ b/drivers/mfd/rsmu_spi.c
@@ -129,7 +129,7 @@ static int rsmu_write_page_register(struct rsmu_ddata *rsmu, u16 reg)
 
 static int rsmu_reg_read(void *context, unsigned int reg, unsigned int *val)
 {
-	struct rsmu_ddata *rsmu = spi_get_drvdata((struct spi_device *)context);
+	struct rsmu_ddata *rsmu = spi_get_drvdata(context);
 	u8 addr = (u8)(reg & RSMU_LOWER_ADDR_MASK);
 	int err;
 
@@ -146,7 +146,7 @@ static int rsmu_reg_read(void *context, unsigned int reg, unsigned int *val)
 
 static int rsmu_reg_write(void *context, unsigned int reg, unsigned int val)
 {
-	struct rsmu_ddata *rsmu = spi_get_drvdata((struct spi_device *)context);
+	struct rsmu_ddata *rsmu = spi_get_drvdata(context);
 	u8 addr = (u8)(reg & RSMU_LOWER_ADDR_MASK);
 	u8 data = (u8)val;
 	int err;
-- 
2.34.1


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

* [PATCH 2/6] spi: fsl-dspi: Remove unneeded cast to same type
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void * Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 3/6] spi: Constify spi_get_ctldata()'s spi parameter Geert Uytterhoeven
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

There is never a need to cast a pointer to the same pointer type.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/spi/spi-fsl-dspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index ee42285b5c5243a5..4339485d202c05c7 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1068,7 +1068,7 @@ static int dspi_setup(struct spi_device *spi)
 
 static void dspi_cleanup(struct spi_device *spi)
 {
-	struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
+	struct chip_data *chip = spi_get_ctldata(spi);
 
 	dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n",
 		spi->controller->bus_num, spi_get_chipselect(spi, 0));
-- 
2.34.1


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

* [PATCH 3/6] spi: Constify spi_get_ctldata()'s spi parameter
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void * Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 2/6] spi: fsl-dspi: Remove unneeded cast to same type Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 4/6] spi: Constify spi_get_drvdata()'s " Geert Uytterhoeven
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

The "spi" parameter of spi_get_ctldata() can be const.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 include/linux/spi/spi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index bdb35a91b4bf0141..6097d2f5126624eb 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -244,7 +244,7 @@ static inline void spi_dev_put(struct spi_device *spi)
 }
 
 /* ctldata is for the bus_controller driver's runtime state */
-static inline void *spi_get_ctldata(struct spi_device *spi)
+static inline void *spi_get_ctldata(const struct spi_device *spi)
 {
 	return spi->controller_state;
 }
-- 
2.34.1


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

* [PATCH 4/6] spi: Constify spi_get_drvdata()'s spi parameter
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2023-03-13 10:58 ` [PATCH 3/6] spi: Constify spi_get_ctldata()'s spi parameter Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 5/6] spi: Constify spi parameters of chip select APIs Geert Uytterhoeven
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

The "spi" parameter of spi_get_drvdata() can be const.
dev_get_drvdata() has been taking a const pointer since commit
7d1d8999b4bec0ba ("i2c: Constify i2c_get_clientdata's parameter").

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 include/linux/spi/spi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 6097d2f5126624eb..e09a61dd34594330 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -261,7 +261,7 @@ static inline void spi_set_drvdata(struct spi_device *spi, void *data)
 	dev_set_drvdata(&spi->dev, data);
 }
 
-static inline void *spi_get_drvdata(struct spi_device *spi)
+static inline void *spi_get_drvdata(const struct spi_device *spi)
 {
 	return dev_get_drvdata(&spi->dev);
 }
-- 
2.34.1


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

* [PATCH 5/6] spi: Constify spi parameters of chip select APIs
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
                   ` (3 preceding siblings ...)
  2023-03-13 10:58 ` [PATCH 4/6] spi: Constify spi_get_drvdata()'s " Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-13 10:58 ` [PATCH 6/6] spi: sh-msiof: Remove casts to drop constness Geert Uytterhoeven
  2023-03-13 18:20 ` (subset) [PATCH 0/6] spi: struct spi_device constification Mark Brown
  6 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

The "spi" parameters of spi_get_chipselect() and spi_get_csgpiod() can
be const.

Fixes: 303feb3cc06ac066 ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 include/linux/spi/spi.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index e09a61dd34594330..74bff5a2f53d36cc 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -266,7 +266,7 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)
 	return dev_get_drvdata(&spi->dev);
 }
 
-static inline u8 spi_get_chipselect(struct spi_device *spi, u8 idx)
+static inline u8 spi_get_chipselect(const struct spi_device *spi, u8 idx)
 {
 	return spi->chip_select;
 }
@@ -276,7 +276,7 @@ static inline void spi_set_chipselect(struct spi_device *spi, u8 idx, u8 chipsel
 	spi->chip_select = chipselect;
 }
 
-static inline struct gpio_desc *spi_get_csgpiod(struct spi_device *spi, u8 idx)
+static inline struct gpio_desc *spi_get_csgpiod(const struct spi_device *spi, u8 idx)
 {
 	return spi->cs_gpiod;
 }
-- 
2.34.1


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

* [PATCH 6/6] spi: sh-msiof: Remove casts to drop constness
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
                   ` (4 preceding siblings ...)
  2023-03-13 10:58 ` [PATCH 5/6] spi: Constify spi parameters of chip select APIs Geert Uytterhoeven
@ 2023-03-13 10:58 ` Geert Uytterhoeven
  2023-03-13 18:20 ` (subset) [PATCH 0/6] spi: struct spi_device constification Mark Brown
  6 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-03-13 10:58 UTC (permalink / raw)
  To: Mark Brown, Min Li, Lee Jones, Vladimir Oltean,
	Amit Kumar Mahapatra, Michal Simek
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

Now the chip select APIs take const pointers, there is no longer a need
to cast away constness.

Fixes: 9e264f3f85a56cc1 ("spi: Replace all spi->chip_select and spi->cs_gpiod references with function call")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/spi/spi-sh-msiof.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 50498c4eb661d09f..55dfe2fd89c8ba4c 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -587,11 +587,11 @@ static int sh_msiof_prepare_message(struct spi_controller *ctlr,
 	u32 ss, cs_high;
 
 	/* Configure pins before asserting CS */
-	if (spi_get_csgpiod((struct spi_device *)spi, 0)) {
+	if (spi_get_csgpiod(spi, 0)) {
 		ss = ctlr->unused_native_cs;
 		cs_high = p->native_cs_high;
 	} else {
-		ss = spi_get_chipselect((struct spi_device *)spi, 0);
+		ss = spi_get_chipselect(spi, 0);
 		cs_high = !!(spi->mode & SPI_CS_HIGH);
 	}
 	sh_msiof_spi_set_pin_regs(p, ss, !!(spi->mode & SPI_CPOL),
-- 
2.34.1


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

* Re: (subset) [PATCH 0/6] spi: struct spi_device constification
  2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
                   ` (5 preceding siblings ...)
  2023-03-13 10:58 ` [PATCH 6/6] spi: sh-msiof: Remove casts to drop constness Geert Uytterhoeven
@ 2023-03-13 18:20 ` Mark Brown
  6 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2023-03-13 18:20 UTC (permalink / raw)
  To: Min Li, Lee Jones, Vladimir Oltean, Amit Kumar Mahapatra,
	Michal Simek, Geert Uytterhoeven
  Cc: linux-spi, linux-renesas-soc, linux-kernel

On Mon, 13 Mar 2023 11:58:32 +0100, Geert Uytterhoeven wrote:
> 	Hi all,
> 
> After noticing new cases of casting away constness, I went over all
> spi_get_*() functions and their callers, and made the following changes:
>   1. Make all pointer parameters const where possible,
>   2. Remove unneeded casts, some not even related to constness.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[2/6] spi: fsl-dspi: Remove unneeded cast to same type
      commit: 9c8400e3795decefe6390646ece820a310b37b79
[3/6] spi: Constify spi_get_ctldata()'s spi parameter
      commit: cc4b15670340315fb0b25d886c06bffb5f128f02
[4/6] spi: Constify spi_get_drvdata()'s spi parameter
      commit: 38dca04d659a422d842f7edcecd32253c7a6fb5e
[5/6] spi: Constify spi parameters of chip select APIs
      commit: d2f19eec510424caa55ea949f016ddabe2d8173a
[6/6] spi: sh-msiof: Remove casts to drop constness
      commit: 7859ad5a401b73bf2ddfa274950b5722492c3150

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

* Re: [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void *
  2023-03-13 10:58 ` [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void * Geert Uytterhoeven
@ 2023-03-16 16:13   ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2023-03-16 16:13 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Mark Brown, Min Li, Vladimir Oltean, Amit Kumar Mahapatra,
	Michal Simek, linux-spi, linux-renesas-soc, linux-kernel

On Mon, 13 Mar 2023, Geert Uytterhoeven wrote:

> There is no need to cast a "void *" to a different type of pointer.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/mfd/rsmu_spi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

--
Lee Jones [李琼斯]

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

end of thread, other threads:[~2023-03-16 16:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 10:58 [PATCH 0/6] spi: struct spi_device constification Geert Uytterhoeven
2023-03-13 10:58 ` [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void * Geert Uytterhoeven
2023-03-16 16:13   ` Lee Jones
2023-03-13 10:58 ` [PATCH 2/6] spi: fsl-dspi: Remove unneeded cast to same type Geert Uytterhoeven
2023-03-13 10:58 ` [PATCH 3/6] spi: Constify spi_get_ctldata()'s spi parameter Geert Uytterhoeven
2023-03-13 10:58 ` [PATCH 4/6] spi: Constify spi_get_drvdata()'s " Geert Uytterhoeven
2023-03-13 10:58 ` [PATCH 5/6] spi: Constify spi parameters of chip select APIs Geert Uytterhoeven
2023-03-13 10:58 ` [PATCH 6/6] spi: sh-msiof: Remove casts to drop constness Geert Uytterhoeven
2023-03-13 18:20 ` (subset) [PATCH 0/6] spi: struct spi_device constification Mark Brown

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).