From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26ED2C433EF for ; Wed, 4 May 2022 08:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347174AbiEDIzs (ORCPT ); Wed, 4 May 2022 04:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346896AbiEDIxx (ORCPT ); Wed, 4 May 2022 04:53:53 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD17025EBB; Wed, 4 May 2022 01:49:38 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 5A61167B; Wed, 4 May 2022 10:49:37 +0200 (CEST) Date: Wed, 4 May 2022 10:49:36 +0200 From: Joerg Roedel To: Xiaomeng Tong Cc: agross@kernel.org, bjorn.andersson@linaro.org, will@kernel.org, sricharan@codeaurora.org, linux-arm-msm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] iommu: fix an incorrect NULL check on list iterator Message-ID: References: <20220501132823.12714-1-xiam0nd.tong@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220501132823.12714-1-xiam0nd.tong@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 01, 2022 at 09:28:23PM +0800, Xiaomeng Tong wrote: > The bug is here: > if (!iommu || iommu->dev->of_node != spec->np) { > > The list iterator value 'iommu' will *always* be set and non-NULL by > list_for_each_entry(), so it is incorrect to assume that the iterator > value will be NULL if the list is empty or no element is found (in fact, > it will point to a invalid structure object containing HEAD). > > To fix the bug, use a new value 'iter' as the list iterator, while use > the old value 'iommu' as a dedicated variable to point to the found one, > and remove the unneeded check for 'iommu->dev->of_node != spec->np' > outside the loop. > > Cc: stable@vger.kernel.org > Fixes: f78ebca8ff3d6 ("iommu/msm: Add support for generic master bindings") > Signed-off-by: Xiaomeng Tong > --- > changes since v1: > - add a new iter variable (suggested by Joerg Roedel) This is now applied. I had to manually apply it because the patch was malformed at line 36 and git-am complained. Regards, Joerg