From patchwork Mon Mar 27 20:52:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 13190084 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DD83C76195 for ; Mon, 27 Mar 2023 20:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=W1sSQhAp9osuEQYD2jOh9/DhwnT9txx0J6GEJM83kUs=; b=NyEtFQfHqBTPIb 5UQFxWcsndiLmYHK3N0/bAREEnXlSK9JxhuaHc6AcwAYkgqIePbrpZgdoybEEsbdsFklCKmD4a+si mNth0qbGJrDHNMn+rn6cHy7kjZcV35JQd+dVyI84zScJeglkUiTgvMbWlg9Gs9eWJnNV5D1viE6Lj 39ILNvrYairRIWuGn6Acl9uZd1ZmRn6rgPo+OzjASLuqPoF7X5KLJtaGCMY+4dXaY5ONqjYHoxMm0 UtZyYn8bFRJaxrW74g6mFrgcUKhi85Q/spwA8AN+nWAf8e52IdUe3iAmFGrk9SRtLjmLLA0DRQWx/ CmxBcBrNFgl5umQEv/sQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pgtpb-00CM5E-2z; Mon, 27 Mar 2023 20:52:43 +0000 Received: from mail-oa1-f48.google.com ([209.85.160.48]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pgtpY-00CM4Z-1I for linux-arm-kernel@lists.infradead.org; Mon, 27 Mar 2023 20:52:41 +0000 Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-17aaa51a911so10669607fac.5 for ; Mon, 27 Mar 2023 13:52:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679950357; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mCokmroWwO4VufX7A6mOYl3GgmQFzU+xi4IMBIypRNk=; b=pD+qB7DsUd5yvAAppjrFs8kgqOxh0FMqnjqBEgmFtTn+addhB9PMi+M2MMAENslQQx 2ORt84YYezg5Ft9yY6kUjorTiWgGdlZUOPw9z7SpYljD0l1vara62t1gUdmzxTEvW0xA U+Sk4GqRsf4buVxah3MCRIBtVCtYHVsxHQsbxKR7PtSz7LqgKl+QYvza8cH+93XDxWni Ew0xockn3TbL1DlCPX37w8pPq+MAeXlg9ldlePc+6IbNEzDY8Iwbe5ojDXkMCPILJc8C +gdVE/YbUU9G6FqzIdjgkAHm+Bb6F6gHwdbPk7gPtmm1EbBhzVtSWGHD6ZIswLVNt9Lg 4Qdg== X-Gm-Message-State: AAQBX9ca75mVzKH2Yte5lhlAAWNxvX3xgwSdHTGebqnofLi3EmoExYyW +zj9rLT2n7EUe12TyWuiow== X-Google-Smtp-Source: AK7set+8JPEPqeE9hXVijJtbMJer5bZDZeNugXZaxtUt4ndBavVZ+nQHJVymYACFFPbFLtprz+KixQ== X-Received: by 2002:a05:6870:899c:b0:17b:1a4f:adfe with SMTP id f28-20020a056870899c00b0017b1a4fadfemr7706053oaq.10.1679950357540; Mon, 27 Mar 2023 13:52:37 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id eh1-20020a056808274100b00383ece4c29bsm11562672oib.6.2023.03.27.13.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 13:52:36 -0700 (PDT) Received: (nullmailer pid 573623 invoked by uid 1000); Mon, 27 Mar 2023 20:52:35 -0000 From: Rob Herring To: Geert Uytterhoeven , Magnus Damm , Russell King Cc: linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ARM: sh-mobile: Use of_cpu_node_to_id() to read CPU node 'reg' Date: Mon, 27 Mar 2023 15:52:28 -0500 Message-Id: <20230327205228.573456-1-robh@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230327_135240_460768_510925D2 X-CRM114-Status: GOOD ( 15.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Replace open coded CPU nodes reading of "reg" and translation to logical ID with of_cpu_node_to_id(). The original code called of_parse_phandle() CONFIG_NR_CPUS times regardless of the length of 'cpus'. Optimize the loop to bail out once of_parse_phandle() fails as the end of 'cpus' property has been reached. Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven --- v2: - Optimize the number of loop iterations --- arch/arm/mach-shmobile/platsmp-apmu.c | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/arch/arm/mach-shmobile/platsmp-apmu.c b/arch/arm/mach-shmobile/platsmp-apmu.c index e771ce70e132..ec6f421c0f4d 100644 --- a/arch/arm/mach-shmobile/platsmp-apmu.c +++ b/arch/arm/mach-shmobile/platsmp-apmu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -210,7 +211,6 @@ static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit)) struct device_node *np_apmu, *np_cpu; struct resource res; int bit, index; - u32 id; for_each_matching_node(np_apmu, apmu_ids) { /* only enable the cluster that includes the boot CPU */ @@ -218,33 +218,29 @@ static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit)) for (bit = 0; bit < CONFIG_NR_CPUS; bit++) { np_cpu = of_parse_phandle(np_apmu, "cpus", bit); - if (np_cpu) { - if (!of_property_read_u32(np_cpu, "reg", &id)) { - if (id == cpu_logical_map(0)) { - is_allowed = true; - of_node_put(np_cpu); - break; - } - - } + if (!np_cpu) + break; + if (of_cpu_node_to_id(np_cpu) == 0) { + is_allowed = true; of_node_put(np_cpu); + break; } + of_node_put(np_cpu); } if (!is_allowed) continue; for (bit = 0; bit < CONFIG_NR_CPUS; bit++) { np_cpu = of_parse_phandle(np_apmu, "cpus", bit); - if (np_cpu) { - if (!of_property_read_u32(np_cpu, "reg", &id)) { - index = get_logical_index(id); - if ((index >= 0) && - !of_address_to_resource(np_apmu, - 0, &res)) - fn(&res, index, bit); - } - of_node_put(np_cpu); - } + if (!np_cpu) + break; + + index = of_cpu_node_to_id(np_cpu); + if ((index >= 0) && + !of_address_to_resource(np_apmu, 0, &res)) + fn(&res, index, bit); + + of_node_put(np_cpu); } } }