All of lore.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-sh@vger.kernel.org
Subject: [PATCH] sh: add INTC out of memory error handling
Date: Wed, 10 Mar 2010 09:31:01 +0000	[thread overview]
Message-ID: <20100310093101.5422.38371.sendpatchset@t400s> (raw)

From: Magnus Damm <damm@opensource.se>

Extend the INTC code to warn and return an error code
in the case of memory allocation failure.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 INTC topic branch material

 drivers/sh/intc.c       |   29 ++++++++++++++++++++++++++++-
 include/linux/sh_intc.h |    2 +-
 2 files changed, 29 insertions(+), 2 deletions(-)

--- 0005/drivers/sh/intc.c
+++ work/drivers/sh/intc.c	2010-03-10 16:31:22.000000000 +0900
@@ -789,13 +789,15 @@ static void intc_redirect_irq(unsigned i
 	generic_handle_irq((unsigned int)get_irq_data(irq));
 }
 
-void __init register_intc_controller(struct intc_desc *desc)
+int __init register_intc_controller(struct intc_desc *desc)
 {
 	unsigned int i, k, smp;
 	struct intc_hw_desc *hw = &desc->hw;
 	struct intc_desc_int *d;
 
 	d = kzalloc(sizeof(*d), GFP_NOWAIT);
+	if (!d)
+		goto err0;
 
 	INIT_LIST_HEAD(&d->list);
 	list_add(&d->list, &intc_list);
@@ -806,8 +808,13 @@ void __init register_intc_controller(str
 	d->nr_reg += hw->ack_regs ? hw->nr_ack_regs : 0;
 
 	d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT);
+	if (!d->reg)
+		goto err1;
+
 #ifdef CONFIG_SMP
 	d->smp = kzalloc(d->nr_reg * sizeof(*d->smp), GFP_NOWAIT);
+	if (!d->smp)
+		goto err2;
 #endif
 	k = 0;
 
@@ -822,6 +829,8 @@ void __init register_intc_controller(str
 	if (hw->prio_regs) {
 		d->prio = kzalloc(hw->nr_vectors * sizeof(*d->prio),
 				  GFP_NOWAIT);
+		if (!d->prio)
+			goto err3;
 
 		for (i = 0; i < hw->nr_prio_regs; i++) {
 			smp = IS_SMP(hw->prio_regs[i]);
@@ -833,6 +842,8 @@ void __init register_intc_controller(str
 	if (hw->sense_regs) {
 		d->sense = kzalloc(hw->nr_vectors * sizeof(*d->sense),
 				   GFP_NOWAIT);
+		if (!d->sense)
+			goto err4;
 
 		for (i = 0; i < hw->nr_sense_regs; i++)
 			k += save_reg(d, k, hw->sense_regs[i].reg, 0);
@@ -912,6 +923,22 @@ void __init register_intc_controller(str
 	/* enable bits matching force_enable after registering irqs */
 	if (desc->force_enable)
 		intc_enable_disable_enum(desc, d, desc->force_enable, 1);
+
+	return 0;
+ err4:
+	kfree(d->prio);
+ err3:
+#ifdef CONFIG_SMP
+	kfree(d->smp);
+ err2:
+#endif
+	kfree(d->reg);
+ err1:
+	kfree(d);
+ err0:
+	pr_err("unable to allocate INTC memory\n");
+
+	return -ENOMEM;
 }
 
 static int intc_suspend(struct sys_device *dev, pm_message_t state)
--- 0005/include/linux/sh_intc.h
+++ work/include/linux/sh_intc.h	2010-03-10 16:18:59.000000000 +0900
@@ -92,7 +92,7 @@ struct intc_desc symbol __initdata = {		
 			   prio_regs, sense_regs, ack_regs),		\
 }
 
-void __init register_intc_controller(struct intc_desc *desc);
+int __init register_intc_controller(struct intc_desc *desc);
 int intc_set_priority(unsigned int irq, unsigned int prio);
 
 int reserve_irq_vector(unsigned int irq);

             reply	other threads:[~2010-03-10  9:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-10  9:31 Magnus Damm [this message]
2010-03-23  8:55 ` [PATCH] sh: add INTC out of memory error handling Paul Mundt

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=20100310093101.5422.38371.sendpatchset@t400s \
    --to=magnus.damm@gmail.com \
    --cc=linux-sh@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.