linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: Amit Kucheria <amit.kucheria@linaro.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Linux PM list <linux-pm@vger.kernel.org>,
	Eduardo Valentin <edubezval@gmail.com>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read
Date: Wed, 28 Aug 2019 21:05:51 +0800	[thread overview]
Message-ID: <961b814b345ee765408b85861ec3c37d01857c0a.camel@intel.com> (raw)
In-Reply-To: <CAP245DVf9fZNVEaYS39_NZ133LbwuZ77i=2fHUs-u_r-5EK-3Q@mail.gmail.com>

On Fri, 2019-08-23 at 17:29 +0530, Amit Kucheria wrote:
> On Fri, Aug 23, 2019 at 3:08 PM Srinivas Kandagatla
> <srinivas.kandagatla@linaro.org> wrote:
> > 
> > memory returned as part of nvmem_read via qfprom_read should be
> > freed by the consumer once done.
> > Existing code is not doing it so fix it.
> > 
> > Below memory leak detected by kmemleak
> >    [<ffffff80088b7658>] kmemleak_alloc+0x50/0x84
> >     [<ffffff80081df120>] __kmalloc+0xe8/0x168
> >     [<ffffff80086db350>] nvmem_cell_read+0x30/0x80
> >     [<ffffff8008632790>] qfprom_read+0x4c/0x7c
> >     [<ffffff80086335a4>] calibrate_v1+0x34/0x204
> >     [<ffffff8008632518>] tsens_probe+0x164/0x258
> >     [<ffffff80084e0a1c>] platform_drv_probe+0x80/0xa0
> >     [<ffffff80084de4f4>] really_probe+0x208/0x248
> >     [<ffffff80084de2c4>] driver_probe_device+0x98/0xc0
> >     [<ffffff80084dec54>] __device_attach_driver+0x9c/0xac
> >     [<ffffff80084dca74>] bus_for_each_drv+0x60/0x8c
> >     [<ffffff80084de634>] __device_attach+0x8c/0x100
> >     [<ffffff80084de6c8>] device_initial_probe+0x20/0x28
> >     [<ffffff80084dcbb8>] bus_probe_device+0x34/0x7c
> >     [<ffffff80084deb08>] deferred_probe_work_func+0x6c/0x98
> >     [<ffffff80080c3da8>] process_one_work+0x160/0x2f8
> > 
> > Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 
> Acked-by: Amit Kucheria <amit.kucheria@linaro.org>

patch applied.

thanks,
rui
> 
> > ---
> >  drivers/thermal/qcom/tsens-8960.c |  2 ++
> >  drivers/thermal/qcom/tsens-v0_1.c | 12 ++++++++++--
> >  drivers/thermal/qcom/tsens-v1.c   |  1 +
> >  drivers/thermal/qcom/tsens.h      |  1 +
> >  4 files changed, 14 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/thermal/qcom/tsens-8960.c
> > b/drivers/thermal/qcom/tsens-8960.c
> > index 8d9b721dadb6..e46a4e3f25c4 100644
> > --- a/drivers/thermal/qcom/tsens-8960.c
> > +++ b/drivers/thermal/qcom/tsens-8960.c
> > @@ -229,6 +229,8 @@ static int calibrate_8960(struct tsens_priv
> > *priv)
> >         for (i = 0; i < num_read; i++, s++)
> >                 s->offset = data[i];
> > 
> > +       kfree(data);
> > +
> >         return 0;
> >  }
> > 
> > diff --git a/drivers/thermal/qcom/tsens-v0_1.c
> > b/drivers/thermal/qcom/tsens-v0_1.c
> > index 6f26fadf4c27..055647bcee67 100644
> > --- a/drivers/thermal/qcom/tsens-v0_1.c
> > +++ b/drivers/thermal/qcom/tsens-v0_1.c
> > @@ -145,8 +145,10 @@ static int calibrate_8916(struct tsens_priv
> > *priv)
> >                 return PTR_ERR(qfprom_cdata);
> > 
> >         qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
> > -       if (IS_ERR(qfprom_csel))
> > +       if (IS_ERR(qfprom_csel)) {
> > +               kfree(qfprom_cdata);
> >                 return PTR_ERR(qfprom_csel);
> > +       }
> > 
> >         mode = (qfprom_csel[0] & MSM8916_CAL_SEL_MASK) >>
> > MSM8916_CAL_SEL_SHIFT;
> >         dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> > @@ -181,6 +183,8 @@ static int calibrate_8916(struct tsens_priv
> > *priv)
> >         }
> > 
> >         compute_intercept_slope(priv, p1, p2, mode);
> > +       kfree(qfprom_cdata);
> > +       kfree(qfprom_csel);
> > 
> >         return 0;
> >  }
> > @@ -198,8 +202,10 @@ static int calibrate_8974(struct tsens_priv
> > *priv)
> >                 return PTR_ERR(calib);
> > 
> >         bkp = (u32 *)qfprom_read(priv->dev, "calib_backup");
> > -       if (IS_ERR(bkp))
> > +       if (IS_ERR(bkp)) {
> > +               kfree(calib);
> >                 return PTR_ERR(bkp);
> > +       }
> > 
> >         calib_redun_sel =  bkp[1] & BKP_REDUN_SEL;
> >         calib_redun_sel >>= BKP_REDUN_SHIFT;
> > @@ -313,6 +319,8 @@ static int calibrate_8974(struct tsens_priv
> > *priv)
> >         }
> > 
> >         compute_intercept_slope(priv, p1, p2, mode);
> > +       kfree(calib);
> > +       kfree(bkp);
> > 
> >         return 0;
> >  }
> > diff --git a/drivers/thermal/qcom/tsens-v1.c
> > b/drivers/thermal/qcom/tsens-v1.c
> > index 10b595d4f619..870f502f2cb6 100644
> > --- a/drivers/thermal/qcom/tsens-v1.c
> > +++ b/drivers/thermal/qcom/tsens-v1.c
> > @@ -138,6 +138,7 @@ static int calibrate_v1(struct tsens_priv
> > *priv)
> >         }
> > 
> >         compute_intercept_slope(priv, p1, p2, mode);
> > +       kfree(qfprom_cdata);
> > 
> >         return 0;
> >  }
> > diff --git a/drivers/thermal/qcom/tsens.h
> > b/drivers/thermal/qcom/tsens.h
> > index 2fd94997245b..b89083b61c38 100644
> > --- a/drivers/thermal/qcom/tsens.h
> > +++ b/drivers/thermal/qcom/tsens.h
> > @@ -17,6 +17,7 @@
> > 
> >  #include <linux/thermal.h>
> >  #include <linux/regmap.h>
> > +#include <linux/slab.h>
> > 
> >  struct tsens_priv;
> > 
> > --
> > 2.21.0
> > 


      reply	other threads:[~2019-08-28 13:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23  9:38 [PATCH] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read Srinivas Kandagatla
2019-08-23 11:59 ` Amit Kucheria
2019-08-28 13:05   ` Zhang Rui [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=961b814b345ee765408b85861ec3c37d01857c0a.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=amit.kucheria@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).