From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvmem: core: fix error path in nvmem_add_cells()
Date: Wed, 17 Feb 2016 10:48:54 +0000 [thread overview]
Message-ID: <56C45016.2010806@linaro.org> (raw)
In-Reply-To: <1454965469-6141-1-git-send-email-linux@rasmusvillemoes.dk>
Hi Rasmus,
Thanks for the patch,
On 08/02/16 21:04, Rasmus Villemoes wrote:
> The current code fails to nvmem_cell_drop(cells[0]) - even worse, if
> the loop above fails already at i==0, we'll enter an essentially
> infinite loop doing nvmem_cell_drop on cells[-1], cells[-2], ... which
> is unlikely to end well.
I agree, it would fail in case of zero.
>
> Also, we're not freeing the temporary backing array cells on the error
> path.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> drivers/nvmem/core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 6fd4e5a5ef4a..1e65eccfea83 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -288,9 +288,11 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
>
> return 0;
> err:
> - while (--i)
> + while (i--)
> nvmem_cell_drop(cells[i]);
No, this will not work.
3 issues,
1> If we enter this err path from nvmem_cell_info_to_nvmem_cell()
failures, you would be accessing already freed cells[i].
2> accessing un-allocated cells[i].
3> you would be trying to drop cells which are not in the list.
This is what you need here to fix it correctly.
while (--i >= 0)
>
> + kfree(cells);
This change looks good.
> +
> return rval;
> }
>
>
--srini
next prev parent reply other threads:[~2016-02-17 10:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-08 21:04 [PATCH] nvmem: core: fix error path in nvmem_add_cells() Rasmus Villemoes
2016-02-17 10:48 ` Srinivas Kandagatla [this message]
2016-02-18 5:35 ` Rasmus Villemoes
2016-02-18 9:07 ` Srinivas Kandagatla
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=56C45016.2010806@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=maxime.ripard@free-electrons.com \
/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).