Skip to content

Commit 1007ae0

Browse files
gregkhbroonie
authored andcommitted
spi: use container_of_cont() for to_spi_device()
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 <[email protected]> Fixes: d69d804 ("driver core: have match() callback in struct bus_type take a const *") Signed-off-by: Greg Kroah-Hartman <[email protected]> Link: https://patch.msgid.link/2025052230-fidgeting-stooge-66f5@gregkh Signed-off-by: Mark Brown <[email protected]>
1 parent a5806cd commit 1007ae0

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

include/linux/spi/spi.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,7 @@ struct spi_device {
249249
static_assert((SPI_MODE_KERNEL_MASK & SPI_MODE_USER_MASK) == 0,
250250
"SPI_MODE_USER_MASK & SPI_MODE_KERNEL_MASK must not overlap");
251251

252-
static inline struct spi_device *to_spi_device(const struct device *dev)
253-
{
254-
return dev ? container_of(dev, struct spi_device, dev) : NULL;
255-
}
252+
#define to_spi_device(__dev) container_of_const(__dev, struct spi_device, dev)
256253

257254
/* Most drivers won't need to care about device refcounting */
258255
static inline struct spi_device *spi_dev_get(struct spi_device *spi)

0 commit comments

Comments
 (0)