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: adxl34x - switch to using "guard" notation

Switch to using guard(mutex)() notation to acquire and automatically
release mutexes.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240610164301.1048482-4-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+20 -41
+20 -41
drivers/input/misc/adxl34x.c
··· 241 241 242 242 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf); 243 243 244 - mutex_lock(&ac->mutex); 244 + guard(mutex)(&ac->mutex); 245 + 245 246 ac->saved.x = (s16) le16_to_cpu(buf[0]); 246 247 axis->x = ac->saved.x; 247 248 ··· 251 250 252 251 ac->saved.z = (s16) le16_to_cpu(buf[2]); 253 252 axis->z = ac->saved.z; 254 - mutex_unlock(&ac->mutex); 255 253 } 256 254 257 255 static void adxl34x_service_ev_fifo(struct adxl34x *ac) ··· 416 416 { 417 417 struct adxl34x *ac = dev_get_drvdata(dev); 418 418 419 - mutex_lock(&ac->mutex); 419 + guard(mutex)(&ac->mutex); 420 420 421 421 if (!ac->suspended && !ac->disabled && ac->opened) 422 422 __adxl34x_disable(ac); 423 423 424 424 ac->suspended = true; 425 - 426 - mutex_unlock(&ac->mutex); 427 425 428 426 return 0; 429 427 } ··· 430 432 { 431 433 struct adxl34x *ac = dev_get_drvdata(dev); 432 434 433 - mutex_lock(&ac->mutex); 435 + guard(mutex)(&ac->mutex); 434 436 435 437 if (ac->suspended && !ac->disabled && ac->opened) 436 438 __adxl34x_enable(ac); 437 439 438 440 ac->suspended = false; 439 - 440 - mutex_unlock(&ac->mutex); 441 441 442 442 return 0; 443 443 } ··· 460 464 if (error) 461 465 return error; 462 466 463 - mutex_lock(&ac->mutex); 467 + guard(mutex)(&ac->mutex); 464 468 465 469 if (!ac->suspended && ac->opened) { 466 470 if (val) { ··· 474 478 475 479 ac->disabled = !!val; 476 480 477 - mutex_unlock(&ac->mutex); 478 - 479 481 return count; 480 482 } 481 483 ··· 483 489 struct device_attribute *attr, char *buf) 484 490 { 485 491 struct adxl34x *ac = dev_get_drvdata(dev); 486 - ssize_t count; 487 492 488 - mutex_lock(&ac->mutex); 489 - count = sprintf(buf, "%d,%d,%d\n", 490 - ac->hwcal.x * 4 + ac->swcal.x, 491 - ac->hwcal.y * 4 + ac->swcal.y, 492 - ac->hwcal.z * 4 + ac->swcal.z); 493 - mutex_unlock(&ac->mutex); 493 + guard(mutex)(&ac->mutex); 494 494 495 - return count; 495 + return sprintf(buf, "%d,%d,%d\n", 496 + ac->hwcal.x * 4 + ac->swcal.x, 497 + ac->hwcal.y * 4 + ac->swcal.y, 498 + ac->hwcal.z * 4 + ac->swcal.z); 496 499 } 497 500 498 501 static ssize_t adxl34x_calibrate_store(struct device *dev, ··· 503 512 * We use HW calibration and handle the remaining bits in SW. (4mg/LSB) 504 513 */ 505 514 506 - mutex_lock(&ac->mutex); 515 + guard(mutex)(&ac->mutex); 516 + 507 517 ac->hwcal.x -= (ac->saved.x / 4); 508 518 ac->swcal.x = ac->saved.x % 4; 509 519 ··· 517 525 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x); 518 526 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y); 519 527 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z); 520 - mutex_unlock(&ac->mutex); 521 528 522 529 return count; 523 530 } ··· 544 553 if (error) 545 554 return error; 546 555 547 - mutex_lock(&ac->mutex); 556 + guard(mutex)(&ac->mutex); 548 557 549 558 ac->pdata.data_rate = RATE(val); 550 559 AC_WRITE(ac, BW_RATE, 551 560 ac->pdata.data_rate | 552 561 (ac->pdata.low_power_mode ? LOW_POWER : 0)); 553 - 554 - mutex_unlock(&ac->mutex); 555 562 556 563 return count; 557 564 } ··· 577 588 if (error) 578 589 return error; 579 590 580 - mutex_lock(&ac->mutex); 591 + guard(mutex)(&ac->mutex); 581 592 582 593 if (val) 583 594 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK); ··· 586 597 587 598 if (!ac->disabled && !ac->suspended && ac->opened) 588 599 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); 589 - 590 - mutex_unlock(&ac->mutex); 591 600 592 601 return count; 593 602 } ··· 597 610 struct device_attribute *attr, char *buf) 598 611 { 599 612 struct adxl34x *ac = dev_get_drvdata(dev); 600 - ssize_t count; 601 613 602 - mutex_lock(&ac->mutex); 603 - count = sprintf(buf, "(%d, %d, %d)\n", 604 - ac->saved.x, ac->saved.y, ac->saved.z); 605 - mutex_unlock(&ac->mutex); 614 + guard(mutex)(&ac->mutex); 606 615 607 - return count; 616 + return sprintf(buf, "(%d, %d, %d)\n", 617 + ac->saved.x, ac->saved.y, ac->saved.z); 608 618 } 609 619 610 620 static DEVICE_ATTR(position, S_IRUGO, adxl34x_position_show, NULL); ··· 622 638 if (error) 623 639 return error; 624 640 625 - mutex_lock(&ac->mutex); 641 + guard(mutex)(&ac->mutex); 626 642 AC_WRITE(ac, val >> 8, val & 0xFF); 627 - mutex_unlock(&ac->mutex); 628 643 629 644 return count; 630 645 } ··· 657 674 { 658 675 struct adxl34x *ac = input_get_drvdata(input); 659 676 660 - mutex_lock(&ac->mutex); 677 + guard(mutex)(&ac->mutex); 661 678 662 679 if (!ac->suspended && !ac->disabled) 663 680 __adxl34x_enable(ac); 664 681 665 682 ac->opened = true; 666 - 667 - mutex_unlock(&ac->mutex); 668 683 669 684 return 0; 670 685 } ··· 671 690 { 672 691 struct adxl34x *ac = input_get_drvdata(input); 673 692 674 - mutex_lock(&ac->mutex); 693 + guard(mutex)(&ac->mutex); 675 694 676 695 if (!ac->suspended && !ac->disabled) 677 696 __adxl34x_disable(ac); 678 697 679 698 ac->opened = false; 680 - 681 - mutex_unlock(&ac->mutex); 682 699 } 683 700 684 701 struct adxl34x *adxl34x_probe(struct device *dev, int irq,