From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr00105.outbound.protection.outlook.com ([40.107.0.105]:33472 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752473AbeGAURQ (ORCPT ); Sun, 1 Jul 2018 16:17:16 -0400 Date: Sun, 01 Jul 2018 22:17:11 +0200 In-Reply-To: <153045307884101@kroah.com> References: <153045307884101@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: FAILED: patch "[PATCH] i2c: smbus: kill memory leak on emulated and failed DMA SMBus" failed to apply to 4.17-stable tree To: gregkh@linuxfoundation.org, wsa@the-dreams.de CC: stable@vger.kernel.org From: Peter Rosin Message-ID: <6A48488A-0A66-4745-8956-F90A55003AAD@axentia.se> Sender: stable-owner@vger.kernel.org List-ID: On July 1, 2018 3:51:18 PM GMT+02:00, gregkh@linuxfoundation=2Eorg wrote: > >The patch below does not apply to the 4=2E17-stable tree=2E >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 =2E I think it might be enough to also backport 8e03477cb709 ("i2c: core: smbu= s: fix a potential missing-check bug")? I have not tested if that is enough though (and am not in a position to ea= sily do so)=2E=2E=2E Cheers, Peter >thanks, > >greg k-h > >------------------ original commit in Linus's tree ------------------ > >>>From 9aa613674f89d01248ae2e4afe691b515ff8fbb6 Mon Sep 17 00:00:00 2001 >From: Peter Rosin >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=2E Plug this leak=2E > >Fixes: 8a77821e74d6 ("i2c: smbus: use DMA safe buffers for emulated >SMBus transactions") >Signed-off-by: Peter Rosin >Signed-off-by: Wolfram Sang >Cc: stable@kernel=2Eorg > >diff --git a/drivers/i2c/i2c-core-smbus=2Ec >b/drivers/i2c/i2c-core-smbus=2Ec >index f3f683041e7f=2E=2E51970bae3c4a 100644 >--- a/drivers/i2c/i2c-core-smbus=2Ec >+++ b/drivers/i2c/i2c-core-smbus=2Ec >@@ -465,15 +465,18 @@ static s32 i2c_smbus_xfer_emulated(struct >i2c_adapter *adapter, u16 addr, >=20 > status =3D i2c_transfer(adapter, msg, num); > if (status < 0) >- return status; >- if (status !=3D num) >- return -EIO; >+ goto cleanup; >+ if (status !=3D num) { >+ status =3D -EIO; >+ goto cleanup; >+ } >+ status =3D 0; >=20 > /* Check PEC if last message is a read */ > if (i && (msg[num-1]=2Eflags & I2C_M_RD)) { > status =3D i2c_smbus_check_pec(partial_pec, &msg[num-1]); > if (status < 0) >- return status; >+ goto cleanup; > } >=20 > if (read_write =3D=3D I2C_SMBUS_READ) >@@ -499,12 +502,13 @@ static s32 i2c_smbus_xfer_emulated(struct >i2c_adapter *adapter, u16 addr, > break; > } >=20 >+cleanup: > if (msg[0]=2Eflags & I2C_M_DMA_SAFE) > kfree(msg[0]=2Ebuf); > if (msg[1]=2Eflags & I2C_M_DMA_SAFE) > kfree(msg[1]=2Ebuf); >=20 >- return 0; >+ return status; > } >=20 > /**