hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/char/lp.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic parallel printer driver
34 *
....@@ -46,8 +47,8 @@
4647 * lp=auto (assign lp devices to all ports that
4748 * have printers attached, as determined
4849 * by the IEEE-1284 autoprobe)
49
- *
50
- * lp=reset (reset the printer during
50
+ *
51
+ * lp=reset (reset the printer during
5152 * initialisation)
5253 *
5354 * lp=off (disable the printer driver entirely)
....@@ -141,6 +142,7 @@
141142
142143 static DEFINE_MUTEX(lp_mutex);
143144 static struct lp_struct lp_table[LP_NO];
145
+static int port_num[LP_NO];
144146
145147 static unsigned int lp_count = 0;
146148 static struct class *lp_class;
....@@ -166,7 +168,7 @@
166168 static void lp_claim_parport_or_block(struct lp_struct *this_lp)
167169 {
168170 if (!test_and_set_bit(LP_PARPORT_CLAIMED, &this_lp->bits)) {
169
- parport_claim_or_block (this_lp->dev);
171
+ parport_claim_or_block(this_lp->dev);
170172 }
171173 }
172174
....@@ -174,7 +176,7 @@
174176 static void lp_release_parport(struct lp_struct *this_lp)
175177 {
176178 if (test_and_clear_bit(LP_PARPORT_CLAIMED, &this_lp->bits)) {
177
- parport_release (this_lp->dev);
179
+ parport_release(this_lp->dev);
178180 }
179181 }
180182
....@@ -184,37 +186,37 @@
184186 {
185187 struct lp_struct *this_lp = (struct lp_struct *)handle;
186188 set_bit(LP_PREEMPT_REQUEST, &this_lp->bits);
187
- return (1);
189
+ return 1;
188190 }
189191
190192
191
-/*
193
+/*
192194 * Try to negotiate to a new mode; if unsuccessful negotiate to
193195 * compatibility mode. Return the mode we ended up in.
194196 */
195
-static int lp_negotiate(struct parport * port, int mode)
197
+static int lp_negotiate(struct parport *port, int mode)
196198 {
197
- if (parport_negotiate (port, mode) != 0) {
199
+ if (parport_negotiate(port, mode) != 0) {
198200 mode = IEEE1284_MODE_COMPAT;
199
- parport_negotiate (port, mode);
201
+ parport_negotiate(port, mode);
200202 }
201203
202
- return (mode);
204
+ return mode;
203205 }
204206
205207 static int lp_reset(int minor)
206208 {
207209 int retval;
208
- lp_claim_parport_or_block (&lp_table[minor]);
210
+ lp_claim_parport_or_block(&lp_table[minor]);
209211 w_ctr(minor, LP_PSELECP);
210
- udelay (LP_DELAY);
212
+ udelay(LP_DELAY);
211213 w_ctr(minor, LP_PSELECP | LP_PINITP);
212214 retval = r_str(minor);
213
- lp_release_parport (&lp_table[minor]);
215
+ lp_release_parport(&lp_table[minor]);
214216 return retval;
215217 }
216218
217
-static void lp_error (int minor)
219
+static void lp_error(int minor)
218220 {
219221 DEFINE_WAIT(wait);
220222 int polling;
....@@ -223,12 +225,15 @@
223225 return;
224226
225227 polling = lp_table[minor].dev->port->irq == PARPORT_IRQ_NONE;
226
- if (polling) lp_release_parport (&lp_table[minor]);
228
+ if (polling)
229
+ lp_release_parport(&lp_table[minor]);
227230 prepare_to_wait(&lp_table[minor].waitq, &wait, TASK_INTERRUPTIBLE);
228231 schedule_timeout(LP_TIMEOUT_POLLED);
229232 finish_wait(&lp_table[minor].waitq, &wait);
230
- if (polling) lp_claim_parport_or_block (&lp_table[minor]);
231
- else parport_yield_blocking (lp_table[minor].dev);
233
+ if (polling)
234
+ lp_claim_parport_or_block(&lp_table[minor]);
235
+ else
236
+ parport_yield_blocking(lp_table[minor].dev);
232237 }
233238
234239 static int lp_check_status(int minor)
....@@ -259,7 +264,7 @@
259264 error = -EIO;
260265 } else {
261266 last = 0; /* Come here if LP_CAREFUL is set and no
262
- errors are reported. */
267
+ errors are reported. */
263268 }
264269
265270 lp_table[minor].last_error = last;
....@@ -276,14 +281,14 @@
276281
277282 /* If we're not in compatibility mode, we're ready now! */
278283 if (lp_table[minor].current_mode != IEEE1284_MODE_COMPAT) {
279
- return (0);
284
+ return 0;
280285 }
281286
282287 do {
283
- error = lp_check_status (minor);
288
+ error = lp_check_status(minor);
284289 if (error && (nonblock || (LP_F(minor) & LP_ABORT)))
285290 break;
286
- if (signal_pending (current)) {
291
+ if (signal_pending(current)) {
287292 error = -EINTR;
288293 break;
289294 }
....@@ -291,8 +296,8 @@
291296 return error;
292297 }
293298
294
-static ssize_t lp_write(struct file * file, const char __user * buf,
295
- size_t count, loff_t *ppos)
299
+static ssize_t lp_write(struct file *file, const char __user *buf,
300
+ size_t count, loff_t *ppos)
296301 {
297302 unsigned int minor = iminor(file_inode(file));
298303 struct parport *port = lp_table[minor].dev->port;
....@@ -317,26 +322,26 @@
317322 if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
318323 return -EINTR;
319324
320
- if (copy_from_user (kbuf, buf, copy_size)) {
325
+ if (copy_from_user(kbuf, buf, copy_size)) {
321326 retv = -EFAULT;
322327 goto out_unlock;
323328 }
324329
325
- /* Claim Parport or sleep until it becomes available
326
- */
327
- lp_claim_parport_or_block (&lp_table[minor]);
330
+ /* Claim Parport or sleep until it becomes available
331
+ */
332
+ lp_claim_parport_or_block(&lp_table[minor]);
328333 /* Go to the proper mode. */
329
- lp_table[minor].current_mode = lp_negotiate (port,
330
- lp_table[minor].best_mode);
334
+ lp_table[minor].current_mode = lp_negotiate(port,
335
+ lp_table[minor].best_mode);
331336
332
- parport_set_timeout (lp_table[minor].dev,
333
- (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
334
- : lp_table[minor].timeout));
337
+ parport_set_timeout(lp_table[minor].dev,
338
+ (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
339
+ : lp_table[minor].timeout));
335340
336
- if ((retv = lp_wait_ready (minor, nonblock)) == 0)
341
+ if ((retv = lp_wait_ready(minor, nonblock)) == 0)
337342 do {
338343 /* Write the data. */
339
- written = parport_write (port, kbuf, copy_size);
344
+ written = parport_write(port, kbuf, copy_size);
340345 if (written > 0) {
341346 copy_size -= written;
342347 count -= written;
....@@ -344,7 +349,7 @@
344349 retv += written;
345350 }
346351
347
- if (signal_pending (current)) {
352
+ if (signal_pending(current)) {
348353 if (retv == 0)
349354 retv = -EINTR;
350355
....@@ -355,11 +360,11 @@
355360 /* incomplete write -> check error ! */
356361 int error;
357362
358
- parport_negotiate (lp_table[minor].dev->port,
359
- IEEE1284_MODE_COMPAT);
363
+ parport_negotiate(lp_table[minor].dev->port,
364
+ IEEE1284_MODE_COMPAT);
360365 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
361366
362
- error = lp_wait_ready (minor, nonblock);
367
+ error = lp_wait_ready(minor, nonblock);
363368
364369 if (error) {
365370 if (retv == 0)
....@@ -371,13 +376,13 @@
371376 break;
372377 }
373378
374
- parport_yield_blocking (lp_table[minor].dev);
375
- lp_table[minor].current_mode
376
- = lp_negotiate (port,
377
- lp_table[minor].best_mode);
379
+ parport_yield_blocking(lp_table[minor].dev);
380
+ lp_table[minor].current_mode
381
+ = lp_negotiate(port,
382
+ lp_table[minor].best_mode);
378383
379384 } else if (need_resched())
380
- schedule ();
385
+ schedule();
381386
382387 if (count) {
383388 copy_size = count;
....@@ -389,27 +394,27 @@
389394 retv = -EFAULT;
390395 break;
391396 }
392
- }
397
+ }
393398 } while (count > 0);
394399
395
- if (test_and_clear_bit(LP_PREEMPT_REQUEST,
400
+ if (test_and_clear_bit(LP_PREEMPT_REQUEST,
396401 &lp_table[minor].bits)) {
397402 printk(KERN_INFO "lp%d releasing parport\n", minor);
398
- parport_negotiate (lp_table[minor].dev->port,
399
- IEEE1284_MODE_COMPAT);
403
+ parport_negotiate(lp_table[minor].dev->port,
404
+ IEEE1284_MODE_COMPAT);
400405 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
401
- lp_release_parport (&lp_table[minor]);
406
+ lp_release_parport(&lp_table[minor]);
402407 }
403408 out_unlock:
404409 mutex_unlock(&lp_table[minor].port_mutex);
405410
406
- return retv;
411
+ return retv;
407412 }
408413
409414 #ifdef CONFIG_PARPORT_1284
410415
411416 /* Status readback conforming to ieee1284 */
412
-static ssize_t lp_read(struct file * file, char __user * buf,
417
+static ssize_t lp_read(struct file *file, char __user *buf,
413418 size_t count, loff_t *ppos)
414419 {
415420 DEFINE_WAIT(wait);
....@@ -426,21 +431,21 @@
426431 if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
427432 return -EINTR;
428433
429
- lp_claim_parport_or_block (&lp_table[minor]);
434
+ lp_claim_parport_or_block(&lp_table[minor]);
430435
431
- parport_set_timeout (lp_table[minor].dev,
432
- (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
433
- : lp_table[minor].timeout));
436
+ parport_set_timeout(lp_table[minor].dev,
437
+ (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
438
+ : lp_table[minor].timeout));
434439
435
- parport_negotiate (lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
436
- if (parport_negotiate (lp_table[minor].dev->port,
437
- IEEE1284_MODE_NIBBLE)) {
440
+ parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
441
+ if (parport_negotiate(lp_table[minor].dev->port,
442
+ IEEE1284_MODE_NIBBLE)) {
438443 retval = -EIO;
439444 goto out;
440445 }
441446
442447 while (retval == 0) {
443
- retval = parport_read (port, kbuf, count);
448
+ retval = parport_read(port, kbuf, count);
444449
445450 if (retval > 0)
446451 break;
....@@ -453,11 +458,11 @@
453458 /* Wait for data. */
454459
455460 if (lp_table[minor].dev->port->irq == PARPORT_IRQ_NONE) {
456
- parport_negotiate (lp_table[minor].dev->port,
457
- IEEE1284_MODE_COMPAT);
458
- lp_error (minor);
459
- if (parport_negotiate (lp_table[minor].dev->port,
460
- IEEE1284_MODE_NIBBLE)) {
461
+ parport_negotiate(lp_table[minor].dev->port,
462
+ IEEE1284_MODE_COMPAT);
463
+ lp_error(minor);
464
+ if (parport_negotiate(lp_table[minor].dev->port,
465
+ IEEE1284_MODE_NIBBLE)) {
461466 retval = -EIO;
462467 goto out;
463468 }
....@@ -467,18 +472,18 @@
467472 finish_wait(&lp_table[minor].waitq, &wait);
468473 }
469474
470
- if (signal_pending (current)) {
475
+ if (signal_pending(current)) {
471476 retval = -ERESTARTSYS;
472477 break;
473478 }
474479
475
- cond_resched ();
480
+ cond_resched();
476481 }
477
- parport_negotiate (lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
482
+ parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
478483 out:
479
- lp_release_parport (&lp_table[minor]);
484
+ lp_release_parport(&lp_table[minor]);
480485
481
- if (retval > 0 && copy_to_user (buf, kbuf, retval))
486
+ if (retval > 0 && copy_to_user(buf, kbuf, retval))
482487 retval = -EFAULT;
483488
484489 mutex_unlock(&lp_table[minor].port_mutex);
....@@ -488,7 +493,7 @@
488493
489494 #endif /* IEEE 1284 support */
490495
491
-static int lp_open(struct inode * inode, struct file * file)
496
+static int lp_open(struct inode *inode, struct file *file)
492497 {
493498 unsigned int minor = iminor(inode);
494499 int ret = 0;
....@@ -513,9 +518,9 @@
513518 should most likely only ever be used by the tunelp application. */
514519 if ((LP_F(minor) & LP_ABORTOPEN) && !(file->f_flags & O_NONBLOCK)) {
515520 int status;
516
- lp_claim_parport_or_block (&lp_table[minor]);
521
+ lp_claim_parport_or_block(&lp_table[minor]);
517522 status = r_str(minor);
518
- lp_release_parport (&lp_table[minor]);
523
+ lp_release_parport(&lp_table[minor]);
519524 if (status & LP_POUTPA) {
520525 printk(KERN_INFO "lp%d out of paper\n", minor);
521526 LP_F(minor) &= ~LP_BUSY;
....@@ -540,32 +545,32 @@
540545 goto out;
541546 }
542547 /* Determine if the peripheral supports ECP mode */
543
- lp_claim_parport_or_block (&lp_table[minor]);
548
+ lp_claim_parport_or_block(&lp_table[minor]);
544549 if ( (lp_table[minor].dev->port->modes & PARPORT_MODE_ECP) &&
545
- !parport_negotiate (lp_table[minor].dev->port,
546
- IEEE1284_MODE_ECP)) {
547
- printk (KERN_INFO "lp%d: ECP mode\n", minor);
550
+ !parport_negotiate(lp_table[minor].dev->port,
551
+ IEEE1284_MODE_ECP)) {
552
+ printk(KERN_INFO "lp%d: ECP mode\n", minor);
548553 lp_table[minor].best_mode = IEEE1284_MODE_ECP;
549554 } else {
550555 lp_table[minor].best_mode = IEEE1284_MODE_COMPAT;
551556 }
552557 /* Leave peripheral in compatibility mode */
553
- parport_negotiate (lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
554
- lp_release_parport (&lp_table[minor]);
558
+ parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
559
+ lp_release_parport(&lp_table[minor]);
555560 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
556561 out:
557562 mutex_unlock(&lp_mutex);
558563 return ret;
559564 }
560565
561
-static int lp_release(struct inode * inode, struct file * file)
566
+static int lp_release(struct inode *inode, struct file *file)
562567 {
563568 unsigned int minor = iminor(inode);
564569
565
- lp_claim_parport_or_block (&lp_table[minor]);
566
- parport_negotiate (lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
570
+ lp_claim_parport_or_block(&lp_table[minor]);
571
+ parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
567572 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
568
- lp_release_parport (&lp_table[minor]);
573
+ lp_release_parport(&lp_table[minor]);
569574 kfree(lp_table[minor].lp_buffer);
570575 lp_table[minor].lp_buffer = NULL;
571576 LP_F(minor) &= ~LP_BUSY;
....@@ -615,7 +620,7 @@
615620 case LPWAIT:
616621 LP_WAIT(minor) = arg;
617622 break;
618
- case LPSETIRQ:
623
+ case LPSETIRQ:
619624 return -EINVAL;
620625 break;
621626 case LPGETIRQ:
....@@ -626,9 +631,9 @@
626631 case LPGETSTATUS:
627632 if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
628633 return -EINTR;
629
- lp_claim_parport_or_block (&lp_table[minor]);
634
+ lp_claim_parport_or_block(&lp_table[minor]);
630635 status = r_str(minor);
631
- lp_release_parport (&lp_table[minor]);
636
+ lp_release_parport(&lp_table[minor]);
632637 mutex_unlock(&lp_table[minor].port_mutex);
633638
634639 if (copy_to_user(argp, &status, sizeof(int)))
....@@ -647,8 +652,8 @@
647652 sizeof(struct lp_stats));
648653 break;
649654 #endif
650
- case LPGETFLAGS:
651
- status = LP_F(minor);
655
+ case LPGETFLAGS:
656
+ status = LP_F(minor);
652657 if (copy_to_user(argp, &status, sizeof(int)))
653658 return -EFAULT;
654659 break;
....@@ -729,7 +734,7 @@
729734 ret = lp_set_timeout32(minor, (void __user *)arg);
730735 break;
731736 }
732
- /* fallthrough for 64-bit */
737
+ fallthrough; /* for 64-bit */
733738 case LPSETTIMEOUT_NEW:
734739 ret = lp_set_timeout64(minor, (void __user *)arg);
735740 break;
....@@ -757,7 +762,7 @@
757762 ret = lp_set_timeout32(minor, (void __user *)arg);
758763 break;
759764 }
760
- /* fallthrough for x32 mode */
765
+ fallthrough; /* for x32 mode */
761766 case LPSETTIMEOUT_NEW:
762767 ret = lp_set_timeout64(minor, (void __user *)arg);
763768 break;
....@@ -805,31 +810,31 @@
805810
806811 /* The console must be locked when we get here. */
807812
808
-static void lp_console_write (struct console *co, const char *s,
809
- unsigned count)
813
+static void lp_console_write(struct console *co, const char *s,
814
+ unsigned count)
810815 {
811816 struct pardevice *dev = lp_table[CONSOLE_LP].dev;
812817 struct parport *port = dev->port;
813818 ssize_t written;
814819
815
- if (parport_claim (dev))
820
+ if (parport_claim(dev))
816821 /* Nothing we can do. */
817822 return;
818823
819
- parport_set_timeout (dev, 0);
824
+ parport_set_timeout(dev, 0);
820825
821826 /* Go to compatibility mode. */
822
- parport_negotiate (port, IEEE1284_MODE_COMPAT);
827
+ parport_negotiate(port, IEEE1284_MODE_COMPAT);
823828
824829 do {
825830 /* Write the data, converting LF->CRLF as we go. */
826831 ssize_t canwrite = count;
827
- char *lf = memchr (s, '\n', count);
832
+ char *lf = memchr(s, '\n', count);
828833 if (lf)
829834 canwrite = lf - s;
830835
831836 if (canwrite > 0) {
832
- written = parport_write (port, s, canwrite);
837
+ written = parport_write(port, s, canwrite);
833838
834839 if (written <= 0)
835840 continue;
....@@ -847,14 +852,16 @@
847852 s++;
848853 count--;
849854 do {
850
- written = parport_write (port, crlf, i);
851
- if (written > 0)
852
- i -= written, crlf += written;
855
+ written = parport_write(port, crlf, i);
856
+ if (written > 0) {
857
+ i -= written;
858
+ crlf += written;
859
+ }
853860 } while (i > 0 && (CONSOLE_LP_STRICT || written > 0));
854861 }
855862 } while (count > 0 && (CONSOLE_LP_STRICT || written > 0));
856863
857
- parport_release (dev);
864
+ parport_release(dev);
858865 }
859866
860867 static struct console lpcons = {
....@@ -875,7 +882,7 @@
875882 module_param(reset, bool, 0);
876883
877884 #ifndef MODULE
878
-static int __init lp_setup (char *str)
885
+static int __init lp_setup(char *str)
879886 {
880887 static int parport_ptr;
881888 int x;
....@@ -912,9 +919,13 @@
912919
913920 static int lp_register(int nr, struct parport *port)
914921 {
915
- lp_table[nr].dev = parport_register_device(port, "lp",
916
- lp_preempt, NULL, NULL, 0,
917
- (void *) &lp_table[nr]);
922
+ struct pardev_cb ppdev_cb;
923
+
924
+ memset(&ppdev_cb, 0, sizeof(ppdev_cb));
925
+ ppdev_cb.preempt = lp_preempt;
926
+ ppdev_cb.private = &lp_table[nr];
927
+ lp_table[nr].dev = parport_register_dev_model(port, "lp",
928
+ &ppdev_cb, nr);
918929 if (lp_table[nr].dev == NULL)
919930 return 1;
920931 lp_table[nr].flags |= LP_EXIST;
....@@ -925,7 +936,7 @@
925936 device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
926937 "lp%d", nr);
927938
928
- printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
939
+ printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
929940 (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven");
930941
931942 #ifdef CONFIG_LP_CONSOLE
....@@ -933,17 +944,18 @@
933944 if (port->modes & PARPORT_MODE_SAFEININT) {
934945 register_console(&lpcons);
935946 console_registered = port;
936
- printk (KERN_INFO "lp%d: console ready\n", CONSOLE_LP);
947
+ printk(KERN_INFO "lp%d: console ready\n", CONSOLE_LP);
937948 } else
938
- printk (KERN_ERR "lp%d: cannot run console on %s\n",
939
- CONSOLE_LP, port->name);
949
+ printk(KERN_ERR "lp%d: cannot run console on %s\n",
950
+ CONSOLE_LP, port->name);
940951 }
941952 #endif
953
+ port_num[nr] = port->number;
942954
943955 return 0;
944956 }
945957
946
-static void lp_attach (struct parport *port)
958
+static void lp_attach(struct parport *port)
947959 {
948960 unsigned int i;
949961
....@@ -957,7 +969,11 @@
957969 printk(KERN_INFO "lp: ignoring parallel port (max. %d)\n",LP_NO);
958970 return;
959971 }
960
- if (!lp_register(lp_count, port))
972
+ for (i = 0; i < LP_NO; i++)
973
+ if (port_num[i] == -1)
974
+ break;
975
+
976
+ if (!lp_register(i, port))
961977 lp_count++;
962978 break;
963979
....@@ -973,8 +989,10 @@
973989 }
974990 }
975991
976
-static void lp_detach (struct parport *port)
992
+static void lp_detach(struct parport *port)
977993 {
994
+ int n;
995
+
978996 /* Write this some day. */
979997 #ifdef CONFIG_LP_CONSOLE
980998 if (console_registered == port) {
....@@ -982,15 +1000,25 @@
9821000 console_registered = NULL;
9831001 }
9841002 #endif /* CONFIG_LP_CONSOLE */
1003
+
1004
+ for (n = 0; n < LP_NO; n++) {
1005
+ if (port_num[n] == port->number) {
1006
+ port_num[n] = -1;
1007
+ lp_count--;
1008
+ device_destroy(lp_class, MKDEV(LP_MAJOR, n));
1009
+ parport_unregister_device(lp_table[n].dev);
1010
+ }
1011
+ }
9851012 }
9861013
9871014 static struct parport_driver lp_driver = {
9881015 .name = "lp",
989
- .attach = lp_attach,
1016
+ .match_port = lp_attach,
9901017 .detach = lp_detach,
1018
+ .devmodel = true,
9911019 };
9921020
993
-static int __init lp_init (void)
1021
+static int __init lp_init(void)
9941022 {
9951023 int i, err = 0;
9961024
....@@ -1007,17 +1035,18 @@
10071035 #ifdef LP_STATS
10081036 lp_table[i].lastcall = 0;
10091037 lp_table[i].runchars = 0;
1010
- memset (&lp_table[i].stats, 0, sizeof (struct lp_stats));
1038
+ memset(&lp_table[i].stats, 0, sizeof(struct lp_stats));
10111039 #endif
10121040 lp_table[i].last_error = 0;
1013
- init_waitqueue_head (&lp_table[i].waitq);
1014
- init_waitqueue_head (&lp_table[i].dataq);
1041
+ init_waitqueue_head(&lp_table[i].waitq);
1042
+ init_waitqueue_head(&lp_table[i].dataq);
10151043 mutex_init(&lp_table[i].port_mutex);
10161044 lp_table[i].timeout = 10 * HZ;
1045
+ port_num[i] = -1;
10171046 }
10181047
1019
- if (register_chrdev (LP_MAJOR, "lp", &lp_fops)) {
1020
- printk (KERN_ERR "lp: unable to get major %d\n", LP_MAJOR);
1048
+ if (register_chrdev(LP_MAJOR, "lp", &lp_fops)) {
1049
+ printk(KERN_ERR "lp: unable to get major %d\n", LP_MAJOR);
10211050 return -EIO;
10221051 }
10231052
....@@ -1027,17 +1056,17 @@
10271056 goto out_reg;
10281057 }
10291058
1030
- if (parport_register_driver (&lp_driver)) {
1031
- printk (KERN_ERR "lp: unable to register with parport\n");
1059
+ if (parport_register_driver(&lp_driver)) {
1060
+ printk(KERN_ERR "lp: unable to register with parport\n");
10321061 err = -EIO;
10331062 goto out_class;
10341063 }
10351064
10361065 if (!lp_count) {
1037
- printk (KERN_INFO "lp: driver loaded but no devices found\n");
1066
+ printk(KERN_INFO "lp: driver loaded but no devices found\n");
10381067 #ifndef CONFIG_PARPORT_1284
10391068 if (parport_nr[0] == LP_PARPORT_AUTO)
1040
- printk (KERN_INFO "lp: (is IEEE 1284 support enabled?)\n");
1069
+ printk(KERN_INFO "lp: (is IEEE 1284 support enabled?)\n");
10411070 #endif
10421071 }
10431072
....@@ -1050,7 +1079,7 @@
10501079 return err;
10511080 }
10521081
1053
-static int __init lp_init_module (void)
1082
+static int __init lp_init_module(void)
10541083 {
10551084 if (parport[0]) {
10561085 /* The user gave some parameters. Let's see what they were. */
....@@ -1064,7 +1093,7 @@
10641093 else {
10651094 char *ep;
10661095 unsigned long r = simple_strtoul(parport[n], &ep, 0);
1067
- if (ep != parport[n])
1096
+ if (ep != parport[n])
10681097 parport_nr[n] = r;
10691098 else {
10701099 printk(KERN_ERR "lp: bad port specifier `%s'\n", parport[n]);
....@@ -1078,23 +1107,15 @@
10781107 return lp_init();
10791108 }
10801109
1081
-static void lp_cleanup_module (void)
1110
+static void lp_cleanup_module(void)
10821111 {
1083
- unsigned int offset;
1084
-
1085
- parport_unregister_driver (&lp_driver);
1112
+ parport_unregister_driver(&lp_driver);
10861113
10871114 #ifdef CONFIG_LP_CONSOLE
1088
- unregister_console (&lpcons);
1115
+ unregister_console(&lpcons);
10891116 #endif
10901117
10911118 unregister_chrdev(LP_MAJOR, "lp");
1092
- for (offset = 0; offset < LP_NO; offset++) {
1093
- if (lp_table[offset].dev == NULL)
1094
- continue;
1095
- parport_unregister_device(lp_table[offset].dev);
1096
- device_destroy(lp_class, MKDEV(LP_MAJOR, offset));
1097
- }
10981119 class_destroy(lp_class);
10991120 }
11001121