From: srinivas.kandagatla@linaro.org (Srinivas Kandagatla)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 3/4] nvmem: add a driver for the Amlogic Meson6/Meson8/Meson8b SoCs
Date: Mon, 9 Oct 2017 11:36:23 +0100 [thread overview]
Message-ID: <dc3200f3-34cd-f531-0a0b-9b856a84cd52@linaro.org> (raw)
In-Reply-To: <cd1e7f9c-5aff-8f4c-82b0-c58c2de4c253@free.fr>
On 03/10/17 05:48, Chris Moore wrote:
> Hi,
>
> Sorry in advance if I am being extremely stupid here.
>
> Le 01/10/2017 ? 14:56, Martin Blumenstingl a ?crit :
>
> [snip]
>
>> +static int meson_mx_efuse_read(void *context, unsigned int offset,
>> + void *buf, size_t bytes)
>> +{
>> + struct meson_mx_efuse *efuse = context;
>> + u32 tmp;
>> + int err, i, addr;
>> +
>> + err = meson_mx_efuse_hw_enable(efuse);
>> + if (err)
>> + return err;
>> +
>> + meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1,
>> + MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE,
>> + MESON_MX_EFUSE_CNTL1_AUTO_RD_ENABLE);
>> +
>> + for (i = offset; i < offset + bytes; i += efuse->config.word_size) {
>> + addr = i / efuse->config.word_size;
>> +
>> + err = meson_mx_efuse_read_addr(efuse, addr, &tmp);
>> + if (err)
>> + break;
>> +
>> + memcpy(buf + i, &tmp, efuse->config.word_size);
>> + }
>
> This will not give the expected result if offset is not a multiple of
> efuse->config.word_size.
Offset should be always multiple of stride which is enforced in nvmem core.
nvmem_cell would return an -EINVAL if that is not the case.
--srini
> This will cause buffer overflow if bytes is not a multiple of
> efuse->config.word_size.
> Shouldn't there at least be some sort of test on offset and bytes?
>
> Also this doesn't look endian-safe, but maybe it is.
>
> Old-timer remarks:
> - I try to avoid divisions where possible but I suppose they are very
> low-cost on recent hardware.
> - I don't like arithmetic on void pointers but I know it is supported by
> gcc (and possibly by recent C standards too).
>
> Sorry again for the noise if I am being stupid.
>
> Cheers,
> Chris
>
next prev parent reply other threads:[~2017-10-09 10:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-01 12:56 [PATCH 0/4] Amlogic Meson6/Meson8/Meson8b efuse support Martin Blumenstingl
2017-10-01 12:56 ` [PATCH 1/4] dt-bindings: nvmem: Describe the Amlogic Meson6/Meson8/Meson8b efuse Martin Blumenstingl
2017-10-01 12:56 ` [PATCH 2/4] nvmem: meson-efuse: indicate that this driver is only for Meson GX SoCs Martin Blumenstingl
2017-10-01 12:56 ` [PATCH 3/4] nvmem: add a driver for the Amlogic Meson6/Meson8/Meson8b SoCs Martin Blumenstingl
2017-10-02 15:28 ` Srinivas Kandagatla
2017-10-02 18:38 ` Martin Blumenstingl
2017-10-03 4:48 ` Chris Moore
2017-10-03 11:14 ` Martin Blumenstingl
2017-10-09 10:36 ` Srinivas Kandagatla [this message]
2017-10-01 12:57 ` [PATCH 4/4] ARM: dts: meson: add the efuse node Martin Blumenstingl
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=dc3200f3-34cd-f531-0a0b-9b856a84cd52@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=linus-amlogic@lists.infradead.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
all inboxes | Powered by JetHome®