All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree
@ 2018-07-01 13:51 gregkh
  2018-07-01 20:17 ` Peter Rosin
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2018-07-01 13:51 UTC (permalink / raw)
  To: peda, wsa; +Cc: stable


The patch below does not apply to the 4.17-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

>From 9aa613674f89d01248ae2e4afe691b515ff8fbb6 Mon Sep 17 00:00:00 2001
From: Peter Rosin <peda@axentia.se>
Date: Wed, 20 Jun 2018 11:43:23 +0200
Subject: [PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus
 xfers

If DMA safe memory was allocated, but the subsequent I2C transfer
fails the memory is leaked. Plug this leak.

Fixes: 8a77821e74d6 ("i2c: smbus: use DMA safe buffers for emulated SMBus transactions")
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: stable@kernel.org

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index f3f683041e7f..51970bae3c4a 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
 
 	status = i2c_transfer(adapter, msg, num);
 	if (status < 0)
-		return status;
-	if (status != num)
-		return -EIO;
+		goto cleanup;
+	if (status != num) {
+		status = -EIO;
+		goto cleanup;
+	}
+	status = 0;
 
 	/* Check PEC if last message is a read */
 	if (i && (msg[num-1].flags & I2C_M_RD)) {
 		status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
 		if (status < 0)
-			return status;
+			goto cleanup;
 	}
 
 	if (read_write == I2C_SMBUS_READ)
@@ -499,12 +502,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
 			break;
 		}
 
+cleanup:
 	if (msg[0].flags & I2C_M_DMA_SAFE)
 		kfree(msg[0].buf);
 	if (msg[1].flags & I2C_M_DMA_SAFE)
 		kfree(msg[1].buf);
 
-	return 0;
+	return status;
 }
 
 /**

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree
  2018-07-01 13:51 FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree gregkh
@ 2018-07-01 20:17 ` Peter Rosin
  2018-07-10 14:13   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Rosin @ 2018-07-01 20:17 UTC (permalink / raw)
  To: gregkh, wsa; +Cc: stable

On July 1, 2018 3:51:18 PM GMT+02:00, gregkh@linuxfoundation.org wrote:
>
>The patch below does not apply to the 4.17-stable tree.
>If someone wants it applied there, or to any other stable or longterm
>tree, then please email the backport, including the original git commit
>id to <stable@vger.kernel.org>.

I think it might be enough to also backport 8e03477cb709 ("i2c: core: smbus: fix a potential missing-check bug")?

I have not tested if that is enough though (and am not in a position to easily do so)...

Cheers,
Peter

>thanks,
>
>greg k-h
>
>------------------ original commit in Linus's tree ------------------
>
>>From 9aa613674f89d01248ae2e4afe691b515ff8fbb6 Mon Sep 17 00:00:00 2001
>From: Peter Rosin <peda@axentia.se>
>Date: Wed, 20 Jun 2018 11:43:23 +0200
>Subject: [PATCH] i2c: smbus: kill memory leak on emulated and failed
>DMA SMBus
> xfers
>
>If DMA safe memory was allocated, but the subsequent I2C transfer
>fails the memory is leaked. Plug this leak.
>
>Fixes: 8a77821e74d6 ("i2c: smbus: use DMA safe buffers for emulated
>SMBus transactions")
>Signed-off-by: Peter Rosin <peda@axentia.se>
>Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
>Cc: stable@kernel.org
>
>diff --git a/drivers/i2c/i2c-core-smbus.c
>b/drivers/i2c/i2c-core-smbus.c
>index f3f683041e7f..51970bae3c4a 100644
>--- a/drivers/i2c/i2c-core-smbus.c
>+++ b/drivers/i2c/i2c-core-smbus.c
>@@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct
>i2c_adapter *adapter, u16 addr,
> 
> 	status = i2c_transfer(adapter, msg, num);
> 	if (status < 0)
>-		return status;
>-	if (status != num)
>-		return -EIO;
>+		goto cleanup;
>+	if (status != num) {
>+		status = -EIO;
>+		goto cleanup;
>+	}
>+	status = 0;
> 
> 	/* Check PEC if last message is a read */
> 	if (i && (msg[num-1].flags & I2C_M_RD)) {
> 		status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
> 		if (status < 0)
>-			return status;
>+			goto cleanup;
> 	}
> 
> 	if (read_write == I2C_SMBUS_READ)
>@@ -499,12 +502,13 @@ static s32 i2c_smbus_xfer_emulated(struct
>i2c_adapter *adapter, u16 addr,
> 			break;
> 		}
> 
>+cleanup:
> 	if (msg[0].flags & I2C_M_DMA_SAFE)
> 		kfree(msg[0].buf);
> 	if (msg[1].flags & I2C_M_DMA_SAFE)
> 		kfree(msg[1].buf);
> 
>-	return 0;
>+	return status;
> }
> 
> /**

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree
  2018-07-01 20:17 ` Peter Rosin
@ 2018-07-10 14:13   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2018-07-10 14:13 UTC (permalink / raw)
  To: Peter Rosin; +Cc: wsa, stable

On Sun, Jul 01, 2018 at 10:17:11PM +0200, Peter Rosin wrote:
> On July 1, 2018 3:51:18 PM GMT+02:00, gregkh@linuxfoundation.org wrote:
> >
> >The patch below does not apply to the 4.17-stable tree.
> >If someone wants it applied there, or to any other stable or longterm
> >tree, then please email the backport, including the original git commit
> >id to <stable@vger.kernel.org>.
> 
> I think it might be enough to also backport 8e03477cb709 ("i2c: core: smbus: fix a potential missing-check bug")?
> 
> I have not tested if that is enough though (and am not in a position to easily do so)...

Yes, that worked, thanks!

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-10 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-01 13:51 FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree gregkh
2018-07-01 20:17 ` Peter Rosin
2018-07-10 14:13   ` Greg KH

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.