* [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
@ 2023-08-04 16:49 Andy Shevchenko
2023-08-04 17:33 ` Marc Zyngier
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-08-04 16:49 UTC (permalink / raw)
To: Marc Zyngier, Johan Hovold, linux-kernel; +Cc: Thomas Gleixner, Andy Shevchenko
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
kernel/irq/irqdomain.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 0bdef4fe925b..d2bbba46c808 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -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;
}
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
2023-08-04 16:49 [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode() Andy Shevchenko
@ 2023-08-04 17:33 ` Marc Zyngier
2023-08-04 20:12 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Marc Zyngier @ 2023-08-04 17:33 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Johan Hovold, linux-kernel, Thomas Gleixner
On 2023-08-04 17:49, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> kernel/irq/irqdomain.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
> index 0bdef4fe925b..d2bbba46c808 100644
> --- a/kernel/irq/irqdomain.c
> +++ b/kernel/irq/irqdomain.c
> @@ -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;
> }
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.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
2023-08-04 17:33 ` Marc Zyngier
@ 2023-08-04 20:12 ` Andy Shevchenko
2023-08-04 22:24 ` Marc Zyngier
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2023-08-04 20:12 UTC (permalink / raw)
To: Marc Zyngier; +Cc: Johan Hovold, linux-kernel, Thomas Gleixner
On Fri, Aug 04, 2023 at 06:33:07PM +0100, Marc Zyngier wrote:
> On 2023-08-04 17:49, Andy Shevchenko wrote:
> > 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.
...
> > n = kasprintf(GFP_KERNEL, "irqchip@%pa", pa);
> > break;
> > }
> > -
> > - 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.).
> 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.
> Now if you have spotted an actual bug, I'm all ears.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
2023-08-04 20:12 ` Andy Shevchenko
@ 2023-08-04 22:24 ` Marc Zyngier
2023-08-07 15:06 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Marc Zyngier @ 2023-08-04 22:24 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Johan Hovold, linux-kernel, Thomas Gleixner
On Fri, 04 Aug 2023 21:12:11 +0100,
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Aug 04, 2023 at 06:33:07PM +0100, Marc Zyngier wrote:
> > On 2023-08-04 17:49, Andy Shevchenko wrote:
> > > 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.
>
> ...
>
> > > n = kasprintf(GFP_KERNEL, "irqchip@%pa", pa);
> > > break;
> > > }
> > > -
> > > - 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.).
Error handling paths rarely qualify as an optimisation.
>
> > 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.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/irqchip/irq-gic-v3-its.c#n3438
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode()
2023-08-04 22:24 ` Marc Zyngier
@ 2023-08-07 15:06 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2023-08-07 15:06 UTC (permalink / raw)
To: Marc Zyngier; +Cc: Johan Hovold, linux-kernel, Thomas Gleixner
On Fri, Aug 04, 2023 at 11:24:02PM +0100, Marc Zyngier wrote:
> On Fri, 04 Aug 2023 21:12:11 +0100,
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Fri, Aug 04, 2023 at 06:33:07PM +0100, Marc Zyngier wrote:
> > > On 2023-08-04 17:49, Andy Shevchenko wrote:
...
> > > > n = kasprintf(GFP_KERNEL, "irqchip@%pa", pa);
> > > > break;
> > > > }
> > > > -
> > > > - 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.).
>
> Error handling paths rarely qualify as an optimisation.
OK.
...
> > > 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.
> Well, this is a pattern I use often enough. Maybe
> it isn't everybody's taste, but it suits me.
Understand. Thanks for review!
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/irqchip/irq-gic-v3-its.c#n3438
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-07 15:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04 16:49 [PATCH v1 1/1] irqdomain: Refactor error path in __irq_domain_alloc_fwnode() Andy Shevchenko
2023-08-04 17:33 ` Marc Zyngier
2023-08-04 20:12 ` Andy Shevchenko
2023-08-04 22:24 ` Marc Zyngier
2023-08-07 15:06 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox