patch-2.4.0-test2 linux/drivers/usb/mousedev.c

Next file: linux/drivers/usb/ov511.c
Previous file: linux/drivers/usb/microtek.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test1/linux/drivers/usb/mousedev.c linux/drivers/usb/mousedev.c
@@ -1,7 +1,7 @@
 /*
- *  mousedev.c  Version 0.1
+ * $Id: mousedev.c,v 1.10 2000/06/23 09:23:00 vojtech Exp $
  *
- *  Copyright (c) 1999 Vojtech Pavlik
+ *  Copyright (c) 1999-2000 Vojtech Pavlik
  *
  *  Input driver to PS/2 or ImPS/2 device driver module.
  *
@@ -47,7 +47,7 @@
 #endif
 
 struct mousedev {
-	int used;
+	int exist;
 	int open;
 	int minor;
 	wait_queue_head_t wait;
@@ -138,8 +138,7 @@
 					
 			list->ready = 1;
 
-			if (list->fasync)
-				kill_fasync(list->fasync, SIGIO, POLL_IN);
+			kill_fasync(&list->fasync, SIGIO, POLL_IN);
 
 			list = list->next;
 		}
@@ -173,25 +172,32 @@
 			struct input_handle *handle = mousedev_handler.handle;
 			while (handle) {
 				struct mousedev *mousedev = handle->private;
-				if (!mousedev->open)
-					input_close_device(handle);
+				if (!mousedev->open) {
+					if (mousedev->exist) {
+						input_close_device(&mousedev->handle);
+					} else {
+						input_unregister_minor(mousedev->devfs);
+						mousedev_table[mousedev->minor] = NULL;
+						kfree(mousedev);
+					}
+				}
 				handle = handle->hnext;
 			}
 		} else {
-			if (!mousedev_mix.open)	
-				input_close_device(&list->mousedev->handle);
+			if (!mousedev_mix.open) {
+				if (list->mousedev->exist) {
+					input_close_device(&list->mousedev->handle);
+				} else {
+					input_unregister_minor(list->mousedev->devfs);
+					mousedev_table[list->mousedev->minor] = NULL;
+					kfree(list->mousedev);
+				}
+			}
 		}
 	}
 	
-	if (!--list->mousedev->used) {
-		input_unregister_minor(list->mousedev->devfs);
-		mousedev_table[list->mousedev->minor] = NULL;
-		kfree(list->mousedev);
-	}
-
 	kfree(list);
 
-	MOD_DEC_USE_COUNT;
 	return 0;
 }
 
@@ -203,12 +209,8 @@
 	if (i > MOUSEDEV_MINORS || !mousedev_table[i])
 		return -ENODEV;
 
-	MOD_INC_USE_COUNT;
-
-	if (!(list = kmalloc(sizeof(struct mousedev_list), GFP_KERNEL))) {
-		MOD_DEC_USE_COUNT;
+	if (!(list = kmalloc(sizeof(struct mousedev_list), GFP_KERNEL)))
 		return -ENOMEM;
-	}
 	memset(list, 0, sizeof(struct mousedev_list));
 
 	list->mousedev = mousedev_table[i];
@@ -216,20 +218,20 @@
 	mousedev_table[i]->list = list;
 	file->private_data = list;
 
-	list->mousedev->used++;
-
 	if (!list->mousedev->open++) {
 		if (list->mousedev->minor == MOUSEDEV_MIX) {
 			struct input_handle *handle = mousedev_handler.handle;
 			while (handle) {
 				struct mousedev *mousedev = handle->private;
 				if (!mousedev->open)
-					input_open_device(handle);
+					if (mousedev->exist)	
+						input_open_device(handle);
 				handle = handle->hnext;
 			}
 		} else {
-			if (!mousedev_mix.open)	
-				input_open_device(&list->mousedev->handle);
+			if (!mousedev_mix.open)
+				if (list->mousedev->exist)	
+					input_open_device(&list->mousedev->handle);
 		}
 	}
 
@@ -311,8 +313,7 @@
 		list->buffer = list->bufsiz;
 	}
 
-	if (list->fasync)
-		kill_fasync(list->fasync, SIGIO, POLL_IN);
+	kill_fasync(&list->fasync, SIGIO, POLL_IN);
 
 	wake_up_interruptible(&list->mousedev->wait);
 		
@@ -376,6 +377,7 @@
 }
 
 struct file_operations mousedev_fops = {
+	owner:		THIS_MODULE,
 	read:		mousedev_read,
 	write:		mousedev_write,
 	poll:		mousedev_poll,
@@ -408,7 +410,7 @@
 	memset(mousedev, 0, sizeof(struct mousedev));
 	init_waitqueue_head(&mousedev->wait);
 
-	mousedev->used = 1;
+	mousedev->exist = 1;
 	mousedev->minor = minor;
 	mousedev_table[minor] = mousedev;
 
@@ -421,7 +423,7 @@
 	if (mousedev_mix.open)
 		input_open_device(&mousedev->handle);
 
-	printk("mouse%d: PS/2 mouse device for input%d\n", minor, dev->number);
+	printk(KERN_INFO "mouse%d: PS/2 mouse device for input%d\n", minor, dev->number);
 
 	return &mousedev->handle;
 }
@@ -430,10 +432,13 @@
 {
 	struct mousedev *mousedev = handle->private;
 
-	if (mousedev->open || mousedev_mix.open)
-		input_close_device(handle);
+	mousedev->exist = 0;
 
-	if (!--mousedev->used) {
+	if (mousedev->open) {
+		input_close_device(handle);
+	} else {
+		if (mousedev_mix.open)
+			input_close_device(handle);
 		input_unregister_minor(mousedev->devfs);
 		mousedev_table[mousedev->minor] = NULL;
 		kfree(mousedev);
@@ -455,11 +460,11 @@
 	memset(&mousedev_mix, 0, sizeof(struct mousedev));
 	init_waitqueue_head(&mousedev_mix.wait);
 	mousedev_table[MOUSEDEV_MIX] = &mousedev_mix;
-	mousedev_mix.used = 1;
+	mousedev_mix.exist = 1;
 	mousedev_mix.minor = MOUSEDEV_MIX;
 	mousedev_mix.devfs = input_register_minor("mice", MOUSEDEV_MIX, MOUSEDEV_MINOR_BASE);
 
-	printk("mice: PS/2 mouse device common for all mice\n");
+	printk(KERN_INFO "mice: PS/2 mouse device common for all mice\n");
 
 	return 0;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)