Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Marcin Nowakowski <marcin.nowakowski@mips.com>
To: Mathieu Malaterre <malat@debian.org>, <Zubair.Kakakhel@mips.com>
Cc: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
	"Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Ralf Baechle <ralf@linux-mips.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	Paul Cercueil <paul@crapouillou.net>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	Harvey Hunt <harvey.hunt@imgtec.com>,
	James Hogan <jhogan@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-mips@linux-mips.org>
Subject: Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse
Date: Thu, 28 Dec 2017 08:13:33 +0100	[thread overview]
Message-ID: <bbc64846-e12e-aea8-c516-5e03f6253fed@mips.com> (raw)
In-Reply-To: <20171227122722.5219-2-malat@debian.org>

Hi Mathieu, PrasannaKumar,

On 27.12.2017 13:27, Mathieu Malaterre wrote:
> From: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
> 
> This patch brings support for the JZ4780 efuse. Currently it only expose
> a read only access to the entire 8K bits efuse memory.
> 
> Tested-by: Mathieu Malaterre <malat@debian.org>
> Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
> ---

> +
> +/* main entry point */
> +static int jz4780_efuse_read(void *context, unsigned int offset,
> +					void *val, size_t bytes)
> +{
> +	static const int nsegments = sizeof(segments) / sizeof(*segments);
> +	struct jz4780_efuse *efuse = context;
> +	char buf[32];
> +	char *cur = val;
> +	int i;
> +	/* PM recommends read/write each segment separately */
> +	for (i = 0; i < nsegments; ++i) {
> +		unsigned int *segment = segments[i];
> +		unsigned int lpos = segment[0];
> +		unsigned int buflen = segment[1] / 8;
> +		unsigned int ncount = buflen / 32;
> +		unsigned int remain = buflen % 32;
> +		int j;

This doesn't look right, as offset & bytes are completely ignored. This 
means it will return data from an offset other than requested and may 
also overrun the provided output buffer?

> +		/* EFUSE can read or write maximum 256bit in each time */
> +		for (j = 0; j < ncount ; ++j) {
> +			jz4780_efuse_read_32bytes(efuse, buf, lpos);
> +			memcpy(cur, buf, sizeof(buf));
> +			cur += sizeof(buf);
> +			lpos += sizeof(buf);
> +			}
> +		if (remain) {
> +			jz4780_efuse_read_32bytes(efuse, buf, lpos);
> +			memcpy(cur, buf, remain);
> +			cur += remain;
> +			}
> +		}
> +
> +	return 0;
> +}


Marcin

WARNING: multiple messages have this Message-ID (diff)
From: Marcin Nowakowski <marcin.nowakowski@mips.com>
To: Mathieu Malaterre <malat@debian.org>, Zubair.Kakakhel@mips.com
Cc: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Ralf Baechle <ralf@linux-mips.org>,
	"David S. Miller" <davem@davemloft.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul Cercueil <paul@crapouillou.net>,
	Linus Walleij <linus.walleij@linaro.org>,
	Harvey Hunt <harvey.hunt@imgtec.com>,
	James Hogan <jhogan@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-mips@linux-mips.org
Subject: Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse
Date: Thu, 28 Dec 2017 08:13:33 +0100	[thread overview]
Message-ID: <bbc64846-e12e-aea8-c516-5e03f6253fed@mips.com> (raw)
Message-ID: <20171228071333.T9f8kqXDFBd1WFVdJA4dZsAvgkZbVmRIoUmx1y8un0M@z> (raw)
In-Reply-To: <20171227122722.5219-2-malat@debian.org>

Hi Mathieu, PrasannaKumar,

On 27.12.2017 13:27, Mathieu Malaterre wrote:
> From: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
> 
> This patch brings support for the JZ4780 efuse. Currently it only expose
> a read only access to the entire 8K bits efuse memory.
> 
> Tested-by: Mathieu Malaterre <malat@debian.org>
> Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
> ---

> +
> +/* main entry point */
> +static int jz4780_efuse_read(void *context, unsigned int offset,
> +					void *val, size_t bytes)
> +{
> +	static const int nsegments = sizeof(segments) / sizeof(*segments);
> +	struct jz4780_efuse *efuse = context;
> +	char buf[32];
> +	char *cur = val;
> +	int i;
> +	/* PM recommends read/write each segment separately */
> +	for (i = 0; i < nsegments; ++i) {
> +		unsigned int *segment = segments[i];
> +		unsigned int lpos = segment[0];
> +		unsigned int buflen = segment[1] / 8;
> +		unsigned int ncount = buflen / 32;
> +		unsigned int remain = buflen % 32;
> +		int j;

This doesn't look right, as offset & bytes are completely ignored. This 
means it will return data from an offset other than requested and may 
also overrun the provided output buffer?

> +		/* EFUSE can read or write maximum 256bit in each time */
> +		for (j = 0; j < ncount ; ++j) {
> +			jz4780_efuse_read_32bytes(efuse, buf, lpos);
> +			memcpy(cur, buf, sizeof(buf));
> +			cur += sizeof(buf);
> +			lpos += sizeof(buf);
> +			}
> +		if (remain) {
> +			jz4780_efuse_read_32bytes(efuse, buf, lpos);
> +			memcpy(cur, buf, remain);
> +			cur += remain;
> +			}
> +		}
> +
> +	return 0;
> +}


Marcin

  reply	other threads:[~2017-12-28  7:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-27 12:27 [PATCH 0/2] Add efuse driver for Ingenic JZ4780 SoC Mathieu Malaterre
2017-12-27 12:27 ` [PATCH 1/2] nvmem: add driver for JZ4780 efuse Mathieu Malaterre
2017-12-28  7:13   ` Marcin Nowakowski [this message]
2017-12-28  7:13     ` Marcin Nowakowski
     [not found]     ` <CA+7wUsxM4Cq-K6ONSO-WzmYYvq8PmT92Jfrf7M-MqY-ntObi-g@mail.gmail.com>
2017-12-28  8:05       ` Marcin Nowakowski
2017-12-28  8:05         ` Marcin Nowakowski
2018-01-06 11:52         ` PrasannaKumar Muralidharan
2017-12-27 12:27 ` [PATCH 2/2] dts: Probe efuse for CI20 Mathieu Malaterre
2017-12-27 12:46   ` Greg Kroah-Hartman

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=bbc64846-e12e-aea8-c516-5e03f6253fed@mips.com \
    --to=marcin.nowakowski@mips.com \
    --cc=Zubair.Kakakhel@mips.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=harvey.hunt@imgtec.com \
    --cc=jhogan@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=malat@debian.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=paul@crapouillou.net \
    --cc=prasannatsmkumar@gmail.com \
    --cc=ralf@linux-mips.org \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tglx@linutronix.de \
    /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