Skip to content

Commit 4c48aed

Browse files
Zijun Hugregkh
authored andcommitted
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>
1 parent eca7103 commit 4c48aed

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/base/auxiliary.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,18 @@
171171
static const struct auxiliary_device_id *auxiliary_match_id(const struct auxiliary_device_id *id,
172172
const struct auxiliary_device *auxdev)
173173
{
174-
for (; id->name[0]; id++) {
175-
const char *p = strrchr(dev_name(&auxdev->dev), '.');
176-
int match_size;
174+
const char *auxdev_name = dev_name(&auxdev->dev);
175+
const char *p = strrchr(auxdev_name, '.');
176+
int match_size;
177177

178-
if (!p)
179-
continue;
180-
match_size = p - dev_name(&auxdev->dev);
178+
if (!p)
179+
return NULL;
180+
match_size = p - auxdev_name;
181181

182+
for (; id->name[0]; id++) {
182183
/* use dev_name(&auxdev->dev) prefix before last '.' char to match to */
183184
if (strlen(id->name) == match_size &&
184-
!strncmp(dev_name(&auxdev->dev), id->name, match_size))
185+
!strncmp(auxdev_name, id->name, match_size))
185186
return id;
186187
}
187188
return NULL;

0 commit comments

Comments
 (0)