All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vernon Mauery <vernux@us.ibm.com>
To: kernel list <linux-kernel@vger.kernel.org>,
	Vojtech Pavlik <vojtech@suse.cz>, Max Asbock <amax@us.ibm.com>
Subject: dynamic input_dev allocation for ibmasm driver
Date: Fri, 06 Jan 2006 15:59:31 -0800	[thread overview]
Message-ID: <43BF0463.7010700@us.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

This patch updates the ibmasm driver to use the dynamic allocation of input_dev
structs to work with the sysfs subsystem.  I have tested it on my machine and it
seems to work fine.

Signed-off-by: Vernon Mauery <vernux@us.ibm.com>

 ibmasm.h |    6 ++---
 remote.c |   72 ++++++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 42 insertions(+), 36 deletions(-)


[-- Attachment #2: ibmasm_dynamic_allocate_input_device.patch --]
[-- Type: text/x-patch, Size: 4649 bytes --]

diff -Nuarp -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/misc/ibmasm/ibmasm.h linux-2.6.15-fixed/drivers/misc/ibmasm/ibmasm.h
--- linux-2.6.15/drivers/misc/ibmasm/ibmasm.h	2006-01-02 19:21:10.000000000 -0800
+++ linux-2.6.15-fixed/drivers/misc/ibmasm/ibmasm.h	2006-01-05 03:43:03.000000000 -0800
@@ -141,8 +141,8 @@ struct reverse_heartbeat {
 };
 
 struct ibmasm_remote {
-	struct input_dev keybd_dev;
-	struct input_dev mouse_dev;
+	struct input_dev * keybd_dev;
+	struct input_dev * mouse_dev;
 };
 
 struct service_processor {
@@ -157,7 +157,7 @@ struct service_processor {
 	char			dirname[IBMASM_NAME_SIZE];
 	char			devname[IBMASM_NAME_SIZE];
 	unsigned int		number;
-	struct ibmasm_remote	*remote;
+	struct ibmasm_remote	remote;
 	int			serial_line;
 	struct device		*dev;
 };
diff -Nuarp -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/misc/ibmasm/remote.c linux-2.6.15-fixed/drivers/misc/ibmasm/remote.c
--- linux-2.6.15/drivers/misc/ibmasm/remote.c	2006-01-02 19:21:10.000000000 -0800
+++ linux-2.6.15-fixed/drivers/misc/ibmasm/remote.c	2006-01-06 07:38:57.000000000 -0800
@@ -203,9 +203,9 @@ void ibmasm_handle_mouse_interrupt(struc
 
 		print_input(&input);
 		if (input.type == INPUT_TYPE_MOUSE) {
-			send_mouse_event(&sp->remote->mouse_dev, regs, &input);
+			send_mouse_event(sp->remote.mouse_dev, regs, &input);
 		} else if (input.type == INPUT_TYPE_KEYBOARD) {
-			send_keyboard_event(&sp->remote->keybd_dev, regs, &input);
+			send_keyboard_event(sp->remote.keybd_dev, regs, &input);
 		} else
 			break;
 
@@ -217,56 +217,62 @@ void ibmasm_handle_mouse_interrupt(struc
 int ibmasm_init_remote_input_dev(struct service_processor *sp)
 {
 	/* set up the mouse input device */
-	struct ibmasm_remote *remote;
+	struct input_dev *mouse_dev, *keybd_dev;
 	struct pci_dev *pdev = to_pci_dev(sp->dev);
 	int i;
+	int ret = 0;
 
-	sp->remote = remote = kmalloc(sizeof(*remote), GFP_KERNEL);
-	if (!remote)
-		return -ENOMEM;
-
-	memset(remote, 0, sizeof(*remote));
-
-	remote->mouse_dev.private = remote;
-	init_input_dev(&remote->mouse_dev);
-	remote->mouse_dev.id.vendor = pdev->vendor;
-	remote->mouse_dev.id.product = pdev->device;
-	remote->mouse_dev.evbit[0]  = BIT(EV_KEY) | BIT(EV_ABS);
-	remote->mouse_dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) |
+	mouse_dev = input_allocate_device();
+	keybd_dev = input_allocate_device();
+	if (!mouse_dev || !keybd_dev) {
+		ret = -ENOMEM;
+		goto error_alloc;
+	}
+	mouse_dev->id.vendor = pdev->vendor;
+	mouse_dev->id.product = pdev->device;
+	mouse_dev->evbit[0]  = BIT(EV_KEY) | BIT(EV_ABS);
+	mouse_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) |
 		BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
-	set_bit(BTN_TOUCH, remote->mouse_dev.keybit);
-	remote->mouse_dev.name = remote_mouse_name;
-	input_set_abs_params(&remote->mouse_dev, ABS_X, 0, xmax, 0, 0);
-	input_set_abs_params(&remote->mouse_dev, ABS_Y, 0, ymax, 0, 0);
-
-	remote->keybd_dev.private = remote;
-	init_input_dev(&remote->keybd_dev);
-	remote->keybd_dev.id.vendor = pdev->vendor;
-	remote->keybd_dev.id.product = pdev->device;
-	remote->keybd_dev.evbit[0]  = BIT(EV_KEY);
-	remote->keybd_dev.name = remote_keybd_name;
+	set_bit(BTN_TOUCH, mouse_dev->keybit);
+	mouse_dev->name = remote_mouse_name;
+	input_set_abs_params(mouse_dev, ABS_X, 0, xmax, 0, 0);
+	input_set_abs_params(mouse_dev, ABS_Y, 0, ymax, 0, 0);
+
+	keybd_dev->id.vendor = pdev->vendor;
+	keybd_dev->id.product = pdev->device;
+	keybd_dev->evbit[0]  = BIT(EV_KEY);
+	keybd_dev->name = remote_keybd_name;
 
 	for (i=0; i<XLATE_SIZE; i++) {
 		if (xlate_high[i])
-			set_bit(xlate_high[i], remote->keybd_dev.keybit);
+			set_bit(xlate_high[i], keybd_dev->keybit);
 		if (xlate[i])
-			set_bit(xlate[i], remote->keybd_dev.keybit);
+			set_bit(xlate[i], keybd_dev->keybit);
 	}
 
-	input_register_device(&remote->mouse_dev);
-	input_register_device(&remote->keybd_dev);
+	if ((ret = input_register_device(mouse_dev)))
+		goto error_alloc;
+	if ((ret = input_register_device(keybd_dev)))
+		goto error_alloc;
+
+	sp->remote.mouse_dev = mouse_dev;
+	sp->remote.keybd_dev = keybd_dev;
 	enable_mouse_interrupts(sp);
 
 	printk(KERN_INFO "ibmasm remote responding to events on RSA card %d\n", sp->number);
 
 	return 0;
+
+error_alloc:
+	input_free_device(mouse_dev);
+	input_free_device(keybd_dev);
+	return ret;
 }
 
 void ibmasm_free_remote_input_dev(struct service_processor *sp)
 {
 	disable_mouse_interrupts(sp);
-	input_unregister_device(&sp->remote->keybd_dev);
-	input_unregister_device(&sp->remote->mouse_dev);
-	kfree(sp->remote);
+	input_unregister_device(sp->remote.mouse_dev);
+	input_unregister_device(sp->remote.keybd_dev);
 }
 

             reply	other threads:[~2006-01-06 23:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-06 23:59 Vernon Mauery [this message]
2006-01-07  5:01 ` dynamic input_dev allocation for ibmasm driver Dmitry Torokhov
2006-01-07  9:58   ` 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=43BF0463.7010700@us.ibm.com \
    --to=vernux@us.ibm.com \
    --cc=amax@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    /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.