[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <84f2ea9ee0c08c8826c0f26c4a6291c9@kernel.org>
Date: Fri, 04 Aug 2023 18:33:07 +0100
From: Marc Zyngier <maz@...nel.org>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Johan Hovold <johan+linaro@...nel.org>,
linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH v1 1/1] irqdomain: Refactor error path in
__irq_domain_alloc_fwnode()
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@...ux.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...
Powered by blists - more mailing lists