From: John Garry <john.garry@huawei.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: <linux-kernel@vger.kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddeodr.com>
Subject: Re: [PATCH] lib: logic_pio: Fix potential NULL pointer dereference
Date: Wed, 4 Apr 2018 09:54:04 +0100 [thread overview]
Message-ID: <c5cc072b-88cb-979c-3645-9b59319dd511@huawei.com> (raw)
In-Reply-To: <20180403211505.GA29612@embeddedor.com>
On 03/04/2018 22:15, Gustavo A. R. Silva wrote:
> new_range is being dereferenced before it is null checked, hence
> there is a potential null pointer dereference.
>
> Fix this by moving the pointer dereference after new_range has
> been properly null checked.
>
Hi Gustavo,
In fact we expect new_range to never be NULL. But, if we're going to
check, then better make sure the check is correct...
Thanks,
John
> Addresses-Coverity-ID: 1466163 ("Dereference before null check")
> Fixes: 0a7198426259 ("lib: Add generic PIO mapping method")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: John Garry <john.garry@huawei.com>
> ---
> lib/logic_pio.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/lib/logic_pio.c b/lib/logic_pio.c
> index 29cedea..30dfdce 100644
> --- a/lib/logic_pio.c
> +++ b/lib/logic_pio.c
> @@ -33,8 +33,8 @@ static DEFINE_MUTEX(io_range_mutex);
> int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
> {
> struct logic_pio_hwaddr *range;
> - resource_size_t start = new_range->hw_start;
> - resource_size_t end = new_range->hw_start + new_range->size;
> + resource_size_t start;
> + resource_size_t end;
> resource_size_t mmio_sz = 0;
> resource_size_t iio_sz = MMIO_UPPER_LIMIT;
> int ret = 0;
> @@ -42,6 +42,9 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
> if (!new_range || !new_range->fwnode || !new_range->size)
> return -EINVAL;
>
> + start = new_range->hw_start;
> + end = new_range->hw_start + new_range->size;
> +
> mutex_lock(&io_range_mutex);
> list_for_each_entry_rcu(range, &io_range_list, list) {
> if (range->fwnode == new_range->fwnode) {
>
next prev parent reply other threads:[~2018-04-04 8:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 21:15 Gustavo A. R. Silva
2018-04-04 8:54 ` John Garry [this message]
2018-04-04 13:43 ` Bjorn Helgaas
-- strict thread matches above, loose matches on Subject: below --
2018-04-03 21:12 Gustavo A. R. Silva
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=c5cc072b-88cb-979c-3645-9b59319dd511@huawei.com \
--to=john.garry@huawei.com \
--cc=andy.shevchenko@gmail.com \
--cc=bhelgaas@google.com \
--cc=gustavo@embeddedor.com \
--cc=gustavo@embeddeodr.com \
--cc=linux-kernel@vger.kernel.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
Powered by JetHome