linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: use container_of_cont() for to_spi_device()
@ 2025-05-22 10:47 Greg Kroah-Hartman
  2025-05-22 14:11 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Kroah-Hartman @ 2025-05-22 10:47 UTC (permalink / raw)
  To: linux-spi; +Cc: linux-kernel, Greg Kroah-Hartman, Mark Brown

Some places in the spi core pass in a const pointer to a device and the
default container_of() casts that away, which is not a good idea.
Preserve the proper const attribute by using container_of_const() for
to_spi_device() instead, which is what it was designed for.

Note, this removes the NULL check for a device pointer in the call, but
no one was ever checking for that return value, and a device pointer
should never be NULL overall anyway, so this should be a safe change.

Cc: Mark Brown <broonie@kernel.org>
Fixes: d69d80484598 ("driver core: have match() callback in struct bus_type take a const *")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/spi/spi.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 0ba5e49bace4..6e64f0193777 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -249,10 +249,7 @@ struct spi_device {
 static_assert((SPI_MODE_KERNEL_MASK & SPI_MODE_USER_MASK) == 0,
 	      "SPI_MODE_USER_MASK & SPI_MODE_KERNEL_MASK must not overlap");
 
-static inline struct spi_device *to_spi_device(const struct device *dev)
-{
-	return dev ? container_of(dev, struct spi_device, dev) : NULL;
-}
+#define to_spi_device(__dev)	container_of_const(__dev, struct spi_device, dev)
 
 /* Most drivers won't need to care about device refcounting */
 static inline struct spi_device *spi_dev_get(struct spi_device *spi)
-- 
2.49.0


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

* Re: [PATCH] spi: use container_of_cont() for to_spi_device()
  2025-05-22 10:47 [PATCH] spi: use container_of_cont() for to_spi_device() Greg Kroah-Hartman
@ 2025-05-22 14:11 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-05-22 14:11 UTC (permalink / raw)
  To: linux-spi, Greg Kroah-Hartman; +Cc: linux-kernel

On Thu, 22 May 2025 12:47:31 +0200, Greg Kroah-Hartman wrote:
> Some places in the spi core pass in a const pointer to a device and the
> default container_of() casts that away, which is not a good idea.
> Preserve the proper const attribute by using container_of_const() for
> to_spi_device() instead, which is what it was designed for.
> 
> Note, this removes the NULL check for a device pointer in the call, but
> no one was ever checking for that return value, and a device pointer
> should never be NULL overall anyway, so this should be a safe change.
> 
> [...]

Applied to

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

Thanks!

[1/1] spi: use container_of_cont() for to_spi_device()
      commit: 1007ae0d464ceb55a3740634790521d3543aaab9

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] 2+ messages in thread

end of thread, other threads:[~2025-05-22 14:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 10:47 [PATCH] spi: use container_of_cont() for to_spi_device() Greg Kroah-Hartman
2025-05-22 14:11 ` 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).