2023-03-13 10:59:01

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH 0/6] spi: struct spi_device constification

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 -- [email protected]

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


2023-03-13 10:59:04

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH 2/6] spi: fsl-dspi: Remove unneeded cast to same type

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

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
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


2023-03-13 10:59:06

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH 4/6] spi: Constify spi_get_drvdata()'s spi parameter

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 <[email protected]>
---
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


2023-03-13 10:59:09

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void *

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

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
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


2023-03-13 18:21:17

by Mark Brown

[permalink] [raw]
Subject: Re: (subset) [PATCH 0/6] spi: struct spi_device constification

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


2023-03-16 16:14:44

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 1/6] mfd: rsmu_spi: Remove unneeded casts of void *

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 <[email protected]>
> ---
> drivers/mfd/rsmu_spi.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

--
Lee Jones [李琼斯]