* [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer
@ 2025-03-12 11:14 Sudeep Holla
2025-03-12 11:14 ` [PATCH 1/3] firmware: arm_scmi: Ensure scmi_devices are always matched by name as well Sudeep Holla
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:14 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sudeep Holla, Cristian Marussi
These cleanup centralizes error logging for SCMI device creation into a
single helper function, _scmi_device_create(), consolidates the device
matching logic into a single function, and ensures that devices must
have a name for registration, removing support for unnamed devices while
matching the devices and drivers for probing.
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
Sudeep Holla (3):
firmware: arm_scmi: Ensure scmi_devices are always matched by name as well
firmware: arm_scmi: Refactor device matching logic to eliminate duplication
firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper
drivers/firmware/arm_scmi/bus.c | 75 ++++++++++++++++++++------------------
drivers/firmware/arm_scmi/driver.c | 8 +---
2 files changed, 40 insertions(+), 43 deletions(-)
---
base-commit: 80e54e84911a923c40d7bee33a34c1b4be148d7a
change-id: 20250312-b4-scmi_minor_cleanup-8f85228d435c
Best regards,
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] firmware: arm_scmi: Ensure scmi_devices are always matched by name as well
2025-03-12 11:14 [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
@ 2025-03-12 11:14 ` Sudeep Holla
2025-03-12 11:14 ` [PATCH 2/3] firmware: arm_scmi: Refactor device matching logic to eliminate duplication Sudeep Holla
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:14 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sudeep Holla, Cristian Marussi
Currently, devices without a name in the id_table cannot register drivers,
and no scmi_device is created without a name via scmi_device_create().
However, the function __scmi_device_create() allows devices with no name,
which are then labeled as "unknown."
Removes support for matching scmi_device instances without a name,
ensuring consistency across the driver registration and probing process.
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
drivers/firmware/arm_scmi/bus.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index a3386bf36de508d312e2c4fa2e27ba62ba3776a0..050a5ff5dc96a7df58edff5faeb8c1ec6228b97d 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -214,13 +214,10 @@ scmi_dev_match_id(struct scmi_device *scmi_dev, const struct scmi_driver *scmi_d
if (!id)
return NULL;
- for (; id->protocol_id; id++)
- if (id->protocol_id == scmi_dev->protocol_id) {
- if (!id->name)
- return id;
- else if (!strcmp(id->name, scmi_dev->name))
- return id;
- }
+ for (; id->protocol_id && id->name; id++)
+ if (id->protocol_id == scmi_dev->protocol_id &&
+ !strcmp(id->name, scmi_dev->name))
+ return id;
return NULL;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] firmware: arm_scmi: Refactor device matching logic to eliminate duplication
2025-03-12 11:14 [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
2025-03-12 11:14 ` [PATCH 1/3] firmware: arm_scmi: Ensure scmi_devices are always matched by name as well Sudeep Holla
@ 2025-03-12 11:14 ` Sudeep Holla
2025-03-12 11:14 ` [PATCH 3/3] firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper Sudeep Holla
2025-03-12 11:20 ` [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
3 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:14 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sudeep Holla, Cristian Marussi
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 <sudeep.holla@arm.com>
---
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)
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper
2025-03-12 11:14 [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
2025-03-12 11:14 ` [PATCH 1/3] firmware: arm_scmi: Ensure scmi_devices are always matched by name as well Sudeep Holla
2025-03-12 11:14 ` [PATCH 2/3] firmware: arm_scmi: Refactor device matching logic to eliminate duplication Sudeep Holla
@ 2025-03-12 11:14 ` Sudeep Holla
2025-03-12 11:20 ` [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
3 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:14 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Sudeep Holla, Cristian Marussi
Refactors the error logging related to SCMI device creation. The goal
is to remove duplicated error-handling code and centralize it into a
single helper function: _scmi_device_create().
By doing so, any code redundancy around error logging is avoided, as
error logging during device creation will now be handled by a unified
helper function.
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
drivers/firmware/arm_scmi/bus.c | 29 +++++++++++++++++++----------
drivers/firmware/arm_scmi/driver.c | 8 +-------
2 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index a30fd8e05e423e226a63833f309d8d30c400fabd..493e2c63b107fd9063f11034b71d65f567bb0778 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -411,6 +411,20 @@ __scmi_device_create(struct device_node *np, struct device *parent,
return NULL;
}
+static struct scmi_device *
+_scmi_device_create(struct device_node *np, struct device *parent,
+ int protocol, const char *name)
+{
+ struct scmi_device *sdev;
+
+ sdev = __scmi_device_create(np, parent, protocol, name);
+ if (!sdev)
+ pr_err("(%s) Failed to create device for protocol 0x%x (%s)\n",
+ of_node_full_name(parent->of_node), protocol, name);
+
+ return sdev;
+}
+
/**
* scmi_device_create - A method to create one or more SCMI devices
*
@@ -443,7 +457,7 @@ struct scmi_device *scmi_device_create(struct device_node *np,
struct scmi_device *scmi_dev = NULL;
if (name)
- return __scmi_device_create(np, parent, protocol, name);
+ return _scmi_device_create(np, parent, protocol, name);
mutex_lock(&scmi_requested_devices_mtx);
phead = idr_find(&scmi_requested_devices, protocol);
@@ -457,18 +471,13 @@ struct scmi_device *scmi_device_create(struct device_node *np,
list_for_each_entry(rdev, phead, node) {
struct scmi_device *sdev;
- sdev = __scmi_device_create(np, parent,
- rdev->id_table->protocol_id,
- rdev->id_table->name);
- /* Report errors and carry on... */
+ sdev = _scmi_device_create(np, parent,
+ rdev->id_table->protocol_id,
+ rdev->id_table->name);
if (sdev)
scmi_dev = sdev;
- else
- pr_err("(%s) Failed to create device for protocol 0x%x (%s)\n",
- of_node_full_name(parent->of_node),
- rdev->id_table->protocol_id,
- rdev->id_table->name);
}
+
mutex_unlock(&scmi_requested_devices_mtx);
return scmi_dev;
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 60050da54bf24c0245290e846f91aea62392855b..b80c574cb3bb2f12b2980fc844ea3da10abdc9f1 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -439,14 +439,8 @@ static void scmi_create_protocol_devices(struct device_node *np,
struct scmi_info *info,
int prot_id, const char *name)
{
- struct scmi_device *sdev;
-
mutex_lock(&info->devreq_mtx);
- sdev = scmi_device_create(np, info->dev, prot_id, name);
- if (name && !sdev)
- dev_err(info->dev,
- "failed to create device for protocol 0x%X (%s)\n",
- prot_id, name);
+ scmi_device_create(np, info->dev, prot_id, name);
mutex_unlock(&info->devreq_mtx);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer
2025-03-12 11:14 [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
` (2 preceding siblings ...)
2025-03-12 11:14 ` [PATCH 3/3] firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper Sudeep Holla
@ 2025-03-12 11:20 ` Sudeep Holla
3 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:20 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Cristian Marussi
On Wed, Mar 12, 2025 at 11:14:31AM +0000, Sudeep Holla wrote:
> These cleanup centralizes error logging for SCMI device creation into a
> single helper function, _scmi_device_create(), consolidates the device
> matching logic into a single function, and ensures that devices must
> have a name for registration, removing support for unnamed devices while
> matching the devices and drivers for probing.
>
Please ignore this as I messed by and somehow managed to not include
arm-scmi list with wrong usage of b4 send, will resend soon.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer
@ 2025-03-12 11:40 Sudeep Holla
0 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2025-03-12 11:40 UTC (permalink / raw)
To: arm-scmi, linux-arm-kernel; +Cc: Sudeep Holla, Cristian Marussi
These cleanup centralizes error logging for SCMI device creation into a
single helper function, _scmi_device_create(), consolidates the device
matching logic into a single function, and ensures that devices must
have a name for registration, removing support for unnamed devices while
matching the devices and drivers for probing.
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
Sudeep Holla (3):
firmware: arm_scmi: Ensure scmi_devices are always matched by name as well
firmware: arm_scmi: Refactor device matching logic to eliminate duplication
firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper
drivers/firmware/arm_scmi/bus.c | 75 ++++++++++++++++++++------------------
drivers/firmware/arm_scmi/driver.c | 8 +---
2 files changed, 40 insertions(+), 43 deletions(-)
---
base-commit: 80e54e84911a923c40d7bee33a34c1b4be148d7a
change-id: 20250312-b4-scmi_minor_cleanup-8f85228d435c
Best regards,
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-12 13:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12 11:14 [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
2025-03-12 11:14 ` [PATCH 1/3] firmware: arm_scmi: Ensure scmi_devices are always matched by name as well Sudeep Holla
2025-03-12 11:14 ` [PATCH 2/3] firmware: arm_scmi: Refactor device matching logic to eliminate duplication Sudeep Holla
2025-03-12 11:14 ` [PATCH 3/3] firmware: arm_scmi: Refactor error logging from SCMI device creation to single helper Sudeep Holla
2025-03-12 11:20 ` [PATCH 0/3] firmware: arm_scmi: Minor cleanups in the scmi bus layer Sudeep Holla
-- strict thread matches above, loose matches on Subject: below --
2025-03-12 11:40 Sudeep Holla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox