Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2685194pxm; Mon, 28 Feb 2022 04:17:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKz6d4TKWCFhrEJcVdN0d73g0qUO7HVONaHwAHmOunukZvxGzaNaC8n9D5Ux3ooDyyiSnE X-Received: by 2002:a17:906:7f02:b0:6cf:86d8:c31c with SMTP id d2-20020a1709067f0200b006cf86d8c31cmr15254406ejr.518.1646050678001; Mon, 28 Feb 2022 04:17:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050677; cv=none; d=google.com; s=arc-20160816; b=m4xtz92y6kkry4VkTZTzs4AwDtNjReR7TYC0fxBxemI/efdh1ZzMdhmXhuFF8oExo1 +Zm06Dam6mbfI4JhSuVIAaK3fqPpOdhuu8ZBuoTmjewS9Efss/fRoQUmPMPmexNUJnyr zJ8tQaiCRh/6UOwP5ZQwUW7aZWIiVrJczDB1vJHvGLZbqHfyIdYes9c/PFq45878lImu H7LY98PjkZbef83IQzYx/54vaciZYkcegRaaP4nI+4yRs1YfhsCDPr484mTPxw7VQan8 64J11c6gp2dNKAukehiqeES0c0/pkbEeKpzmi8V5gdVeIQ2SYLkk0I4gnLHJTzT9Vkly JtHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HpiN/zwO1wBD5W8vJ5qwHzWs2Mz8GYwVSPoaDyTc8jQ=; b=ABpcF+3igCAaayo4RCHxVtYVxmpJV8oWI9GChfSxNez25qKagk0SoP2Mzgnhwua/gA 04wN98mGHTDvBbReI61Tt0wym+TjNNdcmd+4plMFCGQ5bJtX626d8D4PSZkYdBHPeFCw sV+MZW9StgRvJnQNUlw//ijrtaW6TWXNHSdRq5qgey4ty9kSb0gRiXcK60H95fGkQHQw olWfwANtEMPMG9tknTRSdow23QGIH0ceL4AyTfQKogFvbXj6TDVkwYFPWSthbd0lUALu 9ObPkmaEviFsdac1quBbx72s3zesT2gSMeabaJMijNI90Nq30k2VbV0bXo9iHLRHecON Ofog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hjvTHeqA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a50bf46000000b00410a39f661esi6705730edk.495.2022.02.28.04.17.34; Mon, 28 Feb 2022 04:17:57 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=hjvTHeqA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235624AbiB1LJw (ORCPT + 99 others); Mon, 28 Feb 2022 06:09:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235427AbiB1LJj (ORCPT ); Mon, 28 Feb 2022 06:09:39 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469676AA4D; Mon, 28 Feb 2022 03:08:59 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id a8so23987735ejc.8; Mon, 28 Feb 2022 03:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HpiN/zwO1wBD5W8vJ5qwHzWs2Mz8GYwVSPoaDyTc8jQ=; b=hjvTHeqAC17Nm2rqJFqOWVUlo+eMrb6KCGjEjnmUhT0UbOoSD99k2xAziOpWZa+Icu SPp4Zg1lqK8FLNpUHi/iGpToynAZh7AAx7I6BqkiBOWQWPIrLjejJ7mt0E6lp79jr43P Z8Tz3UxSCHK1qzDcri6ZY14M8lx9G0bi6GCGQHl0DVbHpgXti6eqzCprjBZYIcyI1uce Dn/lOukn9J64/ASqyssuY+hk5ExgHfhAh8xyytTN1bW2SLq53AUCqmHXOqxQHzvGm8yg Hb8Tr+NdyPNcInoLFcy82stmYANyPP1+b2zh81uncpq/hmnHTquj2t004aepXQhNWxPC QShA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HpiN/zwO1wBD5W8vJ5qwHzWs2Mz8GYwVSPoaDyTc8jQ=; b=lLl+YmY9FiSRN80GVWrymLx9swIZ3gwOyStRn6bfg3dV/Cj+9GnHjavNd9IXJXv+Xh GPG9BH9/RiwW0YmuimvZ37s2kmXZZvd+p4RFBeEA6UX+2QQUVkBWwDh3Olg818ZEw+vL dHIIjOdr8qcEsZNS9suMsyLOCRouXjXNLitMqC6FNwdGXjzEkHxdZfWvDQqLd1qc5OrE gKZmJbAE9IOmzcGd7+k6vuHGSzbZBSfA+hCxEGr6l8+eiopqfo99O1DokRXVvjBnutsK 11jGbRfp37Rrrtf7038S9jrTkKss7okMbif/HUR3OS6xBC3zzM+ROm6xTD/wsiHpkOtm cwPQ== X-Gm-Message-State: AOAM531kSYy2VbDob0O7hBr4gBcFW8RunwTwxAE+MDCY//frvFtjKqQB 1+pUI8CNx5vrjqxV+9+WW/I= X-Received: by 2002:a17:906:3803:b0:6cf:56b9:60a9 with SMTP id v3-20020a170906380300b006cf56b960a9mr14108161ejc.716.1646046537823; Mon, 28 Feb 2022 03:08:57 -0800 (PST) Received: from localhost.localdomain (dhcp-077-250-038-153.chello.nl. [77.250.38.153]) by smtp.googlemail.com with ESMTPSA id z22-20020a17090655d600b006d229436793sm4209049ejp.223.2022.02.28.03.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 03:08:57 -0800 (PST) From: Jakob Koschel To: Linus Torvalds Cc: Jakob Koschel , linux-arch , Thomas Gleixner , Arnd Bergman , "Andy Shevchenko" , Andrew Morton , Kees Cook , Mike Rapoport , "Gustavo A. R. Silva" , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Christophe JAILLET , Dan Carpenter , Jason Gunthorpe , Rasmus Villemoes , Nathan Chancellor , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sgx@vger.kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, linux-iio@vger.kernel.org, linux-crypto@vger.kernel.org, dmaengine@vger.kernel.org, linux1394-devel@lists.sourceforge.net, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-staging@lists.linux.dev, linux-usb@vger.kernel.org, linux-aspeed@lists.ozlabs.org, bcm-kernel-feedback-list@broadcom.com, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, kvm@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, v9fs-developer@lists.sourceforge.net, tipc-discussion@lists.sourceforge.net, alsa-devel@alsa-project.org Subject: [PATCH 3/6] treewide: fix incorrect use to determine if list is empty Date: Mon, 28 Feb 2022 12:08:19 +0100 Message-Id: <20220228110822.491923-4-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228110822.491923-1-jakobkoschel@gmail.com> References: <20220228110822.491923-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 The list iterator value will *always* be set by list_for_each_entry(). It is incorrect to assume that the iterator value will be NULL if the list is empty. Instead of checking the pointer it should be checked if the list is empty. In acpi_get_pmu_hw_inf() instead of setting the pointer to NULL on the break, it is set to the correct value and leaving it NULL if no element was found. Signed-off-by: Jakob Koschel --- arch/powerpc/sysdev/fsl_gtm.c | 4 ++-- drivers/media/pci/saa7134/saa7134-alsa.c | 4 ++-- drivers/perf/xgene_pmu.c | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/sysdev/fsl_gtm.c b/arch/powerpc/sysdev/fsl_gtm.c index 8963eaffb1b7..39186ad6b3c3 100644 --- a/arch/powerpc/sysdev/fsl_gtm.c +++ b/arch/powerpc/sysdev/fsl_gtm.c @@ -86,7 +86,7 @@ static LIST_HEAD(gtms); */ struct gtm_timer *gtm_get_timer16(void) { - struct gtm *gtm = NULL; + struct gtm *gtm; int i; list_for_each_entry(gtm, >ms, list_node) { @@ -103,7 +103,7 @@ struct gtm_timer *gtm_get_timer16(void) spin_unlock_irq(>m->lock); } - if (gtm) + if (!list_empty(>ms)) return ERR_PTR(-EBUSY); return ERR_PTR(-ENODEV); } diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c index fb24d2ed3621..d3cde05a6eba 100644 --- a/drivers/media/pci/saa7134/saa7134-alsa.c +++ b/drivers/media/pci/saa7134/saa7134-alsa.c @@ -1214,7 +1214,7 @@ static int alsa_device_exit(struct saa7134_dev *dev) static int saa7134_alsa_init(void) { - struct saa7134_dev *dev = NULL; + struct saa7134_dev *dev; saa7134_dmasound_init = alsa_device_init; saa7134_dmasound_exit = alsa_device_exit; @@ -1229,7 +1229,7 @@ static int saa7134_alsa_init(void) alsa_device_init(dev); } - if (dev == NULL) + if (list_empty(&saa7134_devlist)) pr_info("saa7134 ALSA: no saa7134 cards found\n"); return 0; diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c index 2b6d476bd213..e255f9e665d1 100644 --- a/drivers/perf/xgene_pmu.c +++ b/drivers/perf/xgene_pmu.c @@ -1460,7 +1460,8 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, struct hw_pmu_info *inf; void __iomem *dev_csr; struct resource res; - struct resource_entry *rentry; + struct resource_entry *rentry = NULL; + struct resource_entry *tmp; int enable_bit; int rc; @@ -1475,16 +1476,16 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, return NULL; } - list_for_each_entry(rentry, &resource_list, node) { - if (resource_type(rentry->res) == IORESOURCE_MEM) { - res = *rentry->res; - rentry = NULL; + list_for_each_entry(tmp, &resource_list, node) { + if (resource_type(tmp->res) == IORESOURCE_MEM) { + res = *tmp->res; + rentry = tmp; break; } } acpi_dev_free_resource_list(&resource_list); - if (rentry) { + if (!rentry) { dev_err(dev, "PMU type %d: No memory resource found\n", type); return NULL; } -- 2.25.1