driver core: auxiliary bus: Optimize logic of auxiliary_match_id()
auxiliary_match_id() repeatedly calculates variable @match_size in the for loop, however, the variable is fixed actually, so it is enough to only calculate the variable once. Besides, the function should return directly if name of the @auxdev does not include '.', but it still iterates over the ID table. Additionally, statement 'dev_name(&auxdev->dev)' is fixed, but may be evaluated more than 3 times. Optimize logic of the function by: - Move the logic calculating the variable out of the for loop - Return NULL directly if @p == NULL - Give the statement an dedicated local variable @auxdev_name Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com> Link: https://lore.kernel.org/r/20250903-fix_auxbus-v2-1-3eae8374fd65@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
eca7103869
commit
4c48aed6df
|
@ -171,17 +171,18 @@
|
||||||
static const struct auxiliary_device_id *auxiliary_match_id(const struct auxiliary_device_id *id,
|
static const struct auxiliary_device_id *auxiliary_match_id(const struct auxiliary_device_id *id,
|
||||||
const struct auxiliary_device *auxdev)
|
const struct auxiliary_device *auxdev)
|
||||||
{
|
{
|
||||||
|
const char *auxdev_name = dev_name(&auxdev->dev);
|
||||||
|
const char *p = strrchr(auxdev_name, '.');
|
||||||
|
int match_size;
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
return NULL;
|
||||||
|
match_size = p - auxdev_name;
|
||||||
|
|
||||||
for (; id->name[0]; id++) {
|
for (; id->name[0]; id++) {
|
||||||
const char *p = strrchr(dev_name(&auxdev->dev), '.');
|
|
||||||
int match_size;
|
|
||||||
|
|
||||||
if (!p)
|
|
||||||
continue;
|
|
||||||
match_size = p - dev_name(&auxdev->dev);
|
|
||||||
|
|
||||||
/* use dev_name(&auxdev->dev) prefix before last '.' char to match to */
|
/* use dev_name(&auxdev->dev) prefix before last '.' char to match to */
|
||||||
if (strlen(id->name) == match_size &&
|
if (strlen(id->name) == match_size &&
|
||||||
!strncmp(dev_name(&auxdev->dev), id->name, match_size))
|
!strncmp(auxdev_name, id->name, match_size))
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue