devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leonard Crestez <leonard.crestez-3arQi8VN3Tc@public.gmane.org>
To: Srinivas Kandagatla
	<srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: "Shawn Guo" <shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Zhang Rui" <rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	"Eduardo Valentin"
	<edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Mark Rutland" <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	"Lothar Waßmann"
	<LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org>,
	"Fabio Estevam" <fabio.estevam-3arQi8VN3Tc@public.gmane.org>,
	"Dong Aisheng" <aisheng.dong-3arQi8VN3Tc@public.gmane.org>,
	"Bai Ping" <ping.bai-3arQi8VN3Tc@public.gmane.org>,
	"Anson Huang" <Anson.Huang-3arQi8VN3Tc@public.gmane.org>,
	"Octavian Purdila"
	<octavian.purdila-3arQi8VN3Tc@public.gmane.org>,
	linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 2/4] thermal: imx: Add support for reading OCOTP through nvmem
Date: Fri, 14 Jul 2017 13:49:48 +0300	[thread overview]
Message-ID: <1500029388.11612.54.camel@nxp.com> (raw)
In-Reply-To: <3dd43cba-02f2-204c-c3a2-582827018ef8-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

On Fri, 2017-07-14 at 09:48 +0100, Srinivas Kandagatla wrote:
> On 12/07/17 07:36, Shawn Guo wrote:

> > > +static int nvmem_cell_read_u32(struct device* dev, const char *cell_id, u32 *val)
> > > +{
> > > +	struct nvmem_cell *cell;
> > > +	void *buf;
> > > +	size_t len;
> > > +
> > > +	cell = nvmem_cell_get(dev, cell_id);
> > > +	if (IS_ERR(cell))
> > > +		return PTR_ERR(cell);
> > > +
> > > +	buf = nvmem_cell_read(cell, &len);
> > > +	if (IS_ERR(buf)) {
> > > +		nvmem_cell_put(cell);
> > > +		return PTR_ERR(buf);
> > > +	}
> > > +	if (len != sizeof(*val)) {
> > > +		kfree(buf);
> > > +		nvmem_cell_put(cell);
> > > +		return -EINVAL;
> > > +	}
> > > +	memcpy(val, buf, sizeof(*val));

> This can overflow the memory allocated to val, we should be careful here 
> not to do so.
> limit this to sizeof(u32) should be good. Also add some sanity checks to 
> make sure that len is atleast 4 bytes.

I'm not sure what you mean, isn't this already done? There is an
explicit check above that the read len is exactly as expected. It's
just that the limit is written as sizeof(*val) rather than sizeof(u32).

> > > +
> > > +	kfree(buf);
> > > +	nvmem_cell_put(cell);
> > > +	return 0;
> > > +}
> > The function looks nothing IMX specific, and could be a nvmem core
> > function?
> > 
> > @Srinivas, thoughts?
> Yep, this function looks generic, can be moved to nvmem layer.

Ok, next version of the series will have this function in nvmem core as
a separate commit.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-07-14 10:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 13:20 [PATCH 0/4] thermal: imx: Add nvmem-cells binding on imx6sx Leonard Crestez
     [not found] ` <cover.1499347157.git.leonard.crestez-3arQi8VN3Tc@public.gmane.org>
2017-07-06 13:20   ` [PATCH 1/4] thermal: imx: Add nvmem-cells alternate binding for OCOTP access Leonard Crestez
2017-07-10 13:29     ` Rob Herring
2017-07-06 13:20 ` [PATCH 2/4] thermal: imx: Add support for reading OCOTP through nvmem Leonard Crestez
     [not found]   ` <68b476b35b0c0cbce21da0e87338323bb77e9bc4.1499347157.git.leonard.crestez-3arQi8VN3Tc@public.gmane.org>
2017-07-12  6:36     ` Shawn Guo
2017-07-14  8:48       ` Srinivas Kandagatla
     [not found]         ` <3dd43cba-02f2-204c-c3a2-582827018ef8-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-07-14 10:49           ` Leonard Crestez [this message]
2017-07-14 10:54             ` Srinivas Kandagatla
2017-07-06 13:20 ` [PATCH 3/4] ARM: dts: imx6sx: Use nvmem-cells for tempmon Leonard Crestez
     [not found]   ` <6dc9bb756daf75bb26648b06b204872f71b3a548.1499347157.git.leonard.crestez-3arQi8VN3Tc@public.gmane.org>
2017-07-12  6:40     ` Shawn Guo
2017-07-06 13:20 ` [PATCH 4/4] ARM: dts: imx6ul: Add imx6ul-tempmon Leonard Crestez

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=1500029388.11612.54.camel@nxp.com \
    --to=leonard.crestez-3arqi8vn3tc@public.gmane.org \
    --cc=Anson.Huang-3arQi8VN3Tc@public.gmane.org \
    --cc=LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org \
    --cc=aisheng.dong-3arQi8VN3Tc@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=edubezval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=fabio.estevam-3arQi8VN3Tc@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=octavian.purdila-3arQi8VN3Tc@public.gmane.org \
    --cc=ping.bai-3arQi8VN3Tc@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=rui.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.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).