Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * general timer device for using in ISDN stacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author	Karsten Keil <kkeil@novell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright 2008  by Karsten Keil <kkeil@novell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mISDNif.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static DEFINE_MUTEX(mISDN_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static u_int	*debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct mISDNtimerdev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int			next_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct list_head	pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct list_head	expired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	wait_queue_head_t	wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u_int			work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	spinlock_t		lock; /* protect lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct mISDNtimer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct list_head	list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct  mISDNtimerdev	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct timer_list	tl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int			id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) mISDN_open(struct inode *ino, struct file *filep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct mISDNtimerdev	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	dev = kmalloc(sizeof(struct mISDNtimerdev) , GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	dev->next_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	INIT_LIST_HEAD(&dev->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	INIT_LIST_HEAD(&dev->expired);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	spin_lock_init(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	dev->work = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	init_waitqueue_head(&dev->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	filep->private_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return nonseekable_open(ino, filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) mISDN_close(struct inode *ino, struct file *filep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct mISDNtimerdev	*dev = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct list_head	*list = &dev->pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct mISDNtimer	*timer, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	while (!list_empty(list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		timer = list_first_entry(list, struct mISDNtimer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		del_timer_sync(&timer->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		/* it might have been moved to ->expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		list_del(&timer->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		kfree(timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	list_for_each_entry_safe(timer, next, &dev->expired, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		kfree(timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) mISDN_read(struct file *filep, char __user *buf, size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct mISDNtimerdev	*dev = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct list_head *list = &dev->expired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct mISDNtimer	*timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		printk(KERN_DEBUG "%s(%p, %p, %d, %p)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		       filep, buf, (int)count, off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (count < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	while (list_empty(list) && (dev->work == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (filep->f_flags & O_NONBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		wait_event_interruptible(dev->wait, (dev->work ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 						     !list_empty(list)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (dev->work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		dev->work = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (!list_empty(list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		timer = list_first_entry(list, struct mISDNtimer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		list_del(&timer->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (put_user(timer->id, (int __user *)buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			ret = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		kfree(timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static __poll_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) mISDN_poll(struct file *filep, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct mISDNtimerdev	*dev = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	__poll_t		mask = EPOLLERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		printk(KERN_DEBUG "%s(%p, %p)\n", __func__, filep, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		poll_wait(filep, &dev->wait, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (dev->work || !list_empty(&dev->expired))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			mask |= (EPOLLIN | EPOLLRDNORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			printk(KERN_DEBUG "%s work(%d) empty(%d)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			       dev->work, list_empty(&dev->expired));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dev_expire_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct mISDNtimer *timer = from_timer(timer, t, tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	u_long			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	spin_lock_irqsave(&timer->dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (timer->id >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		list_move_tail(&timer->list, &timer->dev->expired);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	wake_up_interruptible(&timer->dev->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	spin_unlock_irqrestore(&timer->dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) misdn_add_timer(struct mISDNtimerdev *dev, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int			id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct mISDNtimer	*timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		dev->work = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		wake_up_interruptible(&dev->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		timer = kzalloc(sizeof(struct mISDNtimer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (!timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		timer->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		timer_setup(&timer->tl, dev_expire_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		id = timer->id = dev->next_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (dev->next_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			dev->next_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		list_add_tail(&timer->list, &dev->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		timer->tl.expires = jiffies + ((HZ * (u_long)timeout) / 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		add_timer(&timer->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) misdn_del_timer(struct mISDNtimerdev *dev, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct mISDNtimer	*timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	spin_lock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	list_for_each_entry(timer, &dev->pending, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (timer->id == id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			list_del_init(&timer->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			timer->id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			del_timer_sync(&timer->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			kfree(timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	spin_unlock_irq(&dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) mISDN_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct mISDNtimerdev	*dev = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	int			id, tout, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		printk(KERN_DEBUG "%s(%p, %x, %lx)\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		       filep, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	mutex_lock(&mISDN_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	case IMADDTIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (get_user(tout, (int __user *)arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		id = misdn_add_timer(dev, tout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			printk(KERN_DEBUG "%s add %d id %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			       tout, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		if (id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			ret = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if (put_user(id, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	case IMDELTIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (get_user(id, (int __user *)arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (*debug & DEBUG_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			printk(KERN_DEBUG "%s del id %d\n", __func__, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		id = misdn_del_timer(dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (put_user(id, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	mutex_unlock(&mISDN_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static const struct file_operations mISDN_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.read		= mISDN_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	.poll		= mISDN_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.unlocked_ioctl	= mISDN_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.open		= mISDN_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.release	= mISDN_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.llseek		= no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static struct miscdevice mISDNtimer = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.minor	= MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.name	= "mISDNtimer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.fops	= &mISDN_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) mISDN_inittimer(u_int *deb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	int	err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	debug = deb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	err = misc_register(&mISDNtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		printk(KERN_WARNING "mISDN: Could not register timer device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) void mISDN_timer_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	misc_deregister(&mISDNtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }