All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] ACPI: PM: Address issues related to managing wakeup power resources
@ 2021-10-15 16:59 Rafael J. Wysocki
  2021-10-15 17:01 ` [PATCH v1 1/3] ACPI: PM: Turn off unused " Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2021-10-15 16:59 UTC (permalink / raw)
  To: Linux ACPI; +Cc: Linux PM, LKML, Mika Westerberg, Linux PCI

Hi,

There are a few issues related to the management of ACPI power resources used
for signaling wakeup that are addressed by the first two patches in this series
(please refer to the changelogs of these patches for details) and the last
patch makes the code a bit more consistent.

Thanks!




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v1 1/3] ACPI: PM: Turn off unused wakeup power resources
  2021-10-15 16:59 [PATCH v1 0/3] ACPI: PM: Address issues related to managing wakeup power resources Rafael J. Wysocki
@ 2021-10-15 17:01 ` Rafael J. Wysocki
  2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
  2021-10-15 17:04 ` [PATCH v1 3/3] ACPI: PM: Turn off wakeup power resources on _DSW/_PSW errors Rafael J. Wysocki
  2 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2021-10-15 17:01 UTC (permalink / raw)
  To: Linux ACPI; +Cc: Linux PM, LKML, Mika Westerberg, Linux PCI

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If an ACPI power resource is found to be "on" during the
initialization of the list of wakeup power resources of a device,
it is reference counted and its wakeup_enabled flag is set, which is
problematic if the deivce in question is the only user of the given
power resource, it is never runtime-suspended and it is not allowed
to wake up the system from sleep, because in that case the given
power resource will stay "on" until the system reboots and energy
will be wasted.

It is better to simply turn off wakeup power resources that are "on"
during the initialization unless their reference counters are not
zero, because that may be the only opportunity to prevent them from
staying in the "on" state all the time.

Fixes: b5d667eb392e ("ACPI / PM: Take unusual configurations of power resources into account")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/power.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -615,20 +615,19 @@ int acpi_power_wakeup_list_init(struct l
 
 	list_for_each_entry(entry, list, node) {
 		struct acpi_power_resource *resource = entry->resource;
-		int result;
 		u8 state;
 
 		mutex_lock(&resource->resource_lock);
 
-		result = acpi_power_get_state(resource, &state);
-		if (result) {
-			mutex_unlock(&resource->resource_lock);
-			return result;
-		}
-		if (state == ACPI_POWER_RESOURCE_STATE_ON) {
-			resource->ref_count++;
-			resource->wakeup_enabled = true;
-		}
+		/*
+		 * Make sure that the power resource state and its reference
+		 * counter value are consistent with each other.
+		 */
+		if (!resource->ref_count &&
+		    !acpi_power_get_state(resource, &state) &&
+		    state == ACPI_POWER_RESOURCE_STATE_ON)
+			__acpi_power_off(resource);
+
 		if (system_level > resource->system_level)
 			system_level = resource->system_level;
 




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
  2021-10-15 16:59 [PATCH v1 0/3] ACPI: PM: Address issues related to managing wakeup power resources Rafael J. Wysocki
  2021-10-15 17:01 ` [PATCH v1 1/3] ACPI: PM: Turn off unused " Rafael J. Wysocki
@ 2021-10-15 17:03 ` Rafael J. Wysocki
  2021-10-15 20:31     ` kernel test robot
                     ` (2 more replies)
  2021-10-15 17:04 ` [PATCH v1 3/3] ACPI: PM: Turn off wakeup power resources on _DSW/_PSW errors Rafael J. Wysocki
  2 siblings, 3 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2021-10-15 17:03 UTC (permalink / raw)
  To: Linux ACPI; +Cc: Linux PM, LKML, Mika Westerberg, Linux PCI

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If an ACPI wakeup power resource is shared between multiple devices,
it may not be managed correctly.

Suppose, for example, that two devices, A and B, share a wakeup power
resource P whose wakeup_enabled flag is 0 initially.  Next, suppose
that wakeup power is enabled for A and B, in this order, and disabled
for B.  When wakeup power is enabled for A, P will be turned on and
its wakeup_enabled flag will be set.  Next, when wakeup power is
enabled for B, P will not be touched, because its wakeup_enabled flag
is set.  Now, when wakeup power is disabled for B, P will be turned
off which is incorrect, because A will still need P in order to signal
wakeup.

Moreover, if wakeup power is enabled for A and then disabled for B,
the latter will cause P to be turned off incorrectly (it will be still
needed by A), because acpi_disable_wakeup_device_power() is allowed
to manipulate power resources when the wakeup.prepare_count counter
of the given device is 0.

