irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
Subsystems (2)
PATCH 1/1 irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
First of all, there is no need to call kasprintf() if the previous allocation failed. Second, there is no need to call for kfree() when we know that its parameter is NULL. Refactor the code accordingly.
--- kernel/irq/irqdomain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/irq/irqdomain.c +3 -3
@@ -81,6 +81,8 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,char *n; fwid =kzalloc (sizeof (*fwid),GFP_KERNEL ); +if (!fwid) +return NULL ;switch (type) {case IRQCHIP_FWNODE_NAMED :
@@ -93,10 +95,8 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; } - -if (!fwid || !n) { +if (!n) {kfree (fwid); -kfree (n);return NULL ; }
Signature · 1 line
2.40.0.1.gaa8946217a0b
Quoted 25 lines · Andy Shevchenko
First of all, there is no need to call
kasprintf()if the previous allocation failed. Second, there is no need to call forkfree()when we know that its parameter is NULL. Refactor the code accordingly.Signed-off-by Andy Shevchenko <[email protected]>--- kernel/irq/irqdomain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/irq/irqdomain.c +2
-0@@ -81,6 +81,8 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, char *n; fwid =kzalloc (sizeof (*fwid),GFP_KERNEL ); +if (!fwid) +return NULL ;switch (type) {kernel/irq/irqdomain.c +0
-0case IRQCHIP_FWNODE_NAMED :@@ -93,10 +95,8 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
kernel/irq/irqdomain.c struct fwnode_handle · line 102
Quoted 10 lines
kernel/irq/irqdomain.c +1
-3n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; } - -if (!fwid || !n) { +if (!n) {kfree (fwid); -kfree (n);return NULL ; }
What are you trying to fix?
We have a common error handling path, which makes it easy to track the memory management. I don't think this sort of bike shedding adds much to the maintainability of this code.
Now if you have spotted an actual bug, I'm all ears.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 4 lines · Marc Zyngier
Quoted 3 lines · Andy Shevchenko
First of all, there is no need to call
kasprintf()if the previous allocation failed. Second, there is no need to call forkfree()when we know that its parameter is NULL. Refactor the code accordingly.
...
Quoted 4 lines
Quoted 4 lines
kernel/irq/irqdomain.c +0
-1n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; } -
Quoted 8 lines
kernel/irq/irqdomain.c struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, · line 101
Quoted 6 lines
kernel/irq/irqdomain.c +1
-2-if (!fwid || !n) { +if (!n) {kfree (fwid); -kfree (n);return NULL ; }What are you trying to fix?
I'm not trying to fix anything (there is no such statement from me), but I would think of some micro-optimization (speedup boot for unnoticeable time? Dunno.).
Quoted 3 lines
We have a common error handling path, which makes it easy to track the memory management. I don't think this sort of bike shedding adds much to the maintainability of this code.
Your call, of course, but I not often see in the kernel two or three attempts to allocate some memory and have grouped check for the failure.
Quoted 1 line
Now if you have spotted an actual bug, I'm all ears.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 4 lines · Marc Zyngier
Quoted 3 lines · Andy Shevchenko
First of all, there is no need to call
kasprintf()if the previous allocation failed. Second, there is no need to call forkfree()when we know that its parameter is NULL. Refactor the code accordingly....
Quoted 4 lines
Quoted 4 lines
kernel/irq/irqdomain.c +0
-1n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; } -Quoted 8 lines
kernel/irq/irqdomain.c struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, · line 101
Quoted 6 lines
kernel/irq/irqdomain.c +1
-2-if (!fwid || !n) { +if (!n) {kfree (fwid); -kfree (n);return NULL ; }What are you trying to fix?
Quoted 3 lines
I'm not trying to fix anything (there is no such statement from me), but I would think of some micro-optimization (speedup boot for unnoticeable time? Dunno.).
Error handling paths rarely qualify as an optimisation.
Quoted 7 lines
Quoted 4 lines
We have a common error handling path, which makes it easy to track the memory management. I don't think this sort of bike shedding adds much to the maintainability of this code.
Your call, of course, but I not often see in the kernel two or three attempts to allocate some memory and have grouped check for the failure.
Things like this[1]? Well, this is a pattern I use often enough. Maybe it isn't everybody's taste, but it suits me.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 4 lines · Marc Zyngier
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Marc Zyngier
On 2023-08-04 17:49, Andy Shevchenko wrote:
...
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
kernel/irq/irqdomain.c struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, · line 101
Quoted 10 lines
kernel/irq/irqdomain.c +1
-3n =kasprintf (GFP_KERNEL ,"irqchip@%pa" , pa);break ; } - -if (!fwid || !n) { +if (!n) {kfree (fwid); -kfree (n);return NULL ; }What are you trying to fix?
Quoted 5 lines
Quoted 3 lines
I'm not trying to fix anything (there is no such statement from me), but I would think of some micro-optimization (speedup boot for unnoticeable time? Dunno.).
Error handling paths rarely qualify as an optimisation.
OK.
...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
We have a common error handling path, which makes it easy to track the memory management. I don't think this sort of bike shedding adds much to the maintainability of this code.
Your call, of course, but I not often see in the kernel two or three attempts to allocate some memory and have grouped check for the failure.
Things like this[1]?
Yes.
Quoted 2 lines
Well, this is a pattern I use often enough. Maybe
it isn't everybody's taste, but it suits me.
Understand. Thanks for review!
Quoted 1 line
Signature · 2 lines
With Best Regards, Andy Shevchenko