From: Lothar =?UTF-8?B?V2HDn21hbm4=?= Date: Thu, 18 May 2017 12:20:29 +0200 Subject: [U-Boot] [PATCH V2] pinctrl: imx: fix memory leak In-Reply-To: <4a07d29c-9430-ffcb-b4e7-c92b830e73b6@denx.de> References: <1494495254-7591-1-git-send-email-peng.fan@nxp.com> <4a07d29c-9430-ffcb-b4e7-c92b830e73b6@denx.de> Message-ID: <20170518122029.06087640@ipc1.ka-ro> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi, On Thu, 18 May 2017 11:15:08 +0200 Stefano Babic wrote: > On 11/05/2017 11:34, Peng Fan wrote: > > Each time set_state is called, a new piece memory will > > be allocated for pin_data, but not freed, this will > > incur memory leak. > >=20 > > When error, the devm API could not free memory automatically. > > So need call devm_kfree when error. > >=20 > > Issue reported by Coverity > >=20 > > Signed-off-by: Peng Fan > > Cc: Simon Glass > > Cc: Stefan Agner > > Cc: Stefano Babic > > --- > > drivers/pinctrl/nxp/pinctrl-imx.c | 4 ++++ > > 1 file changed, 4 insertions(+) > >=20 > > diff --git a/drivers/pinctrl/nxp/pinctrl-imx.c b/drivers/pinctrl/nxp/pi= nctrl-imx.c > > index f0321c4..ebc14a3 100644 > > --- a/drivers/pinctrl/nxp/pinctrl-imx.c > > +++ b/drivers/pinctrl/nxp/pinctrl-imx.c > > @@ -53,6 +53,7 @@ static int imx_pinctrl_set_state(struct udevice *dev,= struct udevice *config) > > if (fdtdec_get_int_array(gd->fdt_blob, node, "fsl,pins", > > pin_data, size >> 2)) { > > dev_err(dev, "Error reading pin data.\n"); > > + devm_kfree(dev, pin_data); > > return -EINVAL; > > } > > =20 > > @@ -78,6 +79,7 @@ static int imx_pinctrl_set_state(struct udevice *dev,= struct udevice *config) > > =20 > > if ((mux_reg =3D=3D -1) || (conf_reg =3D=3D -1)) { > > dev_err(dev, "Error mux_reg or conf_reg\n"); > > + devm_kfree(dev, pin_data); > > return -EINVAL; > > } > > =20 > > @@ -166,6 +168,8 @@ static int imx_pinctrl_set_state(struct udevice *de= v, struct udevice *config) > > } > > } > > =20 > > + devm_kfree(dev, pin_data); > > + > > return 0; > > } > > =20 > >=20 >=20 > Applied to u-boot-imx, thanks ! >=20 I had commented on this patch, but unfortunately my mails were rejected by the mailing list server, so the only reached the individuals on CC. IMO the use of the 'devm_' functions is inappropriate here, since the allocated buffer is only used temporarily inside the function and unconditionally freed at function exit. Lothar Wa=C3=9Fmann