mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ludovic Barre <ludovic.barre@st.com>
Cc: Jason Cooper <jason@lakedaemon.net>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] irqchip/stm32: fix init error handling
Date: Mon, 13 Aug 2018 16:22:44 +0100	[thread overview]
Message-ID: <99d66ae8-f497-0108-8168-6e46fdf2fe1d@arm.com> (raw)
In-Reply-To: <20180808120319.akmstg3ads325xcy@kili.mountain>

On 08/08/18 13:03, Dan Carpenter wrote:
> If there are any errors in stm32_exti_host_init() then it leads to a
> NULL dereference in the callers.  The function should clean up after
> itself.
> 
> Fixes: f9fc1745501e ("irqchip/stm32: Add host and driver data structures")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
> index 3df527fcf4e1..0a2088e12d96 100644
> --- a/drivers/irqchip/irq-stm32-exti.c
> +++ b/drivers/irqchip/irq-stm32-exti.c
> @@ -603,17 +603,24 @@ stm32_exti_host_data *stm32_exti_host_init(const struct stm32_exti_drv_data *dd,
>  					sizeof(struct stm32_exti_chip_data),
>  					GFP_KERNEL);
>  	if (!host_data->chips_data)
> -		return NULL;
> +		goto free_host_data;
>  
>  	host_data->base = of_iomap(node, 0);
>  	if (!host_data->base) {
>  		pr_err("%pOF: Unable to map registers\n", node);
> -		return NULL;
> +		goto free_chips_data;
>  	}
>  
>  	stm32_host_data = host_data;
>  
>  	return host_data;
> +
> +free_chips_data:
> +	kfree(host_data->chips_data);
> +free_host_data:
> +	kfree(host_data);
> +
> +	return NULL;
>  }
>  
>  static struct
> @@ -665,10 +672,8 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data,
>  	struct irq_domain *domain;
>  
>  	host_data = stm32_exti_host_init(drv_data, node);
> -	if (!host_data) {
> -		ret = -ENOMEM;
> -		goto out_free_mem;
> -	}
> +	if (!host_data)
> +		return -ENOMEM;
>  
>  	domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK,
>  				       &irq_exti_domain_ops, NULL);
> @@ -725,7 +730,6 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data,
>  	irq_domain_remove(domain);
>  out_unmap:
>  	iounmap(host_data->base);
> -out_free_mem:
>  	kfree(host_data->chips_data);
>  	kfree(host_data);
>  	return ret;
> @@ -752,10 +756,8 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
>  	}
>  
>  	host_data = stm32_exti_host_init(drv_data, node);
> -	if (!host_data) {
> -		ret = -ENOMEM;
> -		goto out_free_mem;
> -	}
> +	if (!host_data)
> +		return -ENOMEM;
>  
>  	for (i = 0; i < drv_data->bank_nr; i++)
>  		stm32_exti_chip_init(host_data, i, node);
> @@ -777,7 +779,6 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data,
>  
>  out_unmap:
>  	iounmap(host_data->base);
> -out_free_mem:
>  	kfree(host_data->chips_data);
>  	kfree(host_data);
>  	return ret;
> 

Queued, thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

      parent reply	other threads:[~2018-08-13 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-08 12:03 Dan Carpenter
2018-08-08 12:29 ` Ludovic BARRE
2018-08-13 15:22 ` Marc Zyngier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99d66ae8-f497-0108-8168-6e46fdf2fe1d@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=alexandre.torgue@st.com \
    --cc=dan.carpenter@oracle.com \
    --cc=jason@lakedaemon.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.barre@st.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®