-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
depmod: Use shared/ more often #193
Conversation
Btw if you want to de-duplicate depmod, here's another similar task #62 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor suggestions, but looking great overall.
tools/depmod.c
Outdated
continue; | ||
} else if (err < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: there is no need for an else after continue/return/break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged into one, since an error here is the unlikely code path.
tools/depmod.c
Outdated
@@ -2071,39 +2037,42 @@ static inline const char *mod_get_compressed_path(const struct mod *mod) | |||
static int output_deps(struct depmod *depmod, FILE *out) | |||
{ | |||
size_t i; | |||
struct array array; | |||
|
|||
array_init(&array, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick grep on a couple kernels shows we peak at 30, so let's bump this to 32 or even 64 if we want to splash out :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted with 64
tools/depmod.c
Outdated
@@ -2112,28 +2081,28 @@ static int output_deps_bin(struct depmod *depmod, FILE *out) | |||
if (idx == NULL) | |||
return -ENOMEM; | |||
|
|||
array_init(&array, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted with 64
tools/depmod.c
Outdated
} | ||
line[linepos] = '\0'; | ||
line = sbuf.used > 0 ? strbuf_str(&sbuf) : ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Let's drop the strbuf.used
check here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted, forgot that it's safe now.
tools/depmod.c
Outdated
for (idx = 0; idx < depmod->modules.count; idx++) { | ||
struct mod *m = depmod->modules.array[idx]; | ||
m->idx = idx; | ||
if (depmod->modules.count > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted
2261971
to
75741c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few nits, but LGTM
The shared/array implementation is already used within depmod, but not for dependency output. Adding it here reduces the amount of custom code in depmod, simplifies auditing, reduces binary size, and has the nice benefit of slightly faster runtime due to memory reusage. Signed-off-by: Tobias Stoeckmann <[email protected]>
Use shared/strbuf instead of manually re-implementing its features. Reduces the amount of custom code in depmod, simplifies auditing, reduces binary size, and has the nice benefit of slightly faster runtime due to memory reusage. Signed-off-by: Tobias Stoeckmann <[email protected]>
Calling qsort with NULL argument is invalid, although size 0 would prevent anything bad from happening. Make sure that UBSAN is not triggered. Signed-off-by: Tobias Stoeckmann <[email protected]>
75741c5
to
5483e98
Compare
The shared/array implementation is already used within depmod, but not for dependency output. Adding it here reduces the amount of custom code in depmod, simplifies auditing, reduces binary size, and has the nice benefit of slightly faster runtime due to memory reusage. Signed-off-by: Tobias Stoeckmann <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #193 Signed-off-by: Lucas De Marchi <[email protected]>
Use shared/strbuf instead of manually re-implementing its features. Reduces the amount of custom code in depmod, simplifies auditing, reduces binary size, and has the nice benefit of slightly faster runtime due to memory reusage. Signed-off-by: Tobias Stoeckmann <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #193 Signed-off-by: Lucas De Marchi <[email protected]>
Calling qsort with NULL argument is invalid, although size 0 would prevent anything bad from happening. Make sure that UBSAN is not triggered. Signed-off-by: Tobias Stoeckmann <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #193 Signed-off-by: Lucas De Marchi <[email protected]>
Applied, thanks. |
The dependency output code basically contained its own version of shared/array and shared/strbuf.
Use these implementations for easier code, smaller binary size and slightly faster runtime due to reusage of memory.