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

Configure Feed

Select the types of activity you want to include in your feed.

Input: edt-ft5x06 - use guard notation when acquiring mutex

Guard notation simplifies code.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+31 -56
+31 -56
drivers/input/touchscreen/edt-ft5x06.c
··· 380 380 container_of(dattr, struct edt_ft5x06_attribute, dattr); 381 381 u8 *field = (u8 *)tsdata + attr->field_offset; 382 382 unsigned int val; 383 - size_t count = 0; 384 - int error = 0; 383 + int error; 385 384 u8 addr; 386 385 387 - mutex_lock(&tsdata->mutex); 386 + guard(mutex)(&tsdata->mutex); 388 387 389 - if (tsdata->factory_mode) { 390 - error = -EIO; 391 - goto out; 392 - } 388 + if (tsdata->factory_mode) 389 + return -EIO; 393 390 394 391 switch (tsdata->version) { 395 392 case EDT_M06: ··· 404 407 break; 405 408 406 409 default: 407 - error = -ENODEV; 408 - goto out; 410 + return -ENODEV; 409 411 } 410 412 411 413 if (addr != NO_REGISTER) { ··· 413 417 dev_err(&tsdata->client->dev, 414 418 "Failed to fetch attribute %s, error %d\n", 415 419 dattr->attr.name, error); 416 - goto out; 420 + return error; 417 421 } 418 422 } else { 419 423 val = *field; ··· 426 430 *field = val; 427 431 } 428 432 429 - count = sysfs_emit(buf, "%d\n", val); 430 - out: 431 - mutex_unlock(&tsdata->mutex); 432 - return error ?: count; 433 + return sysfs_emit(buf, "%d\n", val); 433 434 } 434 435 435 436 static ssize_t edt_ft5x06_setting_store(struct device *dev, ··· 442 449 int error; 443 450 u8 addr; 444 451 445 - mutex_lock(&tsdata->mutex); 452 + guard(mutex)(&tsdata->mutex); 446 453 447 - if (tsdata->factory_mode) { 448 - error = -EIO; 449 - goto out; 450 - } 454 + if (tsdata->factory_mode) 455 + return -EIO; 451 456 452 457 error = kstrtouint(buf, 0, &val); 453 458 if (error) 454 - goto out; 459 + return error; 455 460 456 - if (val < attr->limit_low || val > attr->limit_high) { 457 - error = -ERANGE; 458 - goto out; 459 - } 461 + if (val < attr->limit_low || val > attr->limit_high) 462 + return -ERANGE; 460 463 461 464 switch (tsdata->version) { 462 465 case EDT_M06: ··· 470 481 break; 471 482 472 483 default: 473 - error = -ENODEV; 474 - goto out; 484 + return -ENODEV; 475 485 } 476 486 477 487 if (addr != NO_REGISTER) { ··· 479 491 dev_err(&tsdata->client->dev, 480 492 "Failed to update attribute %s, error: %d\n", 481 493 dattr->attr.name, error); 482 - goto out; 494 + return error; 483 495 } 484 496 } 485 497 *field = val; 486 498 487 - out: 488 - mutex_unlock(&tsdata->mutex); 489 - return error ?: count; 499 + return count; 490 500 } 491 501 492 502 /* m06, m09: range 0-31, m12: range 0-5 */ ··· 700 714 static int edt_ft5x06_debugfs_mode_set(void *data, u64 mode) 701 715 { 702 716 struct edt_ft5x06_ts_data *tsdata = data; 703 - int retval = 0; 704 717 705 718 if (mode > 1) 706 719 return -ERANGE; 707 720 708 - mutex_lock(&tsdata->mutex); 721 + guard(mutex)(&tsdata->mutex); 709 722 710 - if (mode != tsdata->factory_mode) { 711 - retval = mode ? edt_ft5x06_factory_mode(tsdata) : 712 - edt_ft5x06_work_mode(tsdata); 713 - } 723 + if (mode == tsdata->factory_mode) 724 + return 0; 714 725 715 - mutex_unlock(&tsdata->mutex); 716 - 717 - return retval; 726 + return mode ? edt_ft5x06_factory_mode(tsdata) : 727 + edt_ft5x06_work_mode(tsdata); 718 728 }; 719 729 720 730 DEFINE_SIMPLE_ATTRIBUTE(debugfs_mode_fops, edt_ft5x06_debugfs_mode_get, ··· 732 750 if (*off < 0 || *off >= tsdata->raw_bufsize) 733 751 return 0; 734 752 735 - mutex_lock(&tsdata->mutex); 753 + guard(mutex)(&tsdata->mutex); 736 754 737 - if (!tsdata->factory_mode || !tsdata->raw_buffer) { 738 - error = -EIO; 739 - goto out; 740 - } 755 + if (!tsdata->factory_mode || !tsdata->raw_buffer) 756 + return -EIO; 741 757 742 758 error = regmap_write(tsdata->regmap, 0x08, 0x01); 743 759 if (error) { 744 760 dev_err(&client->dev, 745 761 "failed to write 0x08 register, error %d\n", error); 746 - goto out; 762 + return error; 747 763 } 748 764 749 765 do { ··· 751 771 dev_err(&client->dev, 752 772 "failed to read 0x08 register, error %d\n", 753 773 error); 754 - goto out; 774 + return error; 755 775 } 756 776 757 777 if (val == 1) ··· 761 781 if (retries == 0) { 762 782 dev_err(&client->dev, 763 783 "timed out waiting for register to settle\n"); 764 - error = -ETIMEDOUT; 765 - goto out; 784 + return -ETIMEDOUT; 766 785 } 767 786 768 787 rdbuf = tsdata->raw_buffer; ··· 771 792 rdbuf[0] = i; /* column index */ 772 793 error = regmap_bulk_read(tsdata->regmap, 0xf5, rdbuf, colbytes); 773 794 if (error) 774 - goto out; 795 + return error; 775 796 776 797 rdbuf += colbytes; 777 798 } 778 799 779 800 read = min_t(size_t, count, tsdata->raw_bufsize - *off); 780 - if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) { 781 - error = -EFAULT; 782 - goto out; 783 - } 801 + if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) 802 + return -EFAULT; 784 803 785 804 *off += read; 786 - out: 787 - mutex_unlock(&tsdata->mutex); 788 - return error ?: read; 805 + return read; 789 806 }; 790 807 791 808 static const struct file_operations debugfs_raw_data_fops = {