Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: clean up uinput driver (formatting, extra braces)

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

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