diff options
-rw-r--r-- | drivers/char/scx200_gpio.c | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c index e7665c1ad134..dd1f997944e6 100644 --- a/drivers/char/scx200_gpio.c +++ b/drivers/char/scx200_gpio.c | |||
@@ -63,7 +63,6 @@ static int scx200_gpio_release(struct inode *inode, struct file *file) | |||
63 | return 0; | 63 | return 0; |
64 | } | 64 | } |
65 | 65 | ||
66 | |||
67 | static const struct file_operations scx200_gpio_fops = { | 66 | static const struct file_operations scx200_gpio_fops = { |
68 | .owner = THIS_MODULE, | 67 | .owner = THIS_MODULE, |
69 | .write = nsc_gpio_write, | 68 | .write = nsc_gpio_write, |
@@ -72,11 +71,11 @@ static const struct file_operations scx200_gpio_fops = { | |||
72 | .release = scx200_gpio_release, | 71 | .release = scx200_gpio_release, |
73 | }; | 72 | }; |
74 | 73 | ||
75 | struct cdev *scx200_devices; | 74 | struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */ |
76 | 75 | ||
77 | static int __init scx200_gpio_init(void) | 76 | static int __init scx200_gpio_init(void) |
78 | { | 77 | { |
79 | int rc, i; | 78 | int rc; |
80 | dev_t devid; | 79 | dev_t devid; |
81 | 80 | ||
82 | if (!scx200_gpio_present()) { | 81 | if (!scx200_gpio_present()) { |
@@ -107,25 +106,12 @@ static int __init scx200_gpio_init(void) | |||
107 | dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc); | 106 | dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc); |
108 | goto undo_platform_device_add; | 107 | goto undo_platform_device_add; |
109 | } | 108 | } |
110 | scx200_devices = kzalloc(MAX_PINS * sizeof(struct cdev), GFP_KERNEL); | 109 | |
111 | if (!scx200_devices) { | 110 | cdev_init(&scx200_gpio_cdev, &scx200_gpio_fops); |
112 | rc = -ENOMEM; | 111 | cdev_add(&scx200_gpio_cdev, devid, MAX_PINS); |
113 | goto undo_chrdev_region; | ||
114 | } | ||
115 | for (i = 0; i < MAX_PINS; i++) { | ||
116 | struct cdev *cdev = &scx200_devices[i]; | ||
117 | cdev_init(cdev, &scx200_gpio_fops); | ||
118 | cdev->owner = THIS_MODULE; | ||
119 | rc = cdev_add(cdev, MKDEV(major, i), 1); | ||
120 | /* tolerate 'minor' errors */ | ||
121 | if (rc) | ||
122 | dev_err(&pdev->dev, "Error %d on minor %d", rc, i); | ||
123 | } | ||
124 | 112 | ||
125 | return 0; /* succeed */ | 113 | return 0; /* succeed */ |
126 | 114 | ||
127 | undo_chrdev_region: | ||
128 | unregister_chrdev_region(devid, MAX_PINS); | ||
129 | undo_platform_device_add: | 115 | undo_platform_device_add: |
130 | platform_device_del(pdev); | 116 | platform_device_del(pdev); |
131 | undo_malloc: | 117 | undo_malloc: |
@@ -136,7 +122,9 @@ undo_malloc: | |||
136 | 122 | ||
137 | static void __exit scx200_gpio_cleanup(void) | 123 | static void __exit scx200_gpio_cleanup(void) |
138 | { | 124 | { |
139 | kfree(scx200_devices); | 125 | cdev_del(&scx200_gpio_cdev); |
126 | /* cdev_put(&scx200_gpio_cdev); */ | ||
127 | |||
140 | unregister_chrdev_region(MKDEV(major, 0), MAX_PINS); | 128 | unregister_chrdev_region(MKDEV(major, 0), MAX_PINS); |
141 | platform_device_unregister(pdev); | 129 | platform_device_unregister(pdev); |
142 | } | 130 | } |