All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vojtech Pavlik <vojtech@suse.cz>
To: torvalds@osdl.org, dtor_core@ameritech.net,
	linux-kernel@vger.kernel.org, vojtech@suse.cz
Subject: [PATCH 6/26] i8042 - clean up initialization code; abort if we
Date: Sun, 11 Sep 2005 00:34:12 +0200	[thread overview]
Message-ID: <11263916524159@midnight.ucw.cz> (raw)
In-Reply-To: <11263916513180@midnight.ucw.cz>

Subject: [PATCH] Input: i8042 - clean up initialization code; abort if we
From: Dmitry Torokhov <dtor_core@ameritech.net>
Date: 1125816087 -0500
       can't create all ports.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

---

 drivers/input/serio/i8042.c |  174 ++++++++++++++++++++++++-------------------
 1 files changed, 98 insertions(+), 76 deletions(-)

0854e52d86080c1043bc8988daef2ebda4775f64
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -338,10 +338,10 @@ static int i8042_open(struct serio *seri
 
 	return 0;
 
-activate_fail:
+ activate_fail:
 	free_irq(port->irq, i8042_request_irq_cookie);
 
-irq_fail:
+ irq_fail:
 	serio_unregister_port_delayed(serio);
 
 	return -1;
@@ -485,7 +485,7 @@ static irqreturn_t i8042_interrupt(int i
 		serio_interrupt(port->serio, data, dfl, regs);
 
 	ret = 1;
-out:
+ out:
 	return IRQ_RETVAL(ret);
 }
 
@@ -552,7 +552,7 @@ static int i8042_enable_mux_ports(void)
  * Enable all muxed ports.
  */
 
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
 		i8042_command(&param, I8042_CMD_MUX_PFX + i);
 		i8042_command(&param, I8042_CMD_AUX_ENABLE);
 	}
@@ -682,7 +682,7 @@ static int __init i8042_port_register(st
 		kfree(port->serio);
 		port->serio = NULL;
 		i8042_ctr |= port->disable;
-		return -1;
+		return -EIO;
 	}
 
 	printk(KERN_INFO "serio: i8042 %s port at %#lx,%#lx irq %d\n",
@@ -977,80 +977,83 @@ static struct device_driver i8042_driver
 	.shutdown	= i8042_shutdown,
 };
 
-static void __init i8042_create_kbd_port(void)
+static int __init i8042_create_kbd_port(void)
 {
 	struct serio *serio;
 	struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO];
 
-	serio = kmalloc(sizeof(struct serio), GFP_KERNEL);
-	if (serio) {
-		memset(serio, 0, sizeof(struct serio));
-		serio->id.type		= i8042_direct ? SERIO_8042 : SERIO_8042_XL;
-		serio->write		= i8042_dumbkbd ? NULL : i8042_kbd_write;
-		serio->open		= i8042_open;
-		serio->close		= i8042_close;
-		serio->start		= i8042_start;
-		serio->stop		= i8042_stop;
-		serio->port_data	= port;
-		serio->dev.parent	= &i8042_platform_device->dev;
-		strlcpy(serio->name, "i8042 Kbd Port", sizeof(serio->name));
-		strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys));
+	serio = kcalloc(1, sizeof(struct serio), GFP_KERNEL);
+	if (!serio)
+		return -ENOMEM;
+
+	serio->id.type		= i8042_direct ? SERIO_8042 : SERIO_8042_XL;
+	serio->write		= i8042_dumbkbd ? NULL : i8042_kbd_write;
+	serio->open		= i8042_open;
+	serio->close		= i8042_close;
+	serio->start		= i8042_start;
+	serio->stop		= i8042_stop;
+	serio->port_data	= port;
+	serio->dev.parent	= &i8042_platform_device->dev;
+	strlcpy(serio->name, "i8042 Kbd Port", sizeof(serio->name));
+	strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys));
 
-		port->serio = serio;
-		i8042_port_register(port);
-	}
+	port->serio = serio;
+
+	return i8042_port_register(port);
 }
 
