From patchwork Mon Mar 17 10:31:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 14019041 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 918EDC282EC for ; Mon, 17 Mar 2025 10:41:05 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Bzvtd/vhZp03AeLcq3w4TqXtf5We5BXq0EDS3aEITVY=; b=w7p0BRNFgsOAu2X5HZpMAIRHBR HIeMzTR3XRCtsrlF8IGTivl6GOwnl7duXo1uL1syOIxq2rKecioVcDdn5uP/KhawLGJhqEclEjb2p k0xvjrAY1ltxDV3uQ8uEAYwSMy5hMDUflZHjysVmAlp2DEpadw0eqFCLax5C/JHLgyxVNi74m60i0 R+kohq19ZAEeRAXnOAOxgSf94FRycStEgCJFB9Vv8hMhJKZudKDxrukbXgvZ8kJLX+XCXpbmyQNTn od7UXXX2t9uEKgi0eZeVOpAV95m7AVXkL2uWzRXXBJ/FHSViXAavU49fDzCqomTBoL+UzF7dS10gg /MOv6cTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tu7tx-00000002D98-0GTp; Mon, 17 Mar 2025 10:40:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tu7lF-00000002ATB-02Mt for linux-arm-kernel@lists.infradead.org; Mon, 17 Mar 2025 10:31:58 +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 DA9DB22FA; Mon, 17 Mar 2025 03:32:03 -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 3BB323F673; Mon, 17 Mar 2025 03:31:54 -0700 (PDT) From: Sudeep Holla Date: Mon, 17 Mar 2025 10:31:22 +0000 Subject: [PATCH v2 2/5] firmware: arm_scmi: Refactor device matching logic to eliminate duplication MIME-Version: 1.0 Message-Id: <20250317-b4-scmi_minor_cleanup-v2-2-f4be99bd9864@arm.com> References: <20250317-b4-scmi_minor_cleanup-v2-0-f4be99bd9864@arm.com> In-Reply-To: <20250317-b4-scmi_minor_cleanup-v2-0-f4be99bd9864@arm.com> To: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , Cristian Marussi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3252; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=das9EqDKBZfkwRTCcRMlY6ZRJ43jXpNz8KtuySsJ6qI=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBn1/oX/bDNN6C4OIcuzQDIH8p91pkEVI67HPAN/ vlg5PqJOeGJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZ9f6FwAKCRAAQbq8MX7i mCmRD/91EUqn0e5HHr299UU4qQo8JTS92BhxmGSjlM3JhRUrGRsLUWP1eQUN3LmTaIpHBou9Ebm ZDXdsInfZazZYiZXTjMhHx8sk0leJqewwu5XUshKn7zX1vyWiT8sZgkKwE0yyAPvJkLt7tB8nzr R7KF6mQM9N1YyLfNRJaVDhwXtf7U7QGVbPQLxYUmZZbj6K927KFil/ecXDlhMY540nY5pavtF44 MkwmekOjWz8/3iZuojsBpGvHBntZl/QO7uKzqAXLWXSEJFOBfPVWRyDkrD6NOMAwxo/G3giIUhF HhCVnLyQNCqt1g9+XbKKifXT/A1dKMbq0uv2UZVyfqiTEy7N48E7IAMKskxpwhbu8XdiccfHT4M thzORyH7uqNl3rMkRkgfZUW4IMeQ4M5aszRltf13Z2jjkZQpP+IpC8tjBHdWv31BzGHFvg2IrX7 ApuGphOsEEFBa9UcRXe90N7C1W15wdLFnatNztq34L7eT7qadgyfLhzL281Mr4qCtuXP6w1uRaJ GykV5jkRAe4EwCVIy5lTkljp59OOkvU7GxF/77AmJgsp1Tpz753KgIwkVDJssyxSbBgnlvVh2b5 flssMoWVuCzwbAb3YScQLA4IyPe0VUGq8eHZFe18+/LDXrMVLtNLa0yk5O3h8sdw+zBVdcPPRE8 OzVVylSi6KhnZcA== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250317_033157_178109_373B8D0C X-CRM114-Status: GOOD ( 13.90 ) 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 Currently, the device matching logic is duplicated in two functions: - scmi_dev_match() used by the scmi_bus to match scmi_devices with scmi_drivers. - scmi_child_dev_find() used to check for the presence of a device with the same name and protocol_id to avoid adding duplicates to the bus. Refactor the code to eliminate the redundant matching logic and consolidates the functionality for better maintainability and efficiency. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/bus.c | 43 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index 050a5ff5dc96a7df58edff5faeb8c1ec6228b97d..a30fd8e05e423e226a63833f309d8d30c400fabd 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -206,52 +206,49 @@ scmi_protocol_table_unregister(const struct scmi_device_id *id_table) scmi_protocol_device_unrequest(entry); } -static const struct scmi_device_id * -scmi_dev_match_id(struct scmi_device *scmi_dev, const struct scmi_driver *scmi_drv) +static int scmi_dev_match_by_id_table(struct scmi_device *scmi_dev, + const struct scmi_device_id *id_table) { - const struct scmi_device_id *id = scmi_drv->id_table; + if (!id_table || !id_table->name) + return 0; - if (!id) - return NULL; - - for (; id->protocol_id && id->name; id++) - if (id->protocol_id == scmi_dev->protocol_id && - !strcmp(id->name, scmi_dev->name)) - return id; + for (; id_table->protocol_id && id_table->name; id_table++) + if (id_table->protocol_id == scmi_dev->protocol_id && + !strcmp(id_table->name, scmi_dev->name)) + return 1; + return 0; +} - return NULL; +static int scmi_dev_match_id(struct scmi_device *scmi_dev, + const struct scmi_driver *scmi_drv) +{ + return scmi_dev_match_by_id_table(scmi_dev, scmi_drv->id_table); } static int scmi_dev_match(struct device *dev, const struct device_driver *drv) { const struct scmi_driver *scmi_drv = to_scmi_driver(drv); struct scmi_device *scmi_dev = to_scmi_dev(dev); - const struct scmi_device_id *id; - - id = scmi_dev_match_id(scmi_dev, scmi_drv); - if (id) - return 1; - return 0; + return scmi_dev_match_id(scmi_dev, scmi_drv); } static int scmi_match_by_id_table(struct device *dev, const void *data) { - struct scmi_device *sdev = to_scmi_dev(dev); + struct scmi_device *scmi_dev = to_scmi_dev(dev); const struct scmi_device_id *id_table = data; - return sdev->protocol_id == id_table->protocol_id && - (id_table->name && !strcmp(sdev->name, id_table->name)); + return scmi_dev_match_by_id_table(scmi_dev, id_table); } static struct scmi_device *scmi_child_dev_find(struct device *parent, int prot_id, const char *name) { - struct scmi_device_id id_table; + struct scmi_device_id id_table[2] = { 0 }; struct device *dev; - id_table.protocol_id = prot_id; - id_table.name = name; + id_table[0].protocol_id = prot_id; + id_table[0].name = name; dev = device_find_child(parent, &id_table, scmi_match_by_id_table); if (!dev)