Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4632852pxb; Sun, 27 Mar 2022 23:52:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt9aNj9q248xqs6qWwpQEQu2BwyhMvzJFDS+DYwAVg3Gg0+mhQ6aGbxE3BL+P0aJYr31/q X-Received: by 2002:a05:6402:26c8:b0:419:2e54:9262 with SMTP id x8-20020a05640226c800b004192e549262mr14221338edd.61.1648450320324; Sun, 27 Mar 2022 23:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648450320; cv=none; d=google.com; s=arc-20160816; b=m9RnQWe24MyGskICQRc7EPGXSTlTOzR1/2QsC5gQAnMQpNFjuDOt5aVxryHQ2p28lR snFSeFbvJ2BSUKTNgjBwHpMeGAgs4cp8tWa0hu0A2aFP5EhAMX4naH0mXAvYIJsdjn11 YmUCR0GAeUn/gxjy1ntCMU/kA8k6MZXREhMG8h8h6oRRteVOwxxpihYS6an4SrJxzUGg A9aeuNaLAcb1H0oB9VXadFq5pI3d0hHmDozPdPiN+dL7Z/djmYINMCM62tY7E7EoDwcZ WvKfQipaC6uIqO3dAR7JSxaLaPnPDFPbUueM9GY7RTwp0fJj+kfPMGNO2Katdt0bqrur dQ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=6GFJ7ancB1plEhfgVzWZYVl+G7Gv/ojaNkdikZ/2jZg=; b=sE64CFw+AELBo5qO9ASvkEucsn9Ne/Z177X8L6tewsnDt9aSHInCpJLyEasvH5ShjO zv75GtkgDkBYXb3HmgM/CM3ScrBNcB8I7ErPqVsC/KV7g/2ooeMn+TouxJXkgowtHWAf bRjmLp1Z/L05L87u6yahJVLGD07Tea93+/LUU1KPqXlwFk4vOyTAATlpQ3ZKlK1hugGZ afb6/gCeWhGr3Q8iHhRD6/uQAsya7c7oWGMZSWG+QFszjlYbINZDhAWi/6Yfn9dBt4bW l6XkCJY+qUdLGVPURxL3LsJgiNY3NTo25hNMt4EOeV8Ldt3hzqw4OOqqMGN5A1WA7l4w C3rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=orqlMfSr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020aa7df08000000b00418c2b5bf1esi12303834edy.512.2022.03.27.23.51.34; Sun, 27 Mar 2022 23:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=orqlMfSr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235961AbiC0QNJ (ORCPT + 99 others); Sun, 27 Mar 2022 12:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbiC0QNG (ORCPT ); Sun, 27 Mar 2022 12:13:06 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73971C13E for ; Sun, 27 Mar 2022 09:11:27 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id l7-20020a05600c1d0700b0038c99618859so11630521wms.2 for ; Sun, 27 Mar 2022 09:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version; bh=6GFJ7ancB1plEhfgVzWZYVl+G7Gv/ojaNkdikZ/2jZg=; b=orqlMfSrIwbyWYkxZvplXPR/LEXQlsFsphWNY42yJ+k9AqwBhabrHAiJkEGgEJQ4c5 tVuDgtkcZUw1pUawPj2wupbIlL/noe5AYE2CHM7E0rKnye5waqjP/HxuCyT9FwuCnpK2 xsMGqznycLaxDy5IQwMEQWsmr+IyiRLbLY0HGQDcchsthrw8OOApWaGgBVIrBl4JiXAj 2/vaEs0dJJXrLC+rjpwDoOFI8FYSXTIWoUMrh6rMex8x0zFj05tukxn4PUD+cmQSsaMr JozTSLpuTmfQepoKzpTN39+u5OADe14u/40UVQWLBl4P62b8cwQ7VuhzncUvLB52PfFk c7nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :in-reply-to:message-id:mime-version; bh=6GFJ7ancB1plEhfgVzWZYVl+G7Gv/ojaNkdikZ/2jZg=; b=lCnSfPNyb3G7cQXg5I1Xp2wqEoIzzyqUOXJBwOYTCj7ciW0/wBeAY6RERnzvH3D23u ycONiCfSGi1E8mvm/y6mB8AqSWMptQr2Rd7SewvGBdDgTZlb+F6qLlopeulXIxEzbsxw i8rOmBUVxI5GyOBMbW3fjnJOi+pbdMXCdykKeLvJ5qn5U0ABk994wEKtyK2SuM9XruSz ncyJcQT+TmiwA1wCPvOsYF6Aj2zUhxMqbotYyjc5VOL1XNr/R2a9XaajSqSt3gfdgR4h Mg+yxCnw7XG27Vyowc/Are9Zp98nCCep8wY6s/MBKshqo7a0Jtb+SicibDCEppM7XfV+ sw6g== X-Gm-Message-State: AOAM5339C5IOVD5bLIt6YtG10wvCZsSje13Nci3mAlATo8bhP3UY37yA sRp1uYZQN5shki/O3pOLTpVFZw== X-Received: by 2002:a05:600c:5029:b0:38c:9768:b4c with SMTP id n41-20020a05600c502900b0038c97680b4cmr19962707wmr.123.1648397486308; Sun, 27 Mar 2022 09:11:26 -0700 (PDT) Received: from localhost (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.gmail.com with ESMTPSA id v8-20020a1cf708000000b0034d7b5f2da0sm9633355wmh.33.2022.03.27.09.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 09:11:25 -0700 (PDT) References: <1jk0cf6480.fsf@starbuckisacylon.baylibre.com> <20220327130801.15631-1-xiam0nd.tong@gmail.com> User-agent: mu4e 1.6.10; emacs 27.1 From: Jerome Brunet To: Xiaomeng Tong Cc: alsa-devel@alsa-project.org, broonie@kernel.org, khilman@baylibre.com, lgirdwood@gmail.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, martin.blumenstingl@googlemail.com, narmstrong@baylibre.com, perex@perex.cz, stable@vger.kernel.org, tiwai@suse.com Subject: Re: [PATCH] soc: meson: fix a missing check on list iterator Date: Sun, 27 Mar 2022 18:05:26 +0200 In-reply-to: <20220327130801.15631-1-xiam0nd.tong@gmail.com> Message-ID: <1j35j374us.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 27 Mar 2022 at 21:08, Xiaomeng Tong wrote: > On Sun, 27 Mar 2022 13:03:14 +0200, Jerome Brunet wrote: >> On Sun 27 Mar 2022 at 16:18, Xiaomeng Tong wrote: >> >> > The bug is here: >> > *dai_name = dai->driver->name; >> > >> > For for_each_component_dais(), just like list_for_each_entry, >> > the list iterator 'runtime' will point to a bogus position >> > containing HEAD if the list is empty or no element is found. >> > This case must be checked before any use of the iterator, >> > otherwise it will lead to a invalid memory access. >> > >> > To fix the bug, just move the assignment into loop and return >> > 0 when element is found, otherwise return -EINVAL; >> >> Except we already checked that the id is valid and know an element will >> be be found once we enter the loop. No bug here and this patch does not >> seem necessary to me. > > Yea, you should be right, it is not a bug here. id already be checked before > enter the loop: > > if (id < 0 || id >= component->num_dai) > return -EINVAL; > > but if component->num_dai is not correct due to miscaculation or others reason > and the door is reopened, this patch can avoid a invalid memory > access. This is a speculation which just does not hold ATM. What this patch does is adding dead code cause the last "return -EINVAL;" will never be reached. This no fix nor improvement. > Anyway, > it is a good choice to use the list iterator only inside the loop, as linus > suggested[1]. and we are on the way to change all these use-after-iter cases. > > [1]https://lore.kernel.org/lkml/20220217184829.1991035-1-jakobkoschel@gmail.com/ You can make improvements as long as the code is kept clean an maintainable. Dead code is not OK.