diff mbox

[U-Boot] spmi: Fix sandbox spmi driver memory corruption

Message ID 1459792559-24652-1-git-send-email-mateusz.kulikowski@gmail.com
State Accepted
Commit aafa64827f30a7d2aa2c2cc2a60906eabd0272b8
Delegated to: Tom Rini
Headers show

Commit Message

Mateusz Kulikowski April 4, 2016, 5:55 p.m. UTC
There is off-by-one error in sandbox_emul_gpio that causes
segfault of certain tests.

EMUL_GPIO_REG_END is the address of last valid (emulated) register.
This patch fixed this (by adding one more element to emulated register array).

Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
---

 drivers/spmi/spmi-sandbox.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stephen Warren April 4, 2016, 6:06 p.m. UTC | #1
On 04/04/2016 11:55 AM, Mateusz Kulikowski wrote:
> There is off-by-one error in sandbox_emul_gpio that causes
> segfault of certain tests.
>
> EMUL_GPIO_REG_END is the address of last valid (emulated) register.
> This patch fixed this (by adding one more element to emulated register array).

Tested-by: Stephen Warren <swarren@nvidia.com>
Tom Rini April 12, 2016, 2:29 a.m. UTC | #2
On Mon, Apr 04, 2016 at 07:55:58PM +0200, Mateusz Kulikowski wrote:

> There is off-by-one error in sandbox_emul_gpio that causes
> segfault of certain tests.
> 
> EMUL_GPIO_REG_END is the address of last valid (emulated) register.
> This patch fixed this (by adding one more element to emulated register array).
> 
> Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
> Tested-by: Stephen Warren <swarren@nvidia.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/drivers/spmi/spmi-sandbox.c b/drivers/spmi/spmi-sandbox.c
index 2f0fea0..980aff2 100644
--- a/drivers/spmi/spmi-sandbox.c
+++ b/drivers/spmi/spmi-sandbox.c
@@ -35,7 +35,8 @@  struct sandbox_emul_fake_regs {
 };
 
 struct sandbox_emul_gpio {
-	struct sandbox_emul_fake_regs r[EMUL_GPIO_REG_END]; /* Fake registers */
+	/* Fake registers - need one more entry as REG_END is valid address. */
+	struct sandbox_emul_fake_regs r[EMUL_GPIO_REG_END + 1];
 };
 
 struct sandbox_spmi_priv {