提交 b4b84826 编写于 作者: R Roland Stigge 提交者: Mark Brown

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.
Reported-by: NShiraz Hashim <shiraz.linux.kernel@gmail.com>
Signed-off-by: NRoland Stigge <stigge@antcom.de>
Reviewed-by: NLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
上级 38e271cd
...@@ -2053,8 +2053,7 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -2053,8 +2053,7 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
} }
/* Allocate master with space for data */ /* Allocate master with space for data */
master = spi_alloc_master(dev, sizeof(struct pl022) + sizeof(int) * master = spi_alloc_master(dev, sizeof(struct pl022));
num_cs);
if (master == NULL) { if (master == NULL) {
dev_err(&adev->dev, "probe - cannot alloc SPI master\n"); dev_err(&adev->dev, "probe - cannot alloc SPI master\n");
status = -ENOMEM; status = -ENOMEM;
...@@ -2066,8 +2065,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -2066,8 +2065,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
pl022->master_info = platform_info; pl022->master_info = platform_info;
pl022->adev = adev; pl022->adev = adev;
pl022->vendor = id->data; pl022->vendor = id->data;
/* Point chipselects to allocated memory beyond the main struct */ pl022->chipselects = devm_kzalloc(dev, num_cs * sizeof(int),
pl022->chipselects = (int *) pl022 + sizeof(struct pl022); GFP_KERNEL);
/* /*
* Bus Number Which has been Assigned to this SSP controller * Bus Number Which has been Assigned to this SSP controller
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册