lkml.org 
[lkml]   [2022]   [Mar]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 2/3] ASoC: sprd: remove check of list iterator against head past the loop body
On Fri, Apr 1, 2022 at 5:52 AM Jakob Koschel <jakobkoschel@gmail.com> wrote:
>
> When list_for_each_entry() completes the iteration over the whole list
> without breaking the loop, the iterator value will be a bogus pointer
> computed based on the head element.
>
> While it is safe to use the pointer to determine if it was computed
> based on the head element, either with list_entry_is_head() or
> &pos->member == head, using the iterator variable after the loop should
> be avoided.
>
> In preparation to limiting the scope of a list iterator to the list
> traversal loop, use a dedicated pointer to point to the found element [1].
>
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>

LGTM. Thanks.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

> sound/soc/sprd/sprd-mcdt.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/sound/soc/sprd/sprd-mcdt.c b/sound/soc/sprd/sprd-mcdt.c
> index f6a55fa60c1b..6e27789a0df5 100644
> --- a/sound/soc/sprd/sprd-mcdt.c
> +++ b/sound/soc/sprd/sprd-mcdt.c
> @@ -866,20 +866,19 @@ EXPORT_SYMBOL_GPL(sprd_mcdt_chan_dma_disable);
> struct sprd_mcdt_chan *sprd_mcdt_request_chan(u8 channel,
> enum sprd_mcdt_channel_type type)
> {
> - struct sprd_mcdt_chan *temp;
> + struct sprd_mcdt_chan *temp = NULL;
> + struct sprd_mcdt_chan *iter;
>
> mutex_lock(&sprd_mcdt_list_mutex);
>
> - list_for_each_entry(temp, &sprd_mcdt_chan_list, list) {
> - if (temp->type == type && temp->id == channel) {
> - list_del_init(&temp->list);
> + list_for_each_entry(iter, &sprd_mcdt_chan_list, list) {
> + if (iter->type == type && iter->id == channel) {
> + list_del_init(&iter->list);
> + temp = iter;
> break;
> }
> }
>
> - if (list_entry_is_head(temp, &sprd_mcdt_chan_list, list))
> - temp = NULL;
> -
> mutex_unlock(&sprd_mcdt_list_mutex);
>
> return temp;
> --
> 2.25.1
>


--
Baolin Wang

\
 
 \ /
  Last update: 2022-09-17 16:19    [W:0.148 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site