diff mbox

[v1] i2c: aspeed: fixed potential null pointer dereference

Message ID 20170729010012.5032-1-brendanhiggins@google.com
State Accepted
Headers show

Commit Message

Brendan Higgins July 29, 2017, 1 a.m. UTC
Before I skipped null checks when the master is in the STOP state; this
fixes that.

Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
---
 drivers/i2c/busses/i2c-aspeed.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Joel Stanley July 31, 2017, 9:27 a.m. UTC | #1
On Sat, Jul 29, 2017 at 10:30 AM, Brendan Higgins
<brendanhiggins@google.com> wrote:
> Before I skipped null checks when the master is in the STOP state; this
> fixes that.
>
> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>

Acked-by: Joel Stanley <joel@jms.id.au>

Out of interest, was this found by code review, or did you hit this in testing?

Cheers,

Joel

> ---
>  drivers/i2c/busses/i2c-aspeed.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
> index f19348328a71..6fdf9231c23c 100644
> --- a/drivers/i2c/busses/i2c-aspeed.c
> +++ b/drivers/i2c/busses/i2c-aspeed.c
> @@ -410,10 +410,11 @@ static bool aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus)
>         }
>
>         /* We are in an invalid state; reset bus to a known state. */
> -       if (!bus->msgs && bus->master_state != ASPEED_I2C_MASTER_STOP) {
> +       if (!bus->msgs) {
>                 dev_err(bus->dev, "bus in unknown state");
>                 bus->cmd_err = -EIO;
> -               aspeed_i2c_do_stop(bus);
> +               if (bus->master_state != ASPEED_I2C_MASTER_STOP)
> +                       aspeed_i2c_do_stop(bus);
>                 goto out_no_complete;
>         }
>         msg = &bus->msgs[bus->msgs_index];
> --
> 2.14.0.rc0.400.g1c36432dff-goog
>
Brendan Higgins July 31, 2017, 6:20 p.m. UTC | #2
On Mon, Jul 31, 2017 at 2:27 AM, Joel Stanley <joel@jms.id.au> wrote:
> On Sat, Jul 29, 2017 at 10:30 AM, Brendan Higgins
> <brendanhiggins@google.com> wrote:
>> Before I skipped null checks when the master is in the STOP state; this
>> fixes that.
>>
>> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
>
> Acked-by: Joel Stanley <joel@jms.id.au>
>
> Out of interest, was this found by code review, or did you hit this in testing?

I am pretty sure we hit it in testing. Unfortunately, we had trouble reproducing
it, but we did see a null pointer dereference.

>
> Cheers,
>
> Joel
Wolfram Sang Aug. 12, 2017, 11:32 a.m. UTC | #3
On Fri, Jul 28, 2017 at 06:00:12PM -0700, Brendan Higgins wrote:
> Before I skipped null checks when the master is in the STOP state; this
> fixes that.
> 
> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>

Is there a suitable "Fixes:" tag for this?
Joel Stanley Aug. 14, 2017, 3:51 a.m. UTC | #4
On Sat, Aug 12, 2017 at 9:02 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> On Fri, Jul 28, 2017 at 06:00:12PM -0700, Brendan Higgins wrote:
>> Before I skipped null checks when the master is in the STOP state; this
>> fixes that.
>>
>> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
>
> Is there a suitable "Fixes:" tag for this?
>

The driver was introduced in 4.13, so we could add:

Fixes: f327c686d3ba ("i2c: aspeed: added driver for Aspeed I2C")

Cheers,

Joel
Wolfram Sang Aug. 14, 2017, 8:09 p.m. UTC | #5
On Fri, Jul 28, 2017 at 06:00:12PM -0700, Brendan Higgins wrote:
> Before I skipped null checks when the master is in the STOP state; this
> fixes that.
> 
> Signed-off-by: Brendan Higgins <brendanhiggins@google.com>

Applied to for-current, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index f19348328a71..6fdf9231c23c 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -410,10 +410,11 @@  static bool aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus)
 	}
 
 	/* We are in an invalid state; reset bus to a known state. */
-	if (!bus->msgs && bus->master_state != ASPEED_I2C_MASTER_STOP) {
+	if (!bus->msgs) {
 		dev_err(bus->dev, "bus in unknown state");
 		bus->cmd_err = -EIO;
-		aspeed_i2c_do_stop(bus);
+		if (bus->master_state != ASPEED_I2C_MASTER_STOP)
+			aspeed_i2c_do_stop(bus);
 		goto out_no_complete;
 	}
 	msg = &bus->msgs[bus->msgs_index];