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.

platform/x86: ideapad-laptop: Make the scope_guard() clear of its scope

First of all, it's a bit counterintuitive to have something like

int err;
...
scoped_guard(...)
err = foo(...);
if (err)
return err;

Second, with a particular kernel configuration and compiler version in
one of such cases the objtool is not happy:

ideapad-laptop.o: warning: objtool: .text.fan_mode_show: unexpected end of section

I'm not an expert on all this, but the theory is that compiler and
linker in this case can't understand that 'result' variable will be
always initialized as long as no error has been returned. Assigning
'result' to a dummy value helps with this. Note, that fixing the
scoped_guard() scope (as per above) does not make issue gone.

That said, assign dummy value and make the scope_guard() clear of its scope.
For the sake of consistency do it in the entire file.

Fixes: 7cc06e729460 ("platform/x86: ideapad-laptop: add a mutex to synchronize VPC commands")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202408290219.BrPO8twi-lkp@intel.com/
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240829165105.1609180-1-andriy.shevchenko@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Andy Shevchenko and committed by
Hans de Goede
a093cb66 24b66163

+27 -21
+27 -21
drivers/platform/x86/ideapad-laptop.c
··· 554 554 char *buf) 555 555 { 556 556 struct ideapad_private *priv = dev_get_drvdata(dev); 557 - unsigned long result; 557 + unsigned long result = 0; 558 558 int err; 559 559 560 - scoped_guard(mutex, &priv->vpc_mutex) 560 + scoped_guard(mutex, &priv->vpc_mutex) { 561 561 err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); 562 - if (err) 563 - return err; 562 + if (err) 563 + return err; 564 + } 564 565 565 566 return sysfs_emit(buf, "%d\n", !!result); 566 567 } ··· 578 577 if (err) 579 578 return err; 580 579 581 - scoped_guard(mutex, &priv->vpc_mutex) 580 + scoped_guard(mutex, &priv->vpc_mutex) { 582 581 err = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); 583 - if (err) 584 - return err; 582 + if (err) 583 + return err; 584 + } 585 585 586 586 return count; 587 587 } ··· 630 628 char *buf) 631 629 { 632 630 struct ideapad_private *priv = dev_get_drvdata(dev); 633 - unsigned long result; 631 + unsigned long result = 0; 634 632 int err; 635 633 636 - scoped_guard(mutex, &priv->vpc_mutex) 634 + scoped_guard(mutex, &priv->vpc_mutex) { 637 635 err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); 638 - if (err) 639 - return err; 636 + if (err) 637 + return err; 638 + } 640 639 641 640 return sysfs_emit(buf, "%lu\n", result); 642 641 } ··· 657 654 if (state > 4 || state == 3) 658 655 return -EINVAL; 659 656 660 - scoped_guard(mutex, &priv->vpc_mutex) 657 + scoped_guard(mutex, &priv->vpc_mutex) { 661 658 err = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); 662 - if (err) 663 - return err; 659 + if (err) 660 + return err; 661 + } 664 662 665 663 return count; 666 664 } ··· 741 737 char *buf) 742 738 { 743 739 struct ideapad_private *priv = dev_get_drvdata(dev); 744 - unsigned long result; 740 + unsigned long result = 0; 745 741 int err; 746 742 747 - scoped_guard(mutex, &priv->vpc_mutex) 743 + scoped_guard(mutex, &priv->vpc_mutex) { 748 744 err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); 749 - if (err) 750 - return err; 745 + if (err) 746 + return err; 747 + } 751 748 752 749 priv->r_touchpad_val = result; 753 750 ··· 767 762 if (err) 768 763 return err; 769 764 770 - scoped_guard(mutex, &priv->vpc_mutex) 765 + scoped_guard(mutex, &priv->vpc_mutex) { 771 766 err = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); 772 - if (err) 773 - return err; 767 + if (err) 768 + return err; 769 + } 774 770 775 771 priv->r_touchpad_val = state; 776 772