forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/isdn/capi/capi.c
....@@ -39,7 +39,9 @@
3939 #include <linux/isdn/capiutil.h>
4040 #include <linux/isdn/capicmd.h>
4141
42
-MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface");
42
+#include "kcapi.h"
43
+
44
+MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer and /dev/capi20 interface");
4345 MODULE_AUTHOR("Carsten Paeth");
4446 MODULE_LICENSE("GPL");
4547
....@@ -950,6 +952,34 @@
950952 return ret;
951953 }
952954
955
+#ifdef CONFIG_COMPAT
956
+static long
957
+capi_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
958
+{
959
+ int ret;
960
+
961
+ if (cmd == CAPI_MANUFACTURER_CMD) {
962
+ struct {
963
+ compat_ulong_t cmd;
964
+ compat_uptr_t data;
965
+ } mcmd32;
966
+
967
+ if (!capable(CAP_SYS_ADMIN))
968
+ return -EPERM;
969
+ if (copy_from_user(&mcmd32, compat_ptr(arg), sizeof(mcmd32)))
970
+ return -EFAULT;
971
+
972
+ mutex_lock(&capi_mutex);
973
+ ret = capi20_manufacturer(mcmd32.cmd, compat_ptr(mcmd32.data));
974
+ mutex_unlock(&capi_mutex);
975
+
976
+ return ret;
977
+ }
978
+
979
+ return capi_unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
980
+}
981
+#endif
982
+
953983 static int capi_open(struct inode *inode, struct file *file)
954984 {
955985 struct capidev *cdev;
....@@ -968,7 +998,7 @@
968998 list_add_tail(&cdev->list, &capidev_list);
969999 mutex_unlock(&capidev_list_lock);
9701000
971
- return nonseekable_open(inode, file);
1001
+ return stream_open(inode, file);
9721002 }
9731003
9741004 static int capi_release(struct inode *inode, struct file *file)
....@@ -996,6 +1026,9 @@
9961026 .write = capi_write,
9971027 .poll = capi_poll,
9981028 .unlocked_ioctl = capi_unlocked_ioctl,
1029
+#ifdef CONFIG_COMPAT
1030
+ .compat_ioctl = capi_compat_ioctl,
1031
+#endif
9991032 .open = capi_open,
10001033 .release = capi_release,
10011034 };
....@@ -1163,12 +1196,6 @@
11631196 return mp->outbytes;
11641197 }
11651198
1166
-static int capinc_tty_ioctl(struct tty_struct *tty,
1167
- unsigned int cmd, unsigned long arg)
1168
-{
1169
- return -ENOIOCTLCMD;
1170
-}
1171
-
11721199 static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
11731200 {
11741201 pr_debug("capinc_tty_set_termios\n");
....@@ -1244,7 +1271,6 @@
12441271 .flush_chars = capinc_tty_flush_chars,
12451272 .write_room = capinc_tty_write_room,
12461273 .chars_in_buffer = capinc_tty_chars_in_buffer,
1247
- .ioctl = capinc_tty_ioctl,
12481274 .set_termios = capinc_tty_set_termios,
12491275 .throttle = capinc_tty_throttle,
12501276 .unthrottle = capinc_tty_unthrottle,
....@@ -1388,15 +1414,22 @@
13881414 {
13891415 const char *compileinfo;
13901416 int major_ret;
1417
+ int ret;
1418
+
1419
+ ret = kcapi_init();
1420
+ if (ret)
1421
+ return ret;
13911422
13921423 major_ret = register_chrdev(capi_major, "capi20", &capi_fops);
13931424 if (major_ret < 0) {
13941425 printk(KERN_ERR "capi20: unable to get major %d\n", capi_major);
1426
+ kcapi_exit();
13951427 return major_ret;
13961428 }
13971429 capi_class = class_create(THIS_MODULE, "capi");
13981430 if (IS_ERR(capi_class)) {
13991431 unregister_chrdev(capi_major, "capi20");
1432
+ kcapi_exit();
14001433 return PTR_ERR(capi_class);
14011434 }
14021435
....@@ -1406,6 +1439,7 @@
14061439 device_destroy(capi_class, MKDEV(capi_major, 0));
14071440 class_destroy(capi_class);
14081441 unregister_chrdev(capi_major, "capi20");
1442
+ kcapi_exit();
14091443 return -ENOMEM;
14101444 }
14111445
....@@ -1431,6 +1465,8 @@
14311465 unregister_chrdev(capi_major, "capi20");
14321466
14331467 capinc_tty_exit();
1468
+
1469
+ kcapi_exit();
14341470 }
14351471
14361472 module_init(capi_init);