-static void __init i8042_create_aux_port(void)
+static int __init i8042_create_aux_port(void)
 {
 	struct serio *serio;
 	struct i8042_port *port = &i8042_ports[I8042_AUX_PORT_NO];
 
-	serio = kmalloc(sizeof(struct serio), GFP_KERNEL);
-	if (serio) {
-		memset(serio, 0, sizeof(struct serio));
-		serio->id.type		= SERIO_8042;
-		serio->write		= i8042_aux_write;
-		serio->open		= i8042_open;
-		serio->close		= i8042_close;
-		serio->start		= i8042_start;
-		serio->stop		= i8042_stop;
-		serio->port_data	= port;
-		serio->dev.parent	= &i8042_platform_device->dev;
-		strlcpy(serio->name, "i8042 Aux Port", sizeof(serio->name));
-		strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys));
+	serio = kcalloc(1, sizeof(struct serio), GFP_KERNEL);
+	if (!serio)
+		return -ENOMEM;
+
+	serio->id.type		= SERIO_8042;
+	serio->write		= i8042_aux_write;
+	serio->open		= i8042_open;
+	serio->close		= i8042_close;
+	serio->start		= i8042_start;
+	serio->stop		= i8042_stop;
+	serio->port_data	= port;
+	serio->dev.parent	= &i8042_platform_device->dev;
+	strlcpy(serio->name, "i8042 Aux Port", sizeof(serio->name));
+	strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys));
 
-		port->serio = serio;
-		i8042_port_register(port);
-	}
+	port->serio = serio;
+
+	return i8042_port_register(port);
 }
 
-static void __init i8042_create_mux_port(int index)
+static int __init i8042_create_mux_port(int index)
 {
 	struct serio *serio;
 	struct i8042_port *port = &i8042_ports[I8042_MUX_PORT_NO + index];
 
-	serio = kmalloc(sizeof(struct serio), GFP_KERNEL);
-	if (serio) {
-		memset(serio, 0, sizeof(struct serio));
-		serio->id.type		= SERIO_8042;
-		serio->write		= i8042_aux_write;
-		serio->open		= i8042_open;
-		serio->close		= i8042_close;
-		serio->start		= i8042_start;
-		serio->stop		= i8042_stop;
-		serio->port_data	= port;
-		serio->dev.parent	= &i8042_platform_device->dev;
-		snprintf(serio->name, sizeof(serio->name), "i8042 Aux-%d Port", index);
-		snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, index + 1);
-
-		*port = i8042_ports[I8042_AUX_PORT_NO];
-		port->exists = 0;
-		snprintf(port->name, sizeof(port->name), "AUX%d", index);
-		port->mux = index;
-		port->serio = serio;
-		i8042_port_register(port);
-	}
+	serio = kcalloc(1, sizeof(struct serio), GFP_KERNEL);
+	if (!serio)
+		return -ENOMEM;
+
+	serio->id.type		= SERIO_8042;
+	serio->write		= i8042_aux_write;
+	serio->open		= i8042_open;
+	serio->close		= i8042_close;
+	serio->start		= i8042_start;
+	serio->stop		= i8042_stop;
+	serio->port_data	= port;
+	serio->dev.parent	= &i8042_platform_device->dev;
+	snprintf(serio->name, sizeof(serio->name), "i8042 Aux-%d Port", index);
+	snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, index + 1);
+
+	*port = i8042_ports[I8042_AUX_PORT_NO];
+	port->exists = 0;
+	snprintf(port->name, sizeof(port->name), "AUX%d", index);
+	port->mux = index;
+	port->serio = serio;
+
+	return i8042_port_register(port);
 }
 
 static int __init i8042_init(void)
@@ -1070,36 +1073,55 @@ static int __init i8042_init(void)
 	i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ;
 
 	if (i8042_controller_init()) {
-		i8042_platform_exit();
-		return -ENODEV;
+		err = -ENODEV;
+		goto err_platform_exit;
 	}
 
 	err = driver_register(&i8042_driver);
-	if (err) {
-		i8042_platform_exit();
-		return err;
-	}
+	if (err)
+		goto err_controller_cleanup;
 
 	i8042_platform_device = platform_device_register_simple("i8042", -1, NULL, 0);
 	if (IS_ERR(i8042_platform_device)) {
-		driver_unregister(&i8042_driver);
-		i8042_platform_exit();
-		return PTR_ERR(i8042_platform_device);
+		err = PTR_ERR(i8042_platform_device);
+		goto err_unregister_driver;
 	}
 
 	if (!i8042_noaux && !i8042_check_aux()) {
-		if (!i8042_nomux && !i8042_check_mux())
-			for (i = 0; i < I8042_NUM_MUX_PORTS; i++)
-				i8042_create_mux_port(i);
-		else
-			i8042_create_aux_port();
+		if (!i8042_nomux && !i8042_check_mux()) {
+			for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
+				err = i8042_create_mux_port(i);
+				if (err)
+					goto err_unregister_ports;
+			}
+		} else {
+			err = i8042_create_aux_port();
+			if (err)
+				goto err_unregister_ports;
+		}
 	}
 
