kernel/module: Delete an error message for a failed memory allocation in add_module_usage()
PATCH 1/1 kernel/module: Delete an error message for a failed memory allocation in add_module_usage()
From: Markus Elfring <[email protected]>
Date: Fri, 6 Oct 2017 16:27:26 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- kernel/module.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/module.c +1 -3
@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b)pr_debug ("Allocating new usage for %s.\n" , a->name); use =kmalloc (sizeof (*use),GFP_ATOMIC ); -if (!use) { -pr_warn ("%s: out of memory loading\n" , a->name); +if (!use)return -ENOMEM ; - } use->source = a; use->target = b;
Signature · 1 line
2.14.2
+++ SF Markus Elfring [06/10/17 17:12 +0200]:
Quoted 17 lines
From: Markus Elfring <[email protected]>
Date: Fri, 6 Oct 2017 16:27:26 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
kernel/module.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)kernel/module.c +0
-0
kernel/module.c static int add_module_usage(struct module *a, struct module *b) · line 843
Quoted 8 lines
kernel/module.c +1
-3@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b)pr_debug ("Allocating new usage for %s.\n" , a->name); use =kmalloc (sizeof (*use),GFP_ATOMIC ); -if (!use) { -pr_warn ("%s: out of memory loading\n" , a->name); +if (!use)return -ENOMEM ; - }
IMO this is removing useful information. Although stack traces are generated on alloc failures, the extra print also tells us which module we were trying to load at the time the memory allocation failed.
Jessica
Quoted 19 lines · Jessica Yu
+++ SF Markus Elfring [06/10/17 17:12 +0200]:
Quoted 18 lines
From: Markus Elfring <[email protected]>
Date: Fri, 6 Oct 2017 16:27:26 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
kernel/module.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)kernel/module.c +0
-0@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b)
Quoted 12 lines
kernel/module.c static int add_module_usage(struct module *a, struct module *b) · line 843
Quoted 7 lines
kernel/module.c +1
-3pr_debug ("Allocating new usage for %s.\n" , a->name); use =kmalloc (sizeof (*use),GFP_ATOMIC ); -if (!use) { -pr_warn ("%s: out of memory loading\n" , a->name); +if (!use)return -ENOMEM ; - }IMO this is removing useful information. Although stack traces are generated on alloc failures, the extra print also tells us which module we were trying to load at the time the memory allocation failed.
This is a small allocation so it can't fail in current kernels. I can't imagine a situation where this could fail and it wasn't dead easy to debug. Most modules are loaded at boot so it's not likely to fail, but if it did, it would be easy to reproduce. If it's not loaded at boot it's probably really easy to tell which module we're loading.
regards,
dan carpenter
Quoted 11 lines
kernel/module.c static int add_module_usage(struct module *a, struct module *b) · line 843
Quoted 9 lines
kernel/module.c +1
-3@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b) pr_debug("Allocating new usage for %s.\n", a->name); use = kmalloc(sizeof(*use), GFP_ATOMIC); - if (!use) { - pr_warn("%s: out of memory loading\n", a->name); + if (!use) return -ENOMEM; - }IMO this is removing useful information.
How do you think about to clarify the circumstances any further?
Quoted 1 line
Although stack traces are generated on alloc failures,
Do you ever want to switch them off for special use cases?
Quoted 2 lines
the extra print also tells us which module we were trying to load at the time the memory allocation failed.
Can a default allocation failure report provide the same information already?
Regards,
Markus
+++ Dan Carpenter [19/10/17 13:30 +0300]:
Quoted 33 lines · Jessica Yu
Quoted 19 lines
+++ SF Markus Elfring [06/10/17 17:12 +0200]:
Quoted 18 lines
From: Markus Elfring <[email protected]>
Date: Fri, 6 Oct 2017 16:27:26 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
kernel/module.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)kernel/module.c +0
-0@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b)Quoted 12 lines
kernel/module.c static int add_module_usage(struct module *a, struct module *b) · line 843
Quoted 7 lines
kernel/module.c +1
-3pr_debug ("Allocating new usage for %s.\n" , a->name); use =kmalloc (sizeof (*use),GFP_ATOMIC ); -if (!use) { -pr_warn ("%s: out of memory loading\n" , a->name); +if (!use)return -ENOMEM ; - }IMO this is removing useful information. Although stack traces are generated on alloc failures, the extra print also tells us which module we were trying to load at the time the memory allocation failed.
Quoted 5 lines
This is a small allocation so it can't fail in current kernels. I can't imagine a situation where this could fail and it wasn't dead easy to debug. Most modules are loaded at boot so it's not likely to fail, but if it did, it would be easy to reproduce. If it's not loaded at boot it's probably really easy to tell which module we're loading.
Yeah, good points. And on second thought, we normally don't print warnings for every small alloc failure in the kernel anyway (that would be utterly superfluous), the error code itself is sufficient. And in the module loader this seems to be the only printk out of the dozen alloc calls we do, so I'm OK with removing this one.
Thanks,
Jessica
Jessica Yu
Applied+++ SF Markus Elfring [06/10/17 17:12 +0200]:
Quoted 8 lines
From: Markus Elfring <[email protected]>
Date: Fri, 6 Oct 2017 16:27:26 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Applied to modules-next, thanks.
Jessica
Quoted 23 lines
---
kernel/module.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)kernel/module.c +1
-3@@ -837,10 +837,8 @@ static int add_module_usage(struct module *a, struct module *b)pr_debug ("Allocating new usage for %s.\n" , a->name); use =kmalloc (sizeof (*use),GFP_ATOMIC ); -if (!use) { -pr_warn ("%s: out of memory loading\n" , a->name); +if (!use)return -ENOMEM ; - } use->source = a; use->target = b;Signature · 1 line
2.14.2
Quoted 11 lines
Quoted 5 lines
This is a small allocation so it can't fail in current kernels. I can't imagine a situation where this could fail and it wasn't dead easy to debug. Most modules are loaded at boot so it's not likely to fail, but if it did, it would be easy to reproduce. If it's not loaded at boot it's probably really easy to tell which module we're loading.
Yeah, good points. And on second thought, we normally don't print warnings for every small alloc failure in the kernel anyway (that would be utterly superfluous), the error code itself is sufficient. And in the module loader this seems to be the only printk out of the dozen alloc calls we do, so I'm OK with removing this one.
Thanks for your constructive feedback.
Can it help to improve the corresponding documentation for Linux programming interfaces a bit more?
Regards,
Markus
Quoted 7 lines
Quoted 5 lines
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>Applied to modules-next, thanks.
Thanks for your acceptance of this update suggestion after a bit of clarification.
Do you see any need that I should extend subsequent commit messages for this software transformation pattern?
Regards,
Markus
Quoted 4 lines · SF Markus Elfring
Quoted 4 lines
Quoted 4 lines
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>Applied to modules-next, thanks.
Thanks for your acceptance of this update suggestion after a bit of clarification.
Do you see any need that I should extend subsequent commit messages for this software transformation pattern?
Add a description of _why_ this is being done.
Something like:
"because there is a dump_stack() done on allocation failures
without __GFP_JNOWARN"
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>Applied to modules-next, thanks.
Thanks for your acceptance of this update suggestion after a bit of clarification.
Do you see any need that I should extend subsequent commit messages for this software transformation pattern?
Quoted 6 lines
Add a description of _why_ this is being done.
Something like:
"because there is a
dump_stack()done on allocation failures
without__GFP_JNOWARN"
How do you think about to convert such a description into a special format for further reference documentation?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · SF Markus Elfring
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
[]
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Do you see any need that I should extend subsequent commit messages for this software transformation pattern?
Add a description of _why_ this is being done.
Quoted 7 lines
Quoted 4 lines
Something like:
"because there is a
dump_stack()done on allocation failures
without__GFP_JNOWARN"How do you think about to convert such a description into a special format for further reference documentation?
I think it's a bad idea if it's a "special" format.
Always write _why_ some code is being changed.
People could read the commit descriptions and would not need to take extra time to lookup external references.
Maybe add something like
"see (commit <foo> or <file>)" for additional details"
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Something like:
"because there is a
dump_stack()done on allocation failures
without__GFP_JNOWARN"How do you think about to convert such a description into a special format for further reference documentation?
I think it's a bad idea if it's a "special" format.
Will it be nice to represent corresponding details as a better “restructured text”?
Quoted 4 lines
Always write _why_ some code is being changed.
People could read the commit descriptions and would not need to take extra time to lookup external references.
I would appreciate if I could copy a widely accepted explanation.
Quoted 2 lines
Maybe add something like
"see (commit <foo> or <file>)" for additional details"
Are there any related extensions possible besides other background information?
Regards,
Markus