Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4455321pxb; Sun, 27 Mar 2022 19:29:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQ0BuFVGVv/76k+ggXG4UXpXcXCwT11nqyRIuXfTTT333CXmT8WoQ+0CgRUkQfwzKzULrq X-Received: by 2002:a17:907:3d94:b0:6df:8791:135f with SMTP id he20-20020a1709073d9400b006df8791135fmr24453360ejc.205.1648434591699; Sun, 27 Mar 2022 19:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648434591; cv=none; d=google.com; s=arc-20160816; b=zUK1+TCTu/MXZz42dZbWIvXAi0TE7w7LCgBSNhzO8aTMp71CjHfSAhg+xGUntKqSjQ ad53svU+QCl50rhHugEs5z0mawMQkmm4FEJ+djC9u9Yr7KXPjPgfGhABheXLIeWzwjvs Zi6eRuNHaloIsGSn4VZNxynnrBDvkmmPNmj9UvAoyVEhPfVx2DfObmH6t6gDPH8cVuDe IwAenHrdgTgLHNBsmMBG9BHhywT76b8DF9b81s7yL6r4w7kpwSUqlD9w/sfT0ZPQR0AI 6A7gN8JkvMlx0sXWrpcsv9/9opL83q1ZsW7lB/xwekvG7lFGi3MCg501+l/EezJSp9VP jVVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=G/veNDzCNS5/sUVFJGizo3guRLL8pkQ0CB/O7gGvVxs=; b=dI6dHL82qK8ZTJQa83BTSOU0OXA4NQRQHBG2eqnRYmwQ0T8dG/qjuEzxXQmOVfBkzO SDExbK2sJdHzJTkOfHrXF4W8C42mye6pmeZPjsR7ugEaE/Gu3gA6KYPYTHIgux2uX0Pa QXZc5VrwztiWhRcSlEgaBNaHNEjC86EVfw46gUb+0pr5zPOhGjeATLXUhNPL/HKpqHGR E+VpzzSmgXm13vj+KHG1UXmaTbF3uUTQyho/m3h23cCoJ0Q5vIFHlMH1O7PtLj0wgIR8 c2AHhRkEKr4rqs9n76KOu41y1my6i14vO80TZrHLh81iJcoZArNx1S2pCaK6jgZLqbwJ ih1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b=EmL8qGcr; 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 x15-20020a170906148f00b006df80878726si12369197ejc.705.2022.03.27.19.29.27; Sun, 27 Mar 2022 19:29:51 -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=fail header.i=@roeck-us.net header.s=default header.b=EmL8qGcr; 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 S235793AbiC0PJq (ORCPT + 99 others); Sun, 27 Mar 2022 11:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbiC0PJo (ORCPT ); Sun, 27 Mar 2022 11:09:44 -0400 X-Greylist: delayed 1500 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 27 Mar 2022 08:08:05 PDT Received: from gateway20.websitewelcome.com (gateway20.websitewelcome.com [192.185.52.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5DB15A2B for ; Sun, 27 Mar 2022 08:08:05 -0700 (PDT) Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 4B241400C2EE7 for ; Sun, 27 Mar 2022 09:22:29 -0500 (CDT) Received: from 162-215-252-75.unifiedlayer.com ([208.91.199.152]) by cmsmtp with SMTP id YTmnna9qN9AGSYTmnnP1h0; Sun, 27 Mar 2022 09:22:29 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=G/veNDzCNS5/sUVFJGizo3guRLL8pkQ0CB/O7gGvVxs=; b=EmL8qGcra7Wt23Kn0RbrN6quHi J9CWPtYJEhIPgJRb0guYbe+vH7gLtxbxdq5KxZR1SEeb/j1WKvTUVEa/0ifN69o8yjv+4QVKhKcps 1aNwkwqofgKirE16tEjtE6h4A4XcLxRQhWKRJmArD9fE8Ts0ZAtSZBn9dFiU3k5B4mbLK0q3vEkA1 iIBgjiYyJ0aOC/aHbDTZY3Q4DUWDMbQi56BtouuRTeEJm9dkf/8UXQwGb2zZaer7PPJUmotpipCWk Et5tlgfFS1ipzFrDJyH1XwWC9NXuEjV/5GYgihu8DzqTBPXj6HFRbBoozuLZy4+8Kb+TkLBeJcMSS whTuAXMQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:54514) by bh-25.webhostbox.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nYTmm-001lFq-Md; Sun, 27 Mar 2022 14:22:28 +0000 Message-ID: <10cdb7dc-c210-8439-dacc-4338d3070f7f@roeck-us.net> Date: Sun, 27 Mar 2022 07:22:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] device: fix missing check on list iterator Content-Language: en-US To: Xiaomeng Tong Cc: airlied@linux.ie, bskeggs@redhat.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, kherbst@redhat.com, linux-kernel@vger.kernel.org, lyude@redhat.com, nouveau@lists.freedesktop.org, stable@vger.kernel.org References: <80429172-37c6-c9ce-4df7-259bb90338a8@roeck-us.net> <20220327065950.7886-1-xiam0nd.tong@gmail.com> From: Guenter Roeck In-Reply-To: <20220327065950.7886-1-xiam0nd.tong@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-BWhitelist: no X-Source-IP: 108.223.40.66 X-Source-L: No X-Exim-ID: 1nYTmm-001lFq-Md X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net [108.223.40.66]:54514 X-Source-Auth: linux@roeck-us.net X-Email-Count: 4 X-Source-Cap: cm9lY2s7YWN0aXZzdG07YmgtMjUud2ViaG9zdGJveC5uZXQ= X-Local-Domain: yes X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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 3/26/22 23:59, Xiaomeng Tong wrote: > On Sat, 26 Mar 2022 22:38:05 -0700, Guenter Roeck wrote: >>> @@ -103,11 +103,16 @@ nvkm_control_mthd_pstate_attr(struct nvkm_control *ctrl, void *data, u32 size) >>> return -EINVAL; >>> >>> if (args->v0.state != NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT) { >>> - list_for_each_entry(pstate, &clk->states, head) { >>> - if (i++ == args->v0.state) >>> + list_for_each_entry(iter, &clk->states, head) { >>> + if (i++ == args->v0.state) { >>> + pstate = iter; >> >> Is iter and the assignment really necessary ? Unless I am missing something, >> list_for_each_entry() always assigns pos (pstate/iter), even if the list is >> empty. If nothing is found, pstate would be NULL at the end, so > > the pstate will not be NULL at the end! so the assignment is necessary! > #define list_for_each_entry(pos, head, member) \ > for (pos = __container_of((head)->next, pos, member); \ > &pos->member != (head); \ > pos = __container_of(pos->member.next, pos, member)) > Uuh, yes, you are correct. Sorry for the noise. Guenter