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 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 AF8AECCD1AA for ; Fri, 17 Oct 2025 13:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dXfpkdrCfg9zCKF4c76Klt1vwuWSZKiIxgnW46FeXKw=; b=dMMAzA2xdRIckrCyoJOFm+Hb/G W5oTuh9dKt1wnh0GXWtf48mK9nhmWzVnLOn8FFjfAYKzhgFeSy1Ohdg6DajkrPwJ+h1XDdmkR9T+e fL/5T3NB4IGeM5PJCNSqg+QJDhFNB9HLsGYdXnMeHzCXSOOaf0U9iyOuqKlBUscPYO55ce6+eJLMK J5hCupS4amweewU/aieb4xdjVd9RF1lgDDvdKIgF+ZaPiCGz0Mo15Gia3WgwluK5knR6l4VlfoVxN zn+eDXkD0QO9lqVHLJv37xdyFPz+sz9sRTs89PzjTwz9t5W7rXo9B9GOLaGqKpWFwJKklQ3YN4C2d QlNm+zLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9kRS-00000007uU5-2te8; Fri, 17 Oct 2025 13:24:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9kRM-00000007uPD-31ce for linux-arm-kernel@lists.infradead.org; Fri, 17 Oct 2025 13:24:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5AD861595; Fri, 17 Oct 2025 06:24:08 -0700 (PDT) Received: from e133711.arm.com (e133711.arm.com [10.1.196.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 87EBF3F66E; Fri, 17 Oct 2025 06:24:15 -0700 (PDT) From: Sudeep Holla Date: Fri, 17 Oct 2025 14:23:49 +0100 Subject: [PATCH 6/8] firmware: arm_scmi: Refactor protocol device creation logic MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251017-acpi_scmi_pcc-v1-6-0adbab7709d9@arm.com> References: <20251017-acpi_scmi_pcc-v1-0-0adbab7709d9@arm.com> In-Reply-To: <20251017-acpi_scmi_pcc-v1-0-0adbab7709d9@arm.com> To: Cristian Marussi , arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sudeep Holla X-Mailer: b4 0.14.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251017_062416_809896_E6D31387 X-CRM114-Status: GOOD ( 12.21 ) 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 Refactor the protocol validation and device creation logic in scmi_probe() into a new helper function, scmi_device_check_create(), to improve readability and reduce code duplication. The new helper consolidates checks for protocol ID range, implementation availability, and duplicate activation, before invoking scmi_create_protocol_devices(). This refactor simplifies the SCMI probe path while preserving existing behavior. No functional changes intended. This refactoring is required to enable ACPI PCC transport. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/driver.c | 56 ++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index ac51726f24db..f679a769fc87 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -3141,6 +3141,38 @@ static void scmi_enable_matching_quirks(struct scmi_info *info) rev->sub_vendor_id, rev->impl_ver); } +static void scmi_device_check_create(struct fwnode_handle *fwnode, int prot_id, + struct scmi_info *info) +{ + int ret; + struct device *dev = info->dev; + struct scmi_handle *handle = &info->handle; + + if (!FIELD_FIT(MSG_PROTOCOL_ID_MASK, prot_id)) + dev_err(dev, "Out of range protocol %d\n", prot_id); + + if (!scmi_is_protocol_implemented(handle, prot_id)) { + dev_err(dev, "SCMI protocol %d not implemented\n", + prot_id); + return; + } + + /* + * Save this valid fwnode protocol descriptor amongst + * @active_protocols for this SCMI instance/ + */ + ret = idr_alloc(&info->active_protocols, + fwnode_handle_get(fwnode), + prot_id, prot_id + 1, GFP_KERNEL); + if (ret != prot_id) { + dev_err(dev, "SCMI protocol %d already activated. Skip\n", + prot_id); + return; + } + + scmi_create_protocol_devices(fwnode, info, prot_id, NULL); +} + static int scmi_probe(struct platform_device *pdev) { int ret; @@ -3269,29 +3301,7 @@ static int scmi_probe(struct platform_device *pdev) if (fwnode_property_read_u32(child, "reg", &prot_id)) continue; - if (!FIELD_FIT(MSG_PROTOCOL_ID_MASK, prot_id)) - dev_err(dev, "Out of range protocol %d\n", prot_id); - - if (!scmi_is_protocol_implemented(handle, prot_id)) { - dev_err(dev, "SCMI protocol %d not implemented\n", - prot_id); - continue; - } - - /* - * Save this valid fwnode protocol descriptor amongst - * @active_protocols for this SCMI instance/ - */ - ret = idr_alloc(&info->active_protocols, - fwnode_handle_get(child), - prot_id, prot_id + 1, GFP_KERNEL); - if (ret != prot_id) { - dev_err(dev, "SCMI protocol %d already activated. Skip\n", - prot_id); - continue; - } - - scmi_create_protocol_devices(child, info, prot_id, NULL); + scmi_device_check_create(child, prot_id, info); } return 0; -- 2.34.1