mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 10:33:41 +02:00
firmware: arm_scmi: Refactor device matching logic to eliminate duplication
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.
Message-Id: <20250317-b4-scmi_minor_cleanup-v2-2-f4be99bd9864@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
This commit is contained in:
parent
db28d02c40
commit
3da2859ee5
|
|
@ -201,52 +201,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_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;
|
||||
}
|
||||
|
||||
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;
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user