spi/pl022: Fix chipselects pointer computation
Subsystems (2)
PATCH 1/1 spi/pl022: Fix chipselects pointer computation
The new chip select handling via GPIO introduced a pointer computation bug:
(int *) pl022 + sizeof(struct pl022)
doesn't point to the data immediately after the actual struct pl022 (as was intended) but to a multiple of bytes after it because of the (int *) type.
Replacing the kludgy pointer arithmetic with managed memory allocation for the chip selects.
--- drivers/spi/spi-pl022.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/spi/spi-pl022.c +3 -4
@@ -2053,8 +2053,7 @@ pl022_probe(struct amba_device *adev, co }/* Allocate master with space for data */ - master =spi_alloc_master (dev,sizeof (struct pl022 ) +sizeof (int ) * - num_cs); + master =spi_alloc_master (dev,sizeof (struct pl022 ));if (master ==NULL ) {dev_err (&adev->dev,"probe - cannot alloc SPI master\n" ); status = -ENOMEM ;
@@ -2066,8 +2065,8 @@ pl022_probe(struct amba_device *adev, co pl022->master_info = platform_info; pl022->adev = adev; pl022->vendor = id->data; -/* Point chipselects to allocated memory beyond the main struct */ - pl022->chipselects = (int *) pl022 +sizeof (struct pl022 ); + pl022->chipselects =devm_kzalloc (dev, num_cs *sizeof (int ), +GFP_KERNEL );/* * Bus Number Which has been Assigned to this SSP controller
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Quoted 11 lines · Roland Stigge
The new chip select handling via GPIO introduced a pointer computation bug:
(int *) pl022 + sizeof(struct pl022)doesn't point to the data immediately after the actual struct pl022 (as was intended) but to a multiple of bytes after it because of the (int *) type.
Replacing the kludgy pointer arithmetic with managed memory allocation for the chip selects.
Signed-off-by Roland Stigge <[email protected]>
Thanks for fixing this! And thanks to Shiraz for spotting the problem, Mark you could add a:
when applying this.
Yours,
Linus Walleij
Mark Brown
AppliedQuoted 1 line · Roland Stigge
The new chip select handling via GPIO introduced a pointer computation bug:
Applied, thanks.