Skip to content

Commit

Permalink
modpost: refactor do_vmbus_entry()
Browse files Browse the repository at this point in the history
Optimize the size of guid_name[], as it only requires 1 additional byte
for '\0' instead of 2.

Simplify the loop by incrementing the iterator by 1 instead of 2.

Remove the unnecessary TO_NATIVE() call, as the guid is represented as
a byte stream.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
  • Loading branch information
Masahiro Yamada committed Dec 28, 2024
1 parent bf36b4b commit e1352d7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions scripts/mod/file2alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,15 +812,13 @@ static void do_virtio_entry(struct module *mod, void *symval)
* Each byte of the guid will be represented by two hex characters
* in the name.
*/

static void do_vmbus_entry(struct module *mod, void *symval)
{
int i;
DEF_FIELD_ADDR(symval, hv_vmbus_device_id, guid);
char guid_name[(sizeof(*guid) + 1) * 2];
char guid_name[sizeof(*guid) * 2 + 1];

for (i = 0; i < (sizeof(*guid) * 2); i += 2)
sprintf(&guid_name[i], "%02x", TO_NATIVE((guid->b)[i/2]));
for (int i = 0; i < sizeof(*guid); i++)
sprintf(&guid_name[i * 2], "%02x", guid->b[i]);

module_alias_printf(mod, false, "vmbus:%s", guid_name);
}
Expand Down

0 comments on commit e1352d7

Please sign in to comment.