-	i8042_create_kbd_port();
+	err = i8042_create_kbd_port();
+	if (err)
+		goto err_unregister_ports;
 
 	mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD);
 
 	return 0;
+
+ err_unregister_ports:
+	for (i = 0; i < I8042_NUM_PORTS; i++)
+		if (i8042_ports[i].serio)
+			serio_unregister_port(i8042_ports[i].serio);
+	platform_device_unregister(i8042_platform_device);
+ err_unregister_driver:
+	driver_unregister(&i8042_driver);
+ err_controller_cleanup:
+	i8042_controller_cleanup();
+ err_platform_exit:
+	i8042_platform_exit();
+
+	return err;
 }
 
 static void __exit i8042_exit(void)


  reply	other threads:[~2005-09-10 22:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-10 22:32 [GIT PULL 0/26] Input update Vojtech Pavlik
2005-09-10 22:34 ` [PATCH 1/26] psmouse - add support for IBM TrackPoint devices Vojtech Pavlik
2005-09-10 22:34   ` [PATCH 2/26] rework psmouse attributes to reduce module size Vojtech Pavlik
2005-09-10 22:34     ` [PATCH 3/26] ALPS - fix wheel decoding Vojtech Pavlik
2005-09-10 22:34       ` [PATCH 4/26] psmouse - add new Logitech wheel mouse model Vojtech Pavlik
2005-09-10 22:34         ` [PATCH 5/26] fix checking whether new keycode fits size-wise Vojtech Pavlik
2005-09-10 22:34           ` Vojtech Pavlik [this message]
2005-09-10 22:34             ` [PATCH 7/26] make i8042_platform_init return 'real' error code Vojtech Pavlik
2005-09-10 22:34               ` [PATCH 8/26] i8042 - fix IRQ printing when either KBD or AUX port Vojtech Pavlik
2005-09-10 22:34                 ` [PATCH 9/26] i8042 - add i8042.nokbd module option to allow supressing Vojtech Pavlik
2005-09-10 22:34                   ` [PATCH 10/26] i8042 - add Lifebook E4010 to MUX blacklist Vojtech Pavlik
2005-09-10 22:34                     ` [PATCH 11/26] recognize and ignore Logitech vendor usages in HID Vojtech Pavlik
2005-09-10 22:34                       ` [PATCH 12/26] add HID simulation mappings Vojtech Pavlik
2005-09-10 22:34                         ` [PATCH 13/26] HID - add more consumer usages Vojtech Pavlik
2005-09-10 22:34                           ` [PATCH 14/26] atkbd - handle keyboards generating scancode 0x7f Vojtech Pavlik
2005-09-10 22:34                             ` [PATCH 15/26] HID - handle multi-transascion reports Vojtech Pavlik
2005-09-10 22:34                               ` [PATCH 16/26] HID - add support for Logitech UltraX Media Remote control Vojtech Pavlik
2005-09-10 22:34                                 ` [PATCH 17/26] iforce - use wait_event_interruptible_timeout Vojtech Pavlik
2005-09-10 22:34                                   ` [PATCH 18/26] sunkbd - extend mapping to handle Type-6 Sun keyboards Vojtech Pavlik
2005-09-10 22:34                                     ` [PATCH 19/26] HID - fix URB success status handling Vojtech Pavlik
2005-09-10 22:34                                       ` [PATCH 20/26] HID - add a quirk for the Apple Powermouse Vojtech Pavlik
2005-09-10 22:34                                         ` [PATCH 21/26] HID - add the Trust Predator TH 400 gamepad to the badpad list Vojtech Pavlik
2005-09-10 22:34                                           ` [PATCH 22/26] HID - add mapping for Powerbook USB keyboard Vojtech Pavlik
2005-09-10 22:34                                             ` [PATCH 23/26] HID - add Wireless Security Lock to HID blacklist Vojtech Pavlik
2005-09-10 22:34                                               ` [PATCH 24/26] HIDDEV - make HIDIOCSREPORT wait IO completion Vojtech Pavlik
2005-09-10 22:34                                                 ` [PATCH 25/26] clean up whitespace and formatting in drivers/char/keyboard.c Vojtech Pavlik
2005-09-10 22:34                                                   ` [PATCH 26/26] i8042 - use kzalloc instead of kcalloc Vojtech Pavlik

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=11263916524159@midnight.ucw.cz \
    --to=vojtech@suse.cz \
    --cc=dtor_core@ameritech.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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.