From: Milton Miller <miltonm@bga.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/4] irq: radix_tree_insert can fail
Date: Wed, 25 May 2011 01:34:18 -0500 [thread overview]
Message-ID: <radix-insert-can-fail@mdm.bga.com> (raw)
In-Reply-To: <generic-irq-changes@mdm.bga.com>
Check the insert, and if it fails cleanup and free all partial work.
Sparse irq was not checking the return code from radix_tree_insert,
but it may need to allocate memory and can fail. If it failed,
it still claimed success to the caller but the affected irq(s) are
unavailable and the reference to the affected descriptors is leaked.
Signed-off-by: Milton Miller <miltonm@bga.com>
---
I started by tring to change free_desc to take the descriptor pointer
and pushing that down, but that soon ran into conflicts between the
array and sparse implementations, and/or the old dynamic irq cleanup
function that is still used by some architectures. This version is
targeted, and also protects against scribbles to irq_data.irq.
Index: work.git/kernel/irq/irqdesc.c
===================================================================
--- work.git.orig/kernel/irq/irqdesc.c 2011-05-23 13:46:09.197635762 -0500
+++ work.git/kernel/irq/irqdesc.c 2011-05-23 14:29:22.960588100 -0500
@@ -164,10 +164,8 @@ err_desc:
return NULL;
}
-static void free_desc(unsigned int irq)
+static void free_a_desc(unsigned int irq, struct irq_desc *desc)
{
- struct irq_desc *desc = irq_to_desc(irq);
-
unregister_irq_proc(irq, desc);
mutex_lock(&sparse_irq_lock);
@@ -179,21 +177,30 @@ static void free_desc(unsigned int irq)
kfree(desc);
}
+static void free_desc(unsigned int irq)
+{
+ free_a_desc(irq, irq_to_desc(irq));
+}
+
static int alloc_descs(unsigned int start, unsigned int cnt, int node)
{
struct irq_desc *desc;
- int i;
+ int i, res;
for (i = 0; i < cnt; i++) {
desc = alloc_desc(start + i, node);
if (!desc)
goto err;
mutex_lock(&sparse_irq_lock);
- irq_insert_desc(start + i, desc);
+ res = irq_insert_desc(start + i, desc);
mutex_unlock(&sparse_irq_lock);
+ if (res)
+ goto err_insert;
}
return start;
+err_insert:
+ free_a_desc(start + i, desc);
err:
for (i--; i >= 0; i--)
free_desc(start + i);
next prev parent reply other threads:[~2011-05-25 6:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <generic-irq-changes@mdm.bga.com>
2011-05-25 6:34 ` [PATCH RFC 4/4] irq: allow a per-allocation upper limit when allocating irqs Milton Miller
2011-05-25 7:55 ` Ingo Molnar
2011-05-25 8:32 ` Thomas Gleixner
2011-05-27 3:38 ` Grant Likely
2011-05-25 6:34 ` [PATCH 3/4] irq: remove unnecessary __ref on irq_alloc_descs Milton Miller
2011-05-25 6:34 ` Milton Miller [this message]
2011-05-25 8:18 ` [PATCH 2/4] irq: radix_tree_insert can fail Thomas Gleixner
2011-05-25 10:48 ` Milton Miller
2011-05-25 6:34 ` [PATCH 1/4] sparse irq: protect irq_to_desc against irq_free_descs Milton Miller
2011-05-25 8:14 ` Thomas Gleixner
2011-05-25 10:49 ` Milton Miller
2011-05-25 10:54 ` Thomas Gleixner
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=radix-insert-can-fail@mdm.bga.com \
--to=miltonm@bga.com \
--cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).