* [PATCH] spi/pl022: Fix chipselects pointer computation
@ 2012-09-03 8:14 ` Roland Stigge
0 siblings, 0 replies; 4+ messages in thread
From: Roland Stigge @ 2012-09-03 8:14 UTC (permalink / raw)
To: linus.walleij-QSEj5FYQhm4dnm+yROfE0A,
shiraz.linux.kernel-Re5JQEeQqe8AvxtiuMwx3w,
aletes.xgr-Re5JQEeQqe8AvxtiuMwx3w,
broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
linux-doc-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
gabriel.fernandez-0IS4wlFg1OjSUeElwK9/Pw,
lee.jones-QSEj5FYQhm4dnm+yROfE0A,
viresh.kumar-QSEj5FYQhm4dnm+yROfE0A, sachin.verma-lpHj6iFQ3dU
Cc: 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 <stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
---
drivers/spi/spi-pl022.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--- linux-2.6.orig/drivers/spi/spi-pl022.c
+++ linux-2.6/drivers/spi/spi-pl022.c
@@ -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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] spi/pl022: Fix chipselects pointer computation
@ 2012-09-03 8:14 ` Roland Stigge
0 siblings, 0 replies; 4+ messages in thread
From: Roland Stigge @ 2012-09-03 8:14 UTC (permalink / raw)
To: linus.walleij, shiraz.linux.kernel, aletes.xgr, broonie,
grant.likely, rob.herring, rob, linux-doc, linux-kernel,
spi-devel-general, gabriel.fernandez, lee.jones, viresh.kumar,
sachin.verma
Cc: 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 <stigge@antcom.de>
---
drivers/spi/spi-pl022.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--- linux-2.6.orig/drivers/spi/spi-pl022.c
+++ linux-2.6/drivers/spi/spi-pl022.c
@@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] spi/pl022: Fix chipselects pointer computation
2012-09-03 8:14 ` Roland Stigge
(?)
@ 2012-09-03 9:11 ` Linus Walleij
-1 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2012-09-03 9:11 UTC (permalink / raw)
To: Roland Stigge, broonie
Cc: shiraz.linux.kernel, aletes.xgr, grant.likely, rob.herring, rob,
linux-doc, linux-kernel, spi-devel-general, gabriel.fernandez,
lee.jones, viresh.kumar, sachin.verma
On Mon, Sep 3, 2012 at 10:14 AM, Roland Stigge <stigge@antcom.de> wrote:
> 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 <stigge@antcom.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Thanks for fixing this! And thanks to Shiraz for spotting the problem,
Mark you could add a:
Reported-by: Shiraz Hashim <shiraz.linux.kernel@gmail.com>
when applying this.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] spi/pl022: Fix chipselects pointer computation
2012-09-03 8:14 ` Roland Stigge
(?)
(?)
@ 2012-09-05 23:44 ` Mark Brown
-1 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-09-05 23:44 UTC (permalink / raw)
To: Roland Stigge
Cc: linus.walleij, shiraz.linux.kernel, aletes.xgr, grant.likely,
rob.herring, rob, linux-doc, linux-kernel, spi-devel-general,
gabriel.fernandez, lee.jones, viresh.kumar, sachin.verma
On Mon, Sep 03, 2012 at 10:14:29AM +0200, Roland Stigge wrote:
> The new chip select handling via GPIO introduced a pointer computation bug:
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-05 23:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-03 8:14 [PATCH] spi/pl022: Fix chipselects pointer computation Roland Stigge
2012-09-03 8:14 ` Roland Stigge
2012-09-03 9:11 ` Linus Walleij
2012-09-05 23:44 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.