Lines Matching +full:free +full:- +full:running

6  * This program is free software; you can redistribute it and/or modify it
8 * the Free Software Foundation; either version 2 of the License, or (at
39 bool running; member
51 * userio_device_write - Write data from serio to a userio device in userspace
57 struct userio_device *userio = id->port_data; in userio_device_write()
60 spin_lock_irqsave(&userio->buf_lock, flags); in userio_device_write()
62 userio->buf[userio->head] = val; in userio_device_write()
63 userio->head = (userio->head + 1) % USERIO_BUFSIZE; in userio_device_write()
65 if (userio->head == userio->tail) in userio_device_write()
69 spin_unlock_irqrestore(&userio->buf_lock, flags); in userio_device_write()
71 wake_up_interruptible(&userio->waitq); in userio_device_write()
82 return -ENOMEM; in userio_char_open()
84 mutex_init(&userio->mutex); in userio_char_open()
85 spin_lock_init(&userio->buf_lock); in userio_char_open()
86 init_waitqueue_head(&userio->waitq); in userio_char_open()
88 userio->serio = kzalloc(sizeof(*userio->serio), GFP_KERNEL); in userio_char_open()
89 if (!userio->serio) { in userio_char_open()
91 return -ENOMEM; in userio_char_open()
94 userio->serio->write = userio_device_write; in userio_char_open()
95 userio->serio->port_data = userio; in userio_char_open()
97 file->private_data = userio; in userio_char_open()
104 struct userio_device *userio = file->private_data; in userio_char_release()
106 if (userio->running) { in userio_char_release()
108 * Don't free the serio port here, serio_unregister_port() in userio_char_release()
111 serio_unregister_port(userio->serio); in userio_char_release()
113 kfree(userio->serio); in userio_char_release()
124 struct userio_device *userio = file->private_data; in userio_char_read()
134 * until we have data (unless the file descriptor is non-blocking in userio_char_read()
138 spin_lock_irqsave(&userio->buf_lock, flags); in userio_char_read()
140 nonwrap_len = CIRC_CNT_TO_END(userio->head, in userio_char_read()
141 userio->tail, in userio_char_read()
145 memcpy(buf, &userio->buf[userio->tail], copylen); in userio_char_read()
146 userio->tail = (userio->tail + copylen) % in userio_char_read()
150 spin_unlock_irqrestore(&userio->buf_lock, flags); in userio_char_read()
156 if (file->f_flags & O_NONBLOCK) in userio_char_read()
157 return -EAGAIN; in userio_char_read()
160 * count == 0 is special - no IO is done but we check in userio_char_read()
166 error = wait_event_interruptible(userio->waitq, in userio_char_read()
167 userio->head != userio->tail); in userio_char_read()
174 return -EFAULT; in userio_char_read()
182 struct userio_device *userio = file->private_data; in userio_char_write()
188 return -EINVAL; in userio_char_write()
192 return -EFAULT; in userio_char_write()
194 error = mutex_lock_interruptible(&userio->mutex); in userio_char_write()
200 if (!userio->serio->id.type) { in userio_char_write()
204 error = -EINVAL; in userio_char_write()
208 if (userio->running) { in userio_char_write()
210 "Begin command sent, but we're already running\n"); in userio_char_write()
211 error = -EBUSY; in userio_char_write()
215 userio->running = true; in userio_char_write()
216 serio_register_port(userio->serio); in userio_char_write()
220 if (userio->running) { in userio_char_write()
222 "Can't change port type on an already running userio instance\n"); in userio_char_write()
223 error = -EBUSY; in userio_char_write()
227 userio->serio->id.type = cmd.data; in userio_char_write()
231 if (!userio->running) { in userio_char_write()
234 error = -ENODEV; in userio_char_write()
238 serio_interrupt(userio->serio, cmd.data, 0); in userio_char_write()
242 error = -EOPNOTSUPP; in userio_char_write()
247 mutex_unlock(&userio->mutex); in userio_char_write()
253 struct userio_device *userio = file->private_data; in userio_char_poll()
255 poll_wait(file, &userio->waitq, wait); in userio_char_poll()
257 if (userio->head != userio->tail) in userio_char_poll()