diff options
| author | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-06-30 01:47:50 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-06-30 01:47:50 -0400 |
| commit | 152c12f568d4fc6e9a7dfd42f2d51347fb41d9b7 (patch) | |
| tree | ec6b6e5825b0d320529b03d19fc767a81c3faf29 | |
| parent | 9b4311eedb17fa88f02e4876cd6aa9a08e383cd6 (diff) | |
Input: clean up uinput driver (formatting, extra braces)
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
| -rw-r--r-- | drivers/input/misc/uinput.c | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 98710997aaaa..9c3d20073ae3 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c | |||
| @@ -36,16 +36,6 @@ | |||
| 36 | #include <linux/miscdevice.h> | 36 | #include <linux/miscdevice.h> |
| 37 | #include <linux/uinput.h> | 37 | #include <linux/uinput.h> |
| 38 | 38 | ||
| 39 | static int uinput_dev_open(struct input_dev *dev) | ||
| 40 | { | ||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void uinput_dev_close(struct input_dev *dev) | ||
| 45 | { | ||
| 46 | |||
| 47 | } | ||
| 48 | |||
| 49 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 39 | static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
| 50 | { | 40 | { |
| 51 | struct uinput_device *udev; | 41 | struct uinput_device *udev; |
| @@ -68,17 +58,20 @@ static int uinput_request_alloc_id(struct input_dev *dev, struct uinput_request | |||
| 68 | /* Atomically allocate an ID for the given request. Returns 0 on success. */ | 58 | /* Atomically allocate an ID for the given request. Returns 0 on success. */ |
| 69 | struct uinput_device *udev = dev->private; | 59 | struct uinput_device *udev = dev->private; |
| 70 | int id; | 60 | int id; |
| 61 | int err = -1; | ||
| 71 | 62 | ||
| 72 | down(&udev->requests_sem); | 63 | down(&udev->requests_sem); |
| 73 | for (id=0; id<UINPUT_NUM_REQUESTS; id++) | 64 | |
| 65 | for (id = 0; id < UINPUT_NUM_REQUESTS; id++) | ||
| 74 | if (!udev->requests[id]) { | 66 | if (!udev->requests[id]) { |
| 75 | udev->requests[id] = request; | 67 | udev->requests[id] = request; |
| 76 | request->id = id; | 68 | request->id = id; |
| 77 | up(&udev->requests_sem); | 69 | err = 0; |
| 78 | return 0; | 70 | break; |
| 79 | } | 71 | } |
| 72 | |||
| 80 | up(&udev->requests_sem); | 73 | up(&udev->requests_sem); |
| 81 | return -1; | 74 | return err; |
| 82 | } | 75 | } |
| 83 | 76 | ||
| 84 | static struct uinput_request* uinput_request_find(struct uinput_device *udev, int id) | 77 | static struct uinput_request* uinput_request_find(struct uinput_device *udev, int id) |
| @@ -101,7 +94,7 @@ static void uinput_request_init(struct input_dev *dev, struct uinput_request *re | |||
| 101 | 94 | ||
| 102 | /* Allocate an ID. If none are available right away, wait. */ | 95 | /* Allocate an ID. If none are available right away, wait. */ |
| 103 | request->retval = wait_event_interruptible(udev->requests_waitq, | 96 | request->retval = wait_event_interruptible(udev->requests_waitq, |
| 104 | !uinput_request_alloc_id(dev, request)); | 97 | !uinput_request_alloc_id(dev, request)); |
| 105 | } | 98 | } |
| 106 | 99 | ||
| 107 | static void uinput_request_submit(struct input_dev *dev, struct uinput_request *request) | 100 | static void uinput_request_submit(struct input_dev *dev, struct uinput_request *request) |
| @@ -159,32 +152,30 @@ static int uinput_create_device(struct uinput_device *udev) | |||
| 159 | return -EINVAL; | 152 | return -EINVAL; |
| 160 | } | 153 | } |
| 161 | 154 | ||
| 162 | udev->dev->open = uinput_dev_open; | ||
| 163 | udev->dev->close = uinput_dev_close; | ||
| 164 | udev->dev->event = uinput_dev_event; | 155 | udev->dev->event = uinput_dev_event; |
| 165 | udev->dev->upload_effect = uinput_dev_upload_effect; | 156 | udev->dev->upload_effect = uinput_dev_upload_effect; |
| 166 | udev->dev->erase_effect = uinput_dev_erase_effect; | 157 | udev->dev->erase_effect = uinput_dev_erase_effect; |
| 167 | udev->dev->private = udev; | 158 | udev->dev->private = udev; |
| 168 | 159 | ||
| 169 | init_waitqueue_head(&(udev->waitq)); | 160 | init_waitqueue_head(&udev->waitq); |
| 170 | 161 | ||
| 171 | input_register_device(udev->dev); | 162 | input_register_device(udev->dev); |
| 172 | 163 | ||
| 173 | set_bit(UIST_CREATED, &(udev->state)); | 164 | set_bit(UIST_CREATED, &udev->state); |
| 174 | 165 | ||
| 175 | return 0; | 166 | return 0; |
| 176 | } | 167 | } |
| 177 | 168 | ||
| 178 | static int uinput_destroy_device(struct uinput_device *udev) | 169 | static int uinput_destroy_device(struct uinput_device *udev) |
| 179 | { | 170 | { |
| 180 | if (!test_bit(UIST_CREATED, &(udev->state))) { | 171 | if (!test_bit(UIST_CREATED, &udev->state)) { |
| 181 | printk(KERN_WARNING "%s: create the device first\n", UINPUT_NAME); | 172 | printk(KERN_WARNING "%s: create the device first\n", UINPUT_NAME); |
| 182 | return -EINVAL; | 173 | return -EINVAL; |
| 183 | } | 174 | } |
| 184 | 175 | ||
| 185 | input_unregister_device(udev->dev); | 176 | input_unregister_device(udev->dev); |
| 186 | 177 | ||
| 187 | clear_bit(UIST_CREATED, &(udev->state)); | 178 | clear_bit(UIST_CREATED, &udev->state); |
| 188 | 179 | ||
| 189 | return 0; | 180 | return 0; |
| 190 | } | 181 | } |
| @@ -253,15 +244,15 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz | |||
| 253 | struct uinput_user_dev *user_dev; | 244 | struct uinput_user_dev *user_dev; |
| 254 | struct input_dev *dev; | 245 | struct input_dev *dev; |
| 255 | struct uinput_device *udev; | 246 | struct uinput_device *udev; |
| 256 | int size, | 247 | int size; |
| 257 | retval; | 248 | int retval; |
| 258 | 249 | ||
| 259 | retval = count; | 250 | retval = count; |
| 260 | 251 | ||
| 261 | udev = file->private_data; | 252 | udev = file->private_data; |
| 262 | dev = udev->dev; | 253 | dev = udev->dev; |
| 263 | 254 | ||
| 264 | user_dev = kmalloc(sizeof(*user_dev), GFP_KERNEL); | 255 | user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL); |
| 265 | if (!user_dev) { | 256 | if (!user_dev) { |
| 266 | retval = -ENOMEM; | 257 | retval = -ENOMEM; |
| 267 | goto exit; | 258 | goto exit; |
| @@ -272,7 +263,7 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz | |||
| 272 | goto exit; | 263 | goto exit; |
| 273 | } | 264 | } |
| 274 | 265 | ||
| 275 | if (NULL != dev->name) | 266 | if (dev->name) |
| 276 | kfree(dev->name); | 267 | kfree(dev->name); |
| 277 | 268 | ||
| 278 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; | 269 | size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; |
| @@ -314,14 +305,13 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t | |||
| 314 | { | 305 | { |
| 315 | struct uinput_device *udev = file->private_data; | 306 | struct uinput_device *udev = file->private_data; |
| 316 | 307 | ||
| 317 | if (test_bit(UIST_CREATED, &(udev->state))) { | 308 | if (test_bit(UIST_CREATED, &udev->state)) { |
| 318 | struct input_event ev; | 309 | struct input_event ev; |
| 319 | 310 | ||
| 320 | if (copy_from_user(&ev, buffer, sizeof(struct input_event))) | 311 | if (copy_from_user(&ev, buffer, sizeof(struct input_event))) |
| 321 | return -EFAULT; | 312 | return -EFAULT; |
| 322 | input_event(udev->dev, ev.type, ev.code, ev.value); | 313 | input_event(udev->dev, ev.type, ev.code, ev.value); |
| 323 | } | 314 | } else |
| 324 | else | ||
| 325 | count = uinput_alloc_device(file, buffer, count); | 315 | count = uinput_alloc_device(file, buffer, count); |
| 326 | 316 | ||
| 327 | return count; | 317 | return count; |
| @@ -332,26 +322,24 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, | |||
| 332 | struct uinput_device *udev = file->private_data; | 322 | struct uinput_device *udev = file->private_data; |
| 333 | int retval = 0; | 323 | int retval = 0; |
| 334 | 324 | ||
| 335 | if (!test_bit(UIST_CREATED, &(udev->state))) | 325 | if (!test_bit(UIST_CREATED, &udev->state)) |
| 336 | return -ENODEV; | 326 | return -ENODEV; |
| 337 | 327 | ||
| 338 | if ((udev->head == udev->tail) && (file->f_flags & O_NONBLOCK)) | 328 | if (udev->head == udev->tail && (file->f_flags & O_NONBLOCK)) |
| 339 | return -EAGAIN; | 329 | return -EAGAIN; |
| 340 | 330 | ||
| 341 | retval = wait_event_interruptible(udev->waitq, | 331 | retval = wait_event_interruptible(udev->waitq, |
| 342 | (udev->head != udev->tail) || | 332 | udev->head != udev->tail || !test_bit(UIST_CREATED, &udev->state)); |
| 343 | !test_bit(UIST_CREATED, &(udev->state))); | ||
| 344 | |||
| 345 | if (retval) | 333 | if (retval) |
| 346 | return retval; | 334 | return retval; |
| 347 | 335 | ||
| 348 | if (!test_bit(UIST_CREATED, &(udev->state))) | 336 | if (!test_bit(UIST_CREATED, &udev->state)) |
| 349 | return -ENODEV; | 337 | return -ENODEV; |
| 350 | 338 | ||
| 351 | while ((udev->head != udev->tail) && | 339 | while ((udev->head != udev->tail) && |
| 352 | (retval + sizeof(struct input_event) <= count)) { | 340 | (retval + sizeof(struct input_event) <= count)) { |
| 353 | if (copy_to_user(buffer + retval, &(udev->buff[udev->tail]), | 341 | if (copy_to_user(buffer + retval, &udev->buff[udev->tail], sizeof(struct input_event))) |
| 354 | sizeof(struct input_event))) return -EFAULT; | 342 | return -EFAULT; |
| 355 | udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; | 343 | udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; |
| 356 | retval += sizeof(struct input_event); | 344 | retval += sizeof(struct input_event); |
| 357 | } | 345 | } |
| @@ -373,12 +361,12 @@ static unsigned int uinput_poll(struct file *file, poll_table *wait) | |||
| 373 | 361 | ||
| 374 | static int uinput_burn_device(struct uinput_device *udev) | 362 | static int uinput_burn_device(struct uinput_device *udev) |
| 375 | { | 363 | { |
| 376 | if (test_bit(UIST_CREATED, &(udev->state))) | 364 | if (test_bit(UIST_CREATED, &udev->state)) |
| 377 | uinput_destroy_device(udev); | 365 | uinput_destroy_device(udev); |
| 378 | 366 | ||
| 379 | if (NULL != udev->dev->name) | 367 | if (udev->dev->name) |
| 380 | kfree(udev->dev->name); | 368 | kfree(udev->dev->name); |
| 381 | if (NULL != udev->dev->phys) | 369 | if (udev->dev->phys) |
| 382 | kfree(udev->dev->phys); | 370 | kfree(udev->dev->phys); |
| 383 | 371 | ||
| 384 | kfree(udev->dev); | 372 | kfree(udev->dev); |
| @@ -389,7 +377,8 @@ static int uinput_burn_device(struct uinput_device *udev) | |||
| 389 | 377 | ||
| 390 | static int uinput_close(struct inode *inode, struct file *file) | 378 | static int uinput_close(struct inode *inode, struct file *file) |
| 391 | { | 379 | { |
| 392 | return uinput_burn_device(file->private_data); | 380 | uinput_burn_device(file->private_data); |
| 381 | return 0; | ||
| 393 | } | 382 | } |
| 394 | 383 | ||
| 395 | static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | 384 | static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) |
| @@ -415,7 +404,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 415 | case UI_SET_SNDBIT: | 404 | case UI_SET_SNDBIT: |
| 416 | case UI_SET_FFBIT: | 405 | case UI_SET_FFBIT: |
| 417 | case UI_SET_PHYS: | 406 | case UI_SET_PHYS: |
| 418 | if (test_bit(UIST_CREATED, &(udev->state))) | 407 | if (test_bit(UIST_CREATED, &udev->state)) |
| 419 | return -EINVAL; | 408 | return -EINVAL; |
| 420 | } | 409 | } |
| 421 | 410 | ||
| @@ -511,7 +500,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 511 | udev->dev->phys = NULL; | 500 | udev->dev->phys = NULL; |
| 512 | break; | 501 | break; |
| 513 | } | 502 | } |
| 514 | udev->dev->phys[length-1] = '\0'; | 503 | udev->dev->phys[length - 1] = '\0'; |
| 515 | break; | 504 | break; |
| 516 | 505 | ||
| 517 | case UI_BEGIN_FF_UPLOAD: | 506 | case UI_BEGIN_FF_UPLOAD: |
| @@ -520,7 +509,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 520 | break; | 509 | break; |
| 521 | } | 510 | } |
| 522 | req = uinput_request_find(udev, ff_up.request_id); | 511 | req = uinput_request_find(udev, ff_up.request_id); |
| 523 | if (!(req && req->code==UI_FF_UPLOAD && req->u.effect)) { | 512 | if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { |
| 524 | retval = -EINVAL; | 513 | retval = -EINVAL; |
| 525 | break; | 514 | break; |
| 526 | } | 515 | } |
| @@ -538,7 +527,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 538 | break; | 527 | break; |
| 539 | } | 528 | } |
| 540 | req = uinput_request_find(udev, ff_erase.request_id); | 529 | req = uinput_request_find(udev, ff_erase.request_id); |
| 541 | if (!(req && req->code==UI_FF_ERASE)) { | 530 | if (!(req && req->code == UI_FF_ERASE)) { |
| 542 | retval = -EINVAL; | 531 | retval = -EINVAL; |
| 543 | break; | 532 | break; |
| 544 | } | 533 | } |
| @@ -556,7 +545,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 556 | break; | 545 | break; |
| 557 | } | 546 | } |
| 558 | req = uinput_request_find(udev, ff_up.request_id); | 547 | req = uinput_request_find(udev, ff_up.request_id); |
| 559 | if (!(req && req->code==UI_FF_UPLOAD && req->u.effect)) { | 548 | if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) { |
| 560 | retval = -EINVAL; | 549 | retval = -EINVAL; |
| 561 | break; | 550 | break; |
| 562 | } | 551 | } |
| @@ -572,7 +561,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
| 572 | break; | 561 | break; |
| 573 | } | 562 | } |
| 574 | req = uinput_request_find(udev, ff_erase.request_id); | 563 | req = uinput_request_find(udev, ff_erase.request_id); |
| 575 | if (!(req && req->code==UI_FF_ERASE)) { | 564 | if (!(req && req->code == UI_FF_ERASE)) { |
| 576 | retval = -EINVAL; | 565 | retval = -EINVAL; |
| 577 | break; | 566 | break; |
| 578 | } | 567 | } |
