[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGRGNgWoFfCnK9FcWTf_f0b57JNEjsm6ZNQB5X_AMf8L3FyNcQ@mail.gmail.com>
Date: Thu, 17 Sep 2020 10:45:33 +1000
From: Julian Calaby <julian.calaby@...il.com>
To: Alex Dewar <alex.dewar90@...il.com>
Cc: Saeed Mahameed <saeedm@...dia.com>,
Kalle Valo <kvalo@...eaurora.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, ath10k@...ts.infradead.org,
linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] ath10k: sdio: remove redundant check in for loop
Hi Alex,
On Thu, Sep 17, 2020 at 3:09 AM Alex Dewar <alex.dewar90@...il.com> wrote:
>
> The for loop checks whether cur_section is NULL on every iteration, but
> we know it can never be NULL as there is another check towards the
> bottom of the loop body. Refactor to avoid this unnecessary check.
>
> Also, increment the variable i inline for clarity
Comments below.
> Addresses-Coverity: 1496984 ("Null pointer dereferences)
> Suggested-by: Saeed Mahameed <saeedm@...dia.com>
> Signed-off-by: Alex Dewar <alex.dewar90@...il.com>
> ---
> v2: refactor in the manner suggested by Saeed
>
> drivers/net/wireless/ath/ath10k/sdio.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c
> index 81ddaafb6721..486886c74e6a 100644
> --- a/drivers/net/wireless/ath/ath10k/sdio.c
> +++ b/drivers/net/wireless/ath/ath10k/sdio.c
> @@ -2307,8 +2307,8 @@ static int ath10k_sdio_dump_memory_section(struct ath10k *ar,
> }
>
> count = 0;
> -
> - for (i = 0; cur_section; i++) {
> + i = 0;
> + for (; cur_section; cur_section = next_section) {
You can have multiple statements in each section of a for() if you need to, e.g.
for (i = 1; cur_section; cur_section = next_section, i++) {
which means that the increment of i isn't hidden deep in the function body.
That said, this function is a mess. Something (approximately) like
this might be more readable:
prev_end = memregion->start;
for (i = 0; i < mem_region->section_table.size; i++) {
cur_section = &mem_region->section_table.sections[i];
// fail if prev_end is greater than cur_section->start - message
from line 2329 and 2294
// check section size - from line 2315
skip_size = cur_section->start - prev_end;
// check buffer size - from line 2339 - needs to account for the
skip size too.
// fill in the skip size amount - from line 2358 and 2304
// ath10k_sdio_read_mem - from line 2346
prev_end = cur_section->end;
}
Thanks,
--
Julian Calaby
Email: julian.calaby@...il.com
Profile: http://www.google.com/profiles/julian.calaby/
Powered by blists - more mailing lists