LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au,
	allison@lohutok.net, tglx@linutronix.de, clg@kaod.org,
	groug@kaod.org
Cc: linuxppc-dev@lists.ozlabs.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/xive: Add some error handling code to 'xive_spapr_init()'
Date: Tue, 1 Feb 2022 12:31:55 +0100	[thread overview]
Message-ID: <1ea13a2a-90fd-07d3-2031-19e81ea349b4@csgroup.eu> (raw)
In-Reply-To: <20190801110956.8517-1-christophe.jaillet@wanadoo.fr>

Hi,

Le 01/08/2019 à 13:09, Christophe JAILLET a écrit :
> 'xive_irq_bitmap_add()' can return -ENOMEM.
> In this case, we should free the memory already allocated and return
> 'false' to the caller.
> 
> Also add an error path which undoes the 'tima = ioremap(...)'

This old patch doesn't apply, if it is still relevant can you please 
rebase ?

Thanks
Christophe

> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> NOT compile tested (I don't have a cross compiler and won't install one).
> So if some correction or improvement are needed, feel free to propose and
> commit it directly.
> ---
>   arch/powerpc/sysdev/xive/spapr.c | 36 +++++++++++++++++++++++++-------
>   1 file changed, 28 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
> index 52198131c75e..b3ae0b76c433 100644
> --- a/arch/powerpc/sysdev/xive/spapr.c
> +++ b/arch/powerpc/sysdev/xive/spapr.c
> @@ -64,6 +64,17 @@ static int xive_irq_bitmap_add(int base, int count)
>   	return 0;
>   }
>   
> +static void xive_irq_bitmap_remove_all(void)
> +{
> +	struct xive_irq_bitmap *xibm, *tmp;
> +
> +	list_for_each_entry_safe(xibm, tmp, &xive_irq_bitmaps, list) {
> +		list_del(&xibm->list);
> +		kfree(xibm->bitmap);
> +		kfree(xibm);
> +	}
> +}
> +
>   static int __xive_irq_bitmap_alloc(struct xive_irq_bitmap *xibm)
>   {
>   	int irq;
> @@ -723,7 +734,7 @@ bool __init xive_spapr_init(void)
>   	u32 val;
>   	u32 len;
>   	const __be32 *reg;
> -	int i;
> +	int i, err;
>   
>   	if (xive_spapr_disabled())
>   		return false;
> @@ -748,23 +759,26 @@ bool __init xive_spapr_init(void)
>   	}
>   
>   	if (!xive_get_max_prio(&max_prio))
> -		return false;
> +		goto err_unmap;
>   
>   	/* Feed the IRQ number allocator with the ranges given in the DT */
>   	reg = of_get_property(np, "ibm,xive-lisn-ranges", &len);
>   	if (!reg) {
>   		pr_err("Failed to read 'ibm,xive-lisn-ranges' property\n");
> -		return false;
> +		goto err_unmap;
>   	}
>   
>   	if (len % (2 * sizeof(u32)) != 0) {
>   		pr_err("invalid 'ibm,xive-lisn-ranges' property\n");
> -		return false;
> +		goto err_unmap;
>   	}
>   
> -	for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2)
> -		xive_irq_bitmap_add(be32_to_cpu(reg[0]),
> -				    be32_to_cpu(reg[1]));
> +	for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2) {
> +		err = xive_irq_bitmap_add(be32_to_cpu(reg[0]),
> +					  be32_to_cpu(reg[1]));
> +		if (err < 0)
> +			goto err_mem_free;
> +	}
>   
>   	/* Iterate the EQ sizes and pick one */
>   	of_property_for_each_u32(np, "ibm,xive-eq-sizes", prop, reg, val) {
> @@ -775,8 +789,14 @@ bool __init xive_spapr_init(void)
>   
>   	/* Initialize XIVE core with our backend */
>   	if (!xive_core_init(&xive_spapr_ops, tima, TM_QW1_OS, max_prio))
> -		return false;
> +		goto err_mem_free;
>   
>   	pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10));
>   	return true;
> +
> +err_mem_free:
> +	xive_irq_bitmap_remove_all();
> +err_unmap:
> +	iounmap(tima);
> +	return false;
>   }

  parent reply	other threads:[~2022-02-01 11:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-01 11:09 [PATCH] powerpc/xive: Add some error handling code to 'xive_spapr_init()' Christophe JAILLET
2019-08-01 11:31 ` Cédric Le Goater
2022-02-01 11:31 ` Christophe Leroy [this message]
2022-02-01 12:32   ` Christophe JAILLET
2022-02-01 13:39     ` Christophe Leroy

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=1ea13a2a-90fd-07d3-2031-19e81ea349b4@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=allison@lohutok.net \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=clg@kaod.org \
    --cc=groug@kaod.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --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