From: Kalle Valo <kvalo@codeaurora.org>
To: Julian Calaby <julian.calaby@gmail.com>
Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
ath10k@lists.infradead.org,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Saeed Mahameed <saeedm@nvidia.com>,
Alex Dewar <alex.dewar90@gmail.com>
Subject: Re: [PATCH v2] ath10k: sdio: remove redundant check in for loop
Date: Thu, 24 Sep 2020 19:27:36 +0300 [thread overview]
Message-ID: <87h7rnnnrb.fsf@codeaurora.org> (raw)
In-Reply-To: <CAGRGNgWoFfCnK9FcWTf_f0b57JNEjsm6ZNQB5X_AMf8L3FyNcQ@mail.gmail.com> (Julian Calaby's message of "Thu, 17 Sep 2020 10:45:33 +1000")
Julian Calaby <julian.calaby@gmail.com> writes:
> On Thu, Sep 17, 2020 at 3:09 AM Alex Dewar <alex.dewar90@gmail.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@nvidia.com>
>> Signed-off-by: Alex Dewar <alex.dewar90@gmail.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.
Yeah, I was thinking the same. But I'll apply this patch anyway, it's
still an improvement.
> 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;
> }
I agree. Anyone can come up with a patch?
--
https://patchwork.kernel.org/project/linux-wireless/list/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k
WARNING: multiple messages have this Message-ID (diff)
From: Kalle Valo <kvalo@codeaurora.org>
To: Julian Calaby <julian.calaby@gmail.com>
Cc: Alex Dewar <alex.dewar90@gmail.com>,
netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
ath10k@lists.infradead.org, Jakub Kicinski <kuba@kernel.org>,
Saeed Mahameed <saeedm@nvidia.com>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v2] ath10k: sdio: remove redundant check in for loop
Date: Thu, 24 Sep 2020 19:27:36 +0300 [thread overview]
Message-ID: <87h7rnnnrb.fsf@codeaurora.org> (raw)
In-Reply-To: <CAGRGNgWoFfCnK9FcWTf_f0b57JNEjsm6ZNQB5X_AMf8L3FyNcQ@mail.gmail.com> (Julian Calaby's message of "Thu, 17 Sep 2020 10:45:33 +1000")
Julian Calaby <julian.calaby@gmail.com> writes:
> On Thu, Sep 17, 2020 at 3:09 AM Alex Dewar <alex.dewar90@gmail.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@nvidia.com>
>> Signed-off-by: Alex Dewar <alex.dewar90@gmail.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.
Yeah, I was thinking the same. But I'll apply this patch anyway, it's
still an improvement.
> 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;
> }
I agree. Anyone can come up with a patch?
--
https://patchwork.kernel.org/project/linux-wireless/list/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
next prev parent reply other threads:[~2020-09-24 16:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-14 19:19 [PATCH] ath10k: sdio: remove reduntant check in for loop Alex Dewar
2020-09-14 19:19 ` Alex Dewar
2020-09-14 21:51 ` Saeed Mahameed
2020-09-14 21:51 ` Saeed Mahameed
2020-09-16 16:57 ` [PATCH v2] ath10k: sdio: remove redundant " Alex Dewar
2020-09-16 16:57 ` Alex Dewar
2020-09-17 0:45 ` Julian Calaby
2020-09-17 0:45 ` Julian Calaby
2020-09-24 16:27 ` Kalle Valo [this message]
2020-09-24 16:27 ` Kalle Valo
2020-09-27 10:58 ` Alex Dewar
2020-09-27 10:58 ` Alex Dewar
2020-09-29 7:42 ` Kalle Valo
2020-09-29 7:42 ` Kalle Valo
2020-11-06 6:36 ` Kalle Valo
2020-11-06 6:36 ` Kalle Valo
2020-09-16 16:59 ` [PATCH] ath10k: sdio: remove reduntant " Alex Dewar
2020-09-16 16:59 ` Alex Dewar
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=87h7rnnnrb.fsf@codeaurora.org \
--to=kvalo@codeaurora.org \
--cc=alex.dewar90@gmail.com \
--cc=ath10k@lists.infradead.org \
--cc=davem@davemloft.net \
--cc=julian.calaby@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.