| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/drivers/char/ppdev.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * application to use the parport subsystem. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Copyright (C) 1998-2000, 2002 Tim Waugh <tim@cyberelk.net> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or |
|---|
| 10 | | - * modify it under the terms of the GNU General Public License |
|---|
| 11 | | - * as published by the Free Software Foundation; either version |
|---|
| 12 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 13 | 9 | * |
|---|
| 14 | 10 | * A /dev/parportx device node represents an arbitrary device |
|---|
| 15 | 11 | * on port 'x'. The following operations are possible: |
|---|
| .. | .. |
|---|
| 359 | 355 | struct pp_struct *pp = file->private_data; |
|---|
| 360 | 356 | struct parport *port; |
|---|
| 361 | 357 | void __user *argp = (void __user *)arg; |
|---|
| 358 | + struct ieee1284_info *info; |
|---|
| 359 | + unsigned char reg; |
|---|
| 360 | + unsigned char mask; |
|---|
| 361 | + int mode; |
|---|
| 362 | + s32 time32[2]; |
|---|
| 363 | + s64 time64[2]; |
|---|
| 364 | + struct timespec64 ts; |
|---|
| 365 | + int ret; |
|---|
| 362 | 366 | |
|---|
| 363 | 367 | /* First handle the cases that don't take arguments. */ |
|---|
| 364 | 368 | switch (cmd) { |
|---|
| 365 | 369 | case PPCLAIM: |
|---|
| 366 | 370 | { |
|---|
| 367 | | - struct ieee1284_info *info; |
|---|
| 368 | | - int ret; |
|---|
| 369 | | - |
|---|
| 370 | 371 | if (pp->flags & PP_CLAIMED) { |
|---|
| 371 | 372 | dev_dbg(&pp->pdev->dev, "you've already got it!\n"); |
|---|
| 372 | 373 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 517 | 518 | |
|---|
| 518 | 519 | port = pp->pdev->port; |
|---|
| 519 | 520 | switch (cmd) { |
|---|
| 520 | | - struct ieee1284_info *info; |
|---|
| 521 | | - unsigned char reg; |
|---|
| 522 | | - unsigned char mask; |
|---|
| 523 | | - int mode; |
|---|
| 524 | | - s32 time32[2]; |
|---|
| 525 | | - s64 time64[2]; |
|---|
| 526 | | - struct timespec64 ts; |
|---|
| 527 | | - int ret; |
|---|
| 528 | | - |
|---|
| 529 | 521 | case PPRSTATUS: |
|---|
| 530 | 522 | reg = parport_read_status(port); |
|---|
| 531 | 523 | if (copy_to_user(argp, ®, sizeof(reg))) |
|---|
| .. | .. |
|---|
| 682 | 674 | return ret; |
|---|
| 683 | 675 | } |
|---|
| 684 | 676 | |
|---|
| 685 | | -#ifdef CONFIG_COMPAT |
|---|
| 686 | | -static long pp_compat_ioctl(struct file *file, unsigned int cmd, |
|---|
| 687 | | - unsigned long arg) |
|---|
| 688 | | -{ |
|---|
| 689 | | - return pp_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); |
|---|
| 690 | | -} |
|---|
| 691 | | -#endif |
|---|
| 692 | | - |
|---|
| 693 | 677 | static int pp_open(struct inode *inode, struct file *file) |
|---|
| 694 | 678 | { |
|---|
| 695 | 679 | unsigned int minor = iminor(inode); |
|---|
| .. | .. |
|---|
| 749 | 733 | "negotiated back to compatibility mode because user-space forgot\n"); |
|---|
| 750 | 734 | } |
|---|
| 751 | 735 | |
|---|
| 752 | | - if (pp->flags & PP_CLAIMED) { |
|---|
| 736 | + if ((pp->flags & PP_CLAIMED) && pp->pdev) { |
|---|
| 753 | 737 | struct ieee1284_info *info; |
|---|
| 754 | 738 | |
|---|
| 755 | 739 | info = &pp->pdev->port->ieee1284; |
|---|
| .. | .. |
|---|
| 798 | 782 | .write = pp_write, |
|---|
| 799 | 783 | .poll = pp_poll, |
|---|
| 800 | 784 | .unlocked_ioctl = pp_ioctl, |
|---|
| 801 | | -#ifdef CONFIG_COMPAT |
|---|
| 802 | | - .compat_ioctl = pp_compat_ioctl, |
|---|
| 803 | | -#endif |
|---|
| 785 | + .compat_ioctl = compat_ptr_ioctl, |
|---|
| 804 | 786 | .open = pp_open, |
|---|
| 805 | 787 | .release = pp_release, |
|---|
| 806 | 788 | }; |
|---|