While the first issue could be addressed by changing the
wakeup_enabled power resource flag into a counter, addressing the
second one requires modifying acpi_disable_wakeup_device_power() to
do nothing when the target device's wakeup.prepare_count reference
counter is zero and that would cause the new counter to be redundant.
Namely, if acpi_disable_wakeup_device_power() is modified as per the
above, every change of the new counter following a wakeup.prepare_count
change would be reflected by the analogous change of the main reference
counter of the given power resource.

Accordingly, modify acpi_disable_wakeup_device_power() to do nothing
when the target device's wakeup.prepare_count reference counter is
zero and drop the power resource wakeup_enabled flag altogether.

While at it, ensure that all of the power resources that can be
turned off will be turned off when disabling device wakeup due to
a power resource manipulation error, to prevent energy from being
wasted.

Fixes: b5d667eb392e ("ACPI / PM: Take unusual configurations of power resources into account")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/power.c |   73 ++++++++++++++++++---------------------------------
 1 file changed, 26 insertions(+), 47 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -52,7 +52,6 @@ struct acpi_power_resource {
 	u32 order;
 	unsigned int ref_count;
 	u8 state;
-	bool wakeup_enabled;
 	struct mutex resource_lock;
 	struct list_head dependents;
 };
@@ -710,8 +709,7 @@ int acpi_device_sleep_wake(struct acpi_d
  */
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
 {
-	struct acpi_power_resource_entry *entry;
-	int err = 0;
+	int err;
 
 	if (!dev || !dev->wakeup.flags.valid)
 		return -EINVAL;
@@ -721,26 +719,13 @@ int acpi_enable_wakeup_device_power(stru
 	if (dev->wakeup.prepare_count++)
 		goto out;
 
-	list_for_each_entry(entry, &dev->wakeup.resources, node) {
-		struct acpi_power_resource *resource = entry->resource;
-
-		mutex_lock(&resource->resource_lock);
-
-		if (!resource->wakeup_enabled) {
-			err = acpi_power_on_unlocked(resource);
-			if (!err)
-				resource->wakeup_enabled = true;
-		}
-
-		mutex_unlock(&resource->resource_lock);
-
-		if (err) {
-			dev_err(&dev->dev,
-				"Cannot turn wakeup power resources on\n");
-			dev->wakeup.flags.valid = 0;
-			goto out;
-		}
+	err = acpi_power_on_list(&dev->wakeup.resources);
+	if (err) {
+		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
+		dev->wakeup.flags.valid = 0;
+		goto out;
 	}
+
 	/*
 	 * Passing 3 as the third argument below means the device may be
 	 * put into arbitrary power state afterward.
@@ -763,46 +748,40 @@ int acpi_enable_wakeup_device_power(stru
 int acpi_disable_wakeup_device_power(struct acpi_device *dev)
 {
 	struct acpi_power_resource_entry *entry;
-	int err = 0;
+	int err;
 
 	if (!dev || !dev->wakeup.flags.valid)
 		return -EINVAL;
 
 	mutex_lock(&acpi_device_lock);
 
-	if (--dev->wakeup.prepare_count > 0)
+	if (dev->wakeup.prepare_count > 1) {
+		dev->wakeup.prepare_count--;
 		goto out;
+	}
 
-	/*
-	 * Executing the code below even if prepare_count is already zero when
-	 * the function is called may be useful, for example for initialisation.
-	 */
-	if (dev->wakeup.prepare_count < 0)
-		dev->wakeup.prepare_count = 0;
+	/* Do nothing if wakeup power has not been enabled for this device. */
+	if (!dev->wakeup.prepare_count)
+		goto out;
 
 	err = acpi_device_sleep_wake(dev, 0, 0, 0);
 	if (err)
 		goto out;
 
+	/*
+	 * All of the power resources in the list need to be turned off even if
+	 * there are errors.
+	 */
 	list_for_each_entry(entry, &dev->wakeup.resources, node) {
-		struct acpi_power_resource *resource = entry->resource;
-
-		mutex_lock(&resource->resource_lock);
-
-		if (resource->wakeup_enabled) {
-			err = acpi_power_off_unlocked(resource);
-			if (!err)
-				resource->wakeup_enabled = false;
-		}
-
-		mutex_unlock(&resource->resource_lock);
+		int ret;
 
-		if (err) {
-			dev_err(&dev->dev,
-				"Cannot turn wakeup power resources off\n");
-			dev->wakeup.flags.valid = 0;
-			break;
-		}
+		ret = acpi_power_off(entry->resource);
+		if (ret && !err)
+			err = ret;
+	}
+	if (err) {
+		dev_err(&dev->dev, "Cannot turn off wakeup power resources\n");
+		dev->wakeup.flags.valid = 0;
 	}
 
  out:




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v1 3/3] ACPI: PM: Turn off wakeup power resources on _DSW/_PSW errors
  2021-10-15 16:59 [PATCH v1 0/3] ACPI: PM: Address issues related to managing wakeup power resources Rafael J. Wysocki
  2021-10-15 17:01 ` [PATCH v1 1/3] ACPI: PM: Turn off unused " Rafael J. Wysocki
  2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
@ 2021-10-15 17:04 ` Rafael J. Wysocki
  2 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2021-10-15 17:04 UTC (permalink / raw)
  To: Linux ACPI; +Cc: Linux PM, LKML, Mika Westerberg, Linux PCI

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If acpi_device_sleep_wake() called by acpi_enable_wakeup_device_power()
returns an error which means that the evaluation of either _DWS or
_PSW has failed, turn off all of the device's wakeup power resources
to be consistent with the clearing of dev->wakeup.prepare_count.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/power.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -731,8 +731,10 @@ int acpi_enable_wakeup_device_power(stru
 	 * put into arbitrary power state afterward.
 	 */
 	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
-	if (err)
+	if (err) {
+		acpi_power_off_list(&dev->wakeup.resources);
 		dev->wakeup.prepare_count = 0;
+	}
 
  out:
 	mutex_unlock(&acpi_device_lock);




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
  2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
@ 2021-10-15 20:31     ` kernel test robot
  2021-10-16 10:11   ` [PATCH v2 " Rafael J. Wysocki
  2021-10-19  7:25     ` kernel test robot
  2 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-15 20:31 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: llvm, kbuild-all, Linux PM, LKML, Mika Westerberg, Linux PCI

[-- Attachment #1: Type: text/plain, Size: 6517 bytes --]

Hi "Rafael,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linux/master linus/master v5.15-rc5 next-20211015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: i386-randconfig-r035-20211015 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6069a6a5049497a32a50a49661c2f4169078bdba)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
        git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/acpi/power.c:719:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count++)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:739:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:719:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count++)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:712:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   drivers/acpi/power.c:764:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!dev->wakeup.prepare_count)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:764:2: note: remove the 'if' if its condition is always false
           if (!dev->wakeup.prepare_count)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:758:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count > 1) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:758:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count > 1) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:751:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   3 warnings generated.


vim +719 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703  
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713  
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08 @719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721  
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728  
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 39658 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
@ 2021-10-15 20:31     ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-15 20:31 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6631 bytes --]

Hi "Rafael,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linux/master linus/master v5.15-rc5 next-20211015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: i386-randconfig-r035-20211015 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6069a6a5049497a32a50a49661c2f4169078bdba)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
        git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/acpi/power.c:719:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count++)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:739:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:719:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count++)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:712:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   drivers/acpi/power.c:764:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!dev->wakeup.prepare_count)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:764:2: note: remove the 'if' if its condition is always false
           if (!dev->wakeup.prepare_count)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:758:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count > 1) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:758:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count > 1) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:751:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   3 warnings generated.


vim +719 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703  
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713  
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08 @719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721  
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728  
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 39658 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] ACPI: PM: Fix sharing of wakeup power resources
  2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
  2021-10-15 20:31     ` kernel test robot
@ 2021-10-16 10:11   ` Rafael J. Wysocki
  2021-10-19  7:25     ` kernel test robot
  2 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2021-10-16 10:11 UTC (permalink / raw)
  To: Linux ACPI; +Cc: Linux PM, LKML, Mika Westerberg, Linux PCI

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If an ACPI wakeup power resource is shared between multiple devices,
it may not be managed correctly.

Suppose, for example, that two devices, A and B, share a wakeup power
resource P whose wakeup_enabled flag is 0 initially.  Next, suppose
that wakeup power is enabled for A and B, in this order, and disabled
for B.  When wakeup power is enabled for A, P will be turned on and
its wakeup_enabled flag will be set.  Next, when wakeup power is
enabled for B, P will not be touched, because its wakeup_enabled flag
is set.  Now, when wakeup power is disabled for B, P will be turned
off which is incorrect, because A will still need P in order to signal
wakeup.

Moreover, if wakeup power is enabled for A and then disabled for B,
the latter will cause P to be turned off incorrectly (it will be still
needed by A), because acpi_disable_wakeup_device_power() is allowed
to manipulate power resources when the wakeup.prepare_count counter
of the given device is 0.

While the first issue could be addressed by changing the
wakeup_enabled power resource flag into a counter, addressing the
second one requires modifying acpi_disable_wakeup_device_power() to
do nothing when the target device's wakeup.prepare_count reference
counter is zero and that would cause the new counter to be redundant.
Namely, if acpi_disable_wakeup_device_power() is modified as per the
above, every change of the new counter following a wakeup.prepare_count
change would be reflected by the analogous change of the main reference
counter of the given power resource.

Accordingly, modify acpi_disable_wakeup_device_power() to do nothing
when the target device's wakeup.prepare_count reference counter is
zero and drop the power resource wakeup_enabled flag altogether.

While at it, ensure that all of the power resources that can be
turned off will be turned off when disabling device wakeup due to
a power resource manipulation error, to prevent energy from being
wasted.

Fixes: b5d667eb392e ("ACPI / PM: Take unusual configurations of power resources into account")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2:
   * Restore the initialization of err in two places removed by v1 by mistake.

---
 drivers/acpi/power.c |   69 +++++++++++++++++----------------------------------
 1 file changed, 24 insertions(+), 45 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -52,7 +52,6 @@ struct acpi_power_resource {
 	u32 order;
 	unsigned int ref_count;
 	u8 state;
-	bool wakeup_enabled;
 	struct mutex resource_lock;
 	struct list_head dependents;
 };
@@ -710,7 +709,6 @@ int acpi_device_sleep_wake(struct acpi_d
  */
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
 {
-	struct acpi_power_resource_entry *entry;
 	int err = 0;
 
 	if (!dev || !dev->wakeup.flags.valid)
@@ -721,26 +719,13 @@ int acpi_enable_wakeup_device_power(stru
 	if (dev->wakeup.prepare_count++)
 		goto out;
 
-	list_for_each_entry(entry, &dev->wakeup.resources, node) {
-		struct acpi_power_resource *resource = entry->resource;
-
-		mutex_lock(&resource->resource_lock);
-
-		if (!resource->wakeup_enabled) {
-			err = acpi_power_on_unlocked(resource);
-			if (!err)
-				resource->wakeup_enabled = true;
-		}
-
-		mutex_unlock(&resource->resource_lock);
-
-		if (err) {
-			dev_err(&dev->dev,
-				"Cannot turn wakeup power resources on\n");
-			dev->wakeup.flags.valid = 0;
-			goto out;
-		}
+	err = acpi_power_on_list(&dev->wakeup.resources);
+	if (err) {
+		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
+		dev->wakeup.flags.valid = 0;
+		goto out;
 	}
+
 	/*
 	 * Passing 3 as the third argument below means the device may be
 	 * put into arbitrary power state afterward.
@@ -770,39 +755,33 @@ int acpi_disable_wakeup_device_power(str
 
 	mutex_lock(&acpi_device_lock);
 
-	if (--dev->wakeup.prepare_count > 0)
+	if (dev->wakeup.prepare_count > 1) {
+		dev->wakeup.prepare_count--;
 		goto out;
+	}
 
-	/*
-	 * Executing the code below even if prepare_count is already zero when
-	 * the function is called may be useful, for example for initialisation.
-	 */
-	if (dev->wakeup.prepare_count < 0)
-		dev->wakeup.prepare_count = 0;
+	/* Do nothing if wakeup power has not been enabled for this device. */
+	if (!dev->wakeup.prepare_count)
+		goto out;
 
 	err = acpi_device_sleep_wake(dev, 0, 0, 0);
 	if (err)
 		goto out;
 
+	/*
+	 * All of the power resources in the list need to be turned off even if
+	 * there are errors.
+	 */
 	list_for_each_entry(entry, &dev->wakeup.resources, node) {
-		struct acpi_power_resource *resource = entry->resource;
-
-		mutex_lock(&resource->resource_lock);
-
-		if (resource->wakeup_enabled) {
-			err = acpi_power_off_unlocked(resource);
-			if (!err)
-				resource->wakeup_enabled = false;
-		}
-
-		mutex_unlock(&resource->resource_lock);
+		int ret;
 
-		if (err) {
-			dev_err(&dev->dev,
-				"Cannot turn wakeup power resources off\n");
-			dev->wakeup.flags.valid = 0;
-			break;
-		}
+		ret = acpi_power_off(entry->resource);
+		if (ret && !err)
+			err = ret;
+	}
+	if (err) {
+		dev_err(&dev->dev, "Cannot turn off wakeup power resources\n");
+		dev->wakeup.flags.valid = 0;
 	}
 
  out:





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
  2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
@ 2021-10-19  7:25     ` kernel test robot
  2021-10-16 10:11   ` [PATCH v2 " Rafael J. Wysocki
  2021-10-19  7:25     ` kernel test robot
  2 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-19  7:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: llvm, kbuild-all, Linux PM, LKML, Mika Westerberg, Linux PCI

[-- Attachment #1: Type: text/plain, Size: 6533 bytes --]

Hi "Rafael,

I love your patch! Yet something to improve:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on linux/master linus/master v5.15-rc6 next-20211018]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: i386-buildonly-randconfig-r003-20211019 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project d245f2e8597bfb52c34810a328d42b990e4af1a4)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
        git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/acpi/power.c:719:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count++)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:739:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:719:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count++)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:712:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   drivers/acpi/power.c:764:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (!dev->wakeup.prepare_count)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:764:2: note: remove the 'if' if its condition is always false
           if (!dev->wakeup.prepare_count)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:758:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count > 1) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:758:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count > 1) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:751:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   3 errors generated.


vim +719 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703  
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713  
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08 @719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721  
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728  
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 40054 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
@ 2021-10-19  7:25     ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-19  7:25 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6647 bytes --]

Hi "Rafael,

I love your patch! Yet something to improve:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on linux/master linus/master v5.15-rc6 next-20211018]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: i386-buildonly-randconfig-r003-20211019 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project d245f2e8597bfb52c34810a328d42b990e4af1a4)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
        git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/acpi/power.c:719:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count++)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:739:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:719:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count++)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:712:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   drivers/acpi/power.c:764:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (!dev->wakeup.prepare_count)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:764:2: note: remove the 'if' if its condition is always false
           if (!dev->wakeup.prepare_count)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:758:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (dev->wakeup.prepare_count > 1) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:789:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/acpi/power.c:758:2: note: remove the 'if' if its condition is always false
           if (dev->wakeup.prepare_count > 1) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:751:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
   3 errors generated.


vim +719 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703  
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713  
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08 @719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721  
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728  
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 40054 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
  2021-10-17  7:09 [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources kernel test robot
@ 2021-10-19  7:29   ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-19  7:29 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: llvm, kbuild-all, Linux PM, LKML, Mika Westerberg, Linux PCI

[-- Attachment #1: Type: text/plain, Size: 5962 bytes --]

Hi Rafael,

Thanks for your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linux/master linus/master v5.15-rc5 next-20211015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: x86_64-randconfig-c007-20211015 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6069a6a5049497a32a50a49661c2f4169078bdba)
reproduce (this is a W=1 build):
         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
         chmod +x ~/bin/make.cross
         # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
         git remote add linux-review https://github.com/0day-ci/linux
         git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
         git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
         # save the attached .config to linux build tree
         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings:

 >> drivers/acpi/power.c:739:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
            return err;
            ^      ~~~
    drivers/acpi/power.c:712:2: note: 'err' declared without an initial value
            int err;
            ^~~~~~~
    drivers/acpi/power.c:714:6: note: Assuming 'dev' is non-null
            if (!dev || !dev->wakeup.flags.valid)
                ^~~~
    drivers/acpi/power.c:714:6: note: Left side of '||' is false
    drivers/acpi/power.c:714:14: note: Assuming field 'valid' is not equal to 0
            if (!dev || !dev->wakeup.flags.valid)
                        ^~~~~~~~~~~~~~~~~~~~~~~~
    drivers/acpi/power.c:714:2: note: Taking false branch
            if (!dev || !dev->wakeup.flags.valid)
            ^
    drivers/acpi/power.c:719:6: note: Assuming the condition is true
            if (dev->wakeup.prepare_count++)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/acpi/power.c:719:2: note: Taking true branch
            if (dev->wakeup.prepare_count++)
            ^
    drivers/acpi/power.c:720:3: note: Control jumps to line 738
                    goto out;
                    ^
    drivers/acpi/power.c:739:2: note: Undefined or garbage value returned to caller
            return err;
            ^      ~~~


vim +739 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07 @739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34215 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
@ 2021-10-19  7:29   ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2021-10-19  7:29 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6070 bytes --]

Hi Rafael,

Thanks for your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linux/master linus/master v5.15-rc5 next-20211015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: x86_64-randconfig-c007-20211015 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6069a6a5049497a32a50a49661c2f4169078bdba)
reproduce (this is a W=1 build):
         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
         chmod +x ~/bin/make.cross
         # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
         git remote add linux-review https://github.com/0day-ci/linux
         git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
         git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
         # save the attached .config to linux build tree
         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings:

 >> drivers/acpi/power.c:739:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
            return err;
            ^      ~~~
    drivers/acpi/power.c:712:2: note: 'err' declared without an initial value
            int err;
            ^~~~~~~
    drivers/acpi/power.c:714:6: note: Assuming 'dev' is non-null
            if (!dev || !dev->wakeup.flags.valid)
                ^~~~
    drivers/acpi/power.c:714:6: note: Left side of '||' is false
    drivers/acpi/power.c:714:14: note: Assuming field 'valid' is not equal to 0
            if (!dev || !dev->wakeup.flags.valid)
                        ^~~~~~~~~~~~~~~~~~~~~~~~
    drivers/acpi/power.c:714:2: note: Taking false branch
            if (!dev || !dev->wakeup.flags.valid)
            ^
    drivers/acpi/power.c:719:6: note: Assuming the condition is true
            if (dev->wakeup.prepare_count++)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/acpi/power.c:719:2: note: Taking true branch
            if (dev->wakeup.prepare_count++)
            ^
    drivers/acpi/power.c:720:3: note: Control jumps to line 738
                    goto out;
                    ^
    drivers/acpi/power.c:739:2: note: Undefined or garbage value returned to caller
            return err;
            ^      ~~~


vim +739 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07 @739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34215 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources
@ 2021-10-17  7:09 kernel test robot
  2021-10-19  7:29   ` kernel test robot
  0 siblings, 1 reply; 12+ messages in thread
From: kernel test robot @ 2021-10-17  7:09 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 18460 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
In-Reply-To: <2077987.irdbgypaU6@kreacher>
References: <2077987.irdbgypaU6@kreacher>
TO: "Rafael J. Wysocki" <rjw@rjwysocki.net>
TO: Linux ACPI <linux-acpi@vger.kernel.org>
CC: Linux PM <linux-pm@vger.kernel.org>
CC: LKML <linux-kernel@vger.kernel.org>
CC: Mika Westerberg <mika.westerberg@linux.intel.com>
CC: Linux PCI <linux-pci@vger.kernel.org>

Hi "Rafael,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on linux/master linus/master v5.15-rc5 next-20211015]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-c007-20211015 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6069a6a5049497a32a50a49661c2f4169078bdba)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Rafael-J-Wysocki/ACPI-PM-Address-issues-related-to-managing-wakeup-power-resources/20211016-010527
        git checkout 5e93f177b80cbc9b9ee6ffc15ff9ad0ad23f2a7a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/dma-buf/dma-resv.c:431:7: note: Assuming 'fence_excl' is non-null
                   if (fence_excl && !dma_fence_get_rcu(fence_excl))
                       ^~~~~~~~~~
   drivers/dma-buf/dma-resv.c:431:7: note: Left side of '&&' is true
   drivers/dma-buf/dma-resv.c:431:3: note: Taking false branch
                   if (fence_excl && !dma_fence_get_rcu(fence_excl))
                   ^
   drivers/dma-buf/dma-resv.c:435:7: note: Assuming 'fobj' is non-null
                   if (fobj)
                       ^~~~
   drivers/dma-buf/dma-resv.c:435:3: note: Taking true branch
                   if (fobj)
                   ^
   drivers/dma-buf/dma-resv.c:438:7: note: Assuming 'pfence_excl' is null
                   if (!pfence_excl && fence_excl)
                       ^~~~~~~~~~~~
   drivers/dma-buf/dma-resv.c:438:7: note: Left side of '&&' is true
   drivers/dma-buf/dma-resv.c:438:23: note: 'fence_excl' is non-null
                   if (!pfence_excl && fence_excl)
                                       ^~~~~~~~~~
   drivers/dma-buf/dma-resv.c:438:3: note: Taking true branch
                   if (!pfence_excl && fence_excl)
                   ^
   drivers/dma-buf/dma-resv.c:441:7: note: Assuming 'sz' is 0
                   if (sz) {
                       ^~
   drivers/dma-buf/dma-resv.c:441:3: note: Taking false branch
                   if (sz) {
                   ^
   drivers/dma-buf/dma-resv.c:470:7: note: 'i' is equal to 'shared_count'
                   if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) {
                       ^
   drivers/dma-buf/dma-resv.c:470:7: note: Left side of '||' is false
   drivers/dma-buf/dma-resv.c:470:3: note: Taking false branch
                   if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) {
                   ^
   drivers/dma-buf/dma-resv.c:420:2: note: Loop condition is false.  Exiting loop
           do {
           ^
   drivers/dma-buf/dma-resv.c:482:6: note: 'pfence_excl' is null
           if (pfence_excl)
               ^~~~~~~~~~~
   drivers/dma-buf/dma-resv.c:482:2: note: Taking false branch
           if (pfence_excl)
           ^
   drivers/dma-buf/dma-resv.c:484:11: note: 'fence_excl' is non-null
           else if (fence_excl)
                    ^~~~~~~~~~
   drivers/dma-buf/dma-resv.c:484:7: note: Taking true branch
           else if (fence_excl)
                ^
   drivers/dma-buf/dma-resv.c:485:26: note: Array access (from variable 'shared') results in a null pointer dereference
                   shared[shared_count++] = fence_excl;
                   ~~~~~~                 ^
   Suppressed 2 warnings (2 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   drivers/acpi/pci_link.c:88:14: warning: Value stored to 'handle' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
           acpi_handle handle = link->device->handle;
                       ^~~~~~   ~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/pci_link.c:88:14: note: Value stored to 'handle' during its initialization is never read
           acpi_handle handle = link->device->handle;
                       ^~~~~~   ~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/pci_link.c:721:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/pci_link.c:721:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/pci_link.c:722:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
           ^~~~~~
   drivers/acpi/pci_link.c:722:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
           ^~~~~~
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   drivers/acpi/pci_irq.c:131:4: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
                           strcpy(prt->source, quirk->actual_source);
                           ^~~~~~
   drivers/acpi/pci_irq.c:131:4: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
                           strcpy(prt->source, quirk->actual_source);
                           ^~~~~~
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   10 warnings generated.
>> drivers/acpi/power.c:739:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
           return err;
           ^      ~~~
   drivers/acpi/power.c:712:2: note: 'err' declared without an initial value
           int err;
           ^~~~~~~
   drivers/acpi/power.c:714:6: note: Assuming 'dev' is non-null
           if (!dev || !dev->wakeup.flags.valid)
               ^~~~
   drivers/acpi/power.c:714:6: note: Left side of '||' is false
   drivers/acpi/power.c:714:14: note: Assuming field 'valid' is not equal to 0
           if (!dev || !dev->wakeup.flags.valid)
                       ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:714:2: note: Taking false branch
           if (!dev || !dev->wakeup.flags.valid)
           ^
   drivers/acpi/power.c:719:6: note: Assuming the condition is true
           if (dev->wakeup.prepare_count++)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:719:2: note: Taking true branch
           if (dev->wakeup.prepare_count++)
           ^
   drivers/acpi/power.c:720:3: note: Control jumps to line 738
                   goto out;
                   ^
   drivers/acpi/power.c:739:2: note: Undefined or garbage value returned to caller
           return err;
           ^      ~~~
   drivers/acpi/power.c:789:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
           return err;
           ^      ~~~
   drivers/acpi/power.c:751:2: note: 'err' declared without an initial value
           int err;
           ^~~~~~~
   drivers/acpi/power.c:753:6: note: Assuming 'dev' is non-null
           if (!dev || !dev->wakeup.flags.valid)
               ^~~~
   drivers/acpi/power.c:753:6: note: Left side of '||' is false
   drivers/acpi/power.c:753:14: note: Assuming field 'valid' is not equal to 0
           if (!dev || !dev->wakeup.flags.valid)
                       ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:753:2: note: Taking false branch
           if (!dev || !dev->wakeup.flags.valid)
           ^
   drivers/acpi/power.c:758:6: note: Assuming field 'prepare_count' is <= 1
           if (dev->wakeup.prepare_count > 1) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:758:2: note: Taking false branch
           if (dev->wakeup.prepare_count > 1) {
           ^
   drivers/acpi/power.c:764:6: note: Assuming field 'prepare_count' is 0
           if (!dev->wakeup.prepare_count)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/power.c:764:2: note: Taking true branch
           if (!dev->wakeup.prepare_count)
           ^
   drivers/acpi/power.c:765:3: note: Control jumps to line 788
                   goto out;
                   ^
   drivers/acpi/power.c:789:2: note: Undefined or garbage value returned to caller
           return err;
           ^      ~~~
   drivers/acpi/power.c:939:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/power.c:939:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
           ^~~~~~
   drivers/acpi/power.c:940:2: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
           ^~~~~~
   drivers/acpi/power.c:940:2: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
           strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
           ^~~~~~
   Suppressed 6 warnings (3 in non-user code, 3 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   drivers/rtc/rtc-ds3232.c:380:17: warning: Value stored to 'ds3232' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
           struct ds3232 *ds3232 = dev_get_drvdata(dev);
                          ^~~~~~   ~~~~~~~~~~~~~~~~~~~~
   drivers/rtc/rtc-ds3232.c:380:17: note: Value stored to 'ds3232' during its initialization is never read
           struct ds3232 *ds3232 = dev_get_drvdata(dev);
                          ^~~~~~   ~~~~~~~~~~~~~~~~~~~~
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.

vim +739 drivers/acpi/power.c

77e766099efc29 Rafael J. Wysocki 2008-07-07  703  
^1da177e4c3f41 Linus Torvalds    2005-04-16  704  /*
^1da177e4c3f41 Linus Torvalds    2005-04-16  705   * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
^1da177e4c3f41 Linus Torvalds    2005-04-16  706   * 1. Power on the power resources required for the wakeup device
77e766099efc29 Rafael J. Wysocki 2008-07-07  707   * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
77e766099efc29 Rafael J. Wysocki 2008-07-07  708   *    State Wake) for the device, if present
^1da177e4c3f41 Linus Torvalds    2005-04-16  709   */
77e766099efc29 Rafael J. Wysocki 2008-07-07  710  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
^1da177e4c3f41 Linus Torvalds    2005-04-16  711  {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  712  	int err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  713  
^1da177e4c3f41 Linus Torvalds    2005-04-16  714  	if (!dev || !dev->wakeup.flags.valid)
77e766099efc29 Rafael J. Wysocki 2008-07-07  715  		return -EINVAL;
^1da177e4c3f41 Linus Torvalds    2005-04-16  716  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  717  	mutex_lock(&acpi_device_lock);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  718  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  719  	if (dev->wakeup.prepare_count++)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  720  		goto out;
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  721  
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  722  	err = acpi_power_on_list(&dev->wakeup.resources);
993cbe595dda73 Rafael J. Wysocki 2013-01-17  723  	if (err) {
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  724  		dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  725  		dev->wakeup.flags.valid = 0;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  726  		goto out;
b5d667eb392ed9 Rafael J. Wysocki 2013-02-23  727  	}
5e93f177b80cbc Rafael J. Wysocki 2021-10-15  728  
77e766099efc29 Rafael J. Wysocki 2008-07-07  729  	/*
993cbe595dda73 Rafael J. Wysocki 2013-01-17  730  	 * Passing 3 as the third argument below means the device may be
993cbe595dda73 Rafael J. Wysocki 2013-01-17  731  	 * put into arbitrary power state afterward.
77e766099efc29 Rafael J. Wysocki 2008-07-07  732  	 */
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07  733  	err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  734  	if (err)
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  735  		dev->wakeup.prepare_count = 0;
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  736  
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  737   out:
9b83ccd2f14f64 Rafael J. Wysocki 2009-09-08  738  	mutex_unlock(&acpi_device_lock);
0af4b8c4fb3119 Rafael J. Wysocki 2008-07-07 @739  	return err;
^1da177e4c3f41 Linus Torvalds    2005-04-16  740  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  741  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34215 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-10-19  7:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 16:59 [PATCH v1 0/3] ACPI: PM: Address issues related to managing wakeup power resources Rafael J. Wysocki
2021-10-15 17:01 ` [PATCH v1 1/3] ACPI: PM: Turn off unused " Rafael J. Wysocki
2021-10-15 17:03 ` [PATCH v1 2/3] ACPI: PM: Fix sharing of " Rafael J. Wysocki
2021-10-15 20:31   ` kernel test robot
2021-10-15 20:31     ` kernel test robot
2021-10-16 10:11   ` [PATCH v2 " Rafael J. Wysocki
2021-10-19  7:25   ` [PATCH v1 " kernel test robot
2021-10-19  7:25     ` kernel test robot
2021-10-15 17:04 ` [PATCH v1 3/3] ACPI: PM: Turn off wakeup power resources on _DSW/_PSW errors Rafael J. Wysocki
2021-10-17  7:09 [PATCH v1 2/3] ACPI: PM: Fix sharing of wakeup power resources kernel test robot
2021-10-19  7:29 ` kernel test robot
2021-10-19  7:29   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.