Re: [PATCH v4] drm/amd/pm: Use guard(mutex) instead of manual lock+unlock
Hi Andre, kernel test robot noticed the following build errors: [auto build test ERROR on drm-misc/drm-misc-next] [also build test ERROR on linus/master v7.1-rc3 next-20260508] [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#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Andre-Jun-Hirata/drm-amd-pm-Use-guard-mutex-instead-of-manual-lock-unlock/20260513-062000 base: https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next patch link: https://lore.kernel.org/r/20260508172345.6680-1-andrejhirata%40usp.br patch subject: [PATCH v4] drm/amd/pm: Use guard(mutex) instead of manual lock+unlock config: x86_64-randconfig-072-20260513 (https://download.01.org/0day-ci/archive/20260513/[email protected]/config) compiler: gcc-12 (Debian 12.4.0-5) 12.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260513/[email protected]/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ All error/warnings (new ones prefixed by >>): drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_is_mode1_reset_supported': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:247:47: error: expected ';' before '}' token 247 | return smu_mode1_reset_is_support(smu) | ^ | ; 248 | } | ~ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_smu_i2c_bus_access': >> drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:405:16: error: expected >> expression before '=' token 405 | return = pp_funcs->smu_i2c_bus_access(pp_handle, |^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_get_vce_clock_state': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:833:31: warning: unused variable 'vstate' [-Wunused-variable] 833 | struct amd_vce_state *vstate = NULL; | ^~ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_get_pp_table': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1016:16: error: expected expression before '=' token 1016 | return = pp_funcs->get_pp_table(adev->powerplay.pp_handle, |^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_set_fine_grain_clk_vol': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1031:16: error: expected expression before '=' token 1031 | return = pp_funcs->set_fine_grain_clk_vol(adev->powerplay.pp_handle, |^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_get_display_mode_validation_clks': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1498:16: error: expected expression before '=' token 1498 | return = pp_funcs->get_display_mode_validation_clocks(adev->powerplay.pp_handle, |^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_smu_i2c_bus_access': >> drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:407:1: warning: control >> reaches end of non-void function [-Wreturn-type] 407 | } | ^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_get_pp_table': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1018:1: warning: control reaches end of non-void function [-Wreturn-type] 1018 | } | ^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_set_fine_grain_clk_vol': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1035:1: warning: control reaches end of non-void function [-Wreturn-type] 1035 | } | ^ drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c: In function 'amdgpu_dpm_get_display_mode_validation_clks': drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c:1500:1: warning: control reaches end of non-void function [-Wreturn-type] 1500 | } | ^ vim +405 drivers/gpu/drm/amd/amdgpu/../pm/amdgpu_dpm.c 393 394 int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, 395bool acquire) 396 { 397 void *pp_handle = adev->powerplay.pp_handle; 398 const struct amd_pm_funcs *pp_funcs = 399
[PATCH v4] drm/amd/pm: Use guard(mutex) instead of manual lock+unlock
Use guard() and scoped_guard() for handling mutex lock instead of
manually locking and unlocking the mutex. This prevents forgotten
locks due to early exits and removes the need of gotos.
Signed-off-by: Andre Jun Hirata
Co-developed-by: Gabriel Dimant
Signed-off-by: Gabriel Dimant
Co-developed-by: Guilherme Gabriel
Signed-off-by: Guilherme Gabriel
Reviewed-by: Christian König
---
v2: incorporate Christian König's suggestions:
- use return f() directly instead of ret = f(); return ret;
- use early return pattern before guard() where applicable
v3: fix style nits pointed by Christian König:
- drop superfluous ret initialization in set_gfx_power_up_by_imu
- drop unnecessary braces around single-line scoped_guard
v4:
- fix build errors introduced in v3
- fix incorrect is_support_sw_smu() condition
- remove accidental "return =" typos
drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 868 +---
1 file changed, 261 insertions(+), 607 deletions(-)
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index feadf604b..2a0f4abc4 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -30,6 +30,7 @@
#include "amd_pcie.h"
#include "amdgpu_display.h"
#include "hwmgr.h"
+#include
#include
#include "amdgpu_smu.h"
@@ -41,33 +42,25 @@
int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low)
{
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
- int ret = 0;
if (!pp_funcs->get_sclk)
return 0;
- mutex_lock(&adev->pm.mutex);
- ret = pp_funcs->get_sclk((adev)->powerplay.pp_handle,
+ guard(mutex)(&adev->pm.mutex);
+ return pp_funcs->get_sclk((adev)->powerplay.pp_handle,
low);
- mutex_unlock(&adev->pm.mutex);
-
- return ret;
}
int amdgpu_dpm_get_mclk(struct amdgpu_device *adev, bool low)
{
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
- int ret = 0;
if (!pp_funcs->get_mclk)
return 0;
- mutex_lock(&adev->pm.mutex);
- ret = pp_funcs->get_mclk((adev)->powerplay.pp_handle,
+ guard(mutex)(&adev->pm.mutex);
+ return pp_funcs->get_mclk((adev)->powerplay.pp_handle,
low);
- mutex_unlock(&adev->pm.mutex);
-
- return ret;
}
int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
@@ -80,13 +73,12 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device
*adev,
enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
- mutex_lock(&adev->pm.mutex);
-
+ guard(mutex)(&adev->pm.mutex);
if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
dev_dbg(adev->dev, "IP block%d already in the target %s state!",
block_type, gate ? "gate" : "ungate");
- goto out_unlock;
+ return ret;
}
switch (block_type) {
@@ -115,9 +107,6 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device
*adev,
if (!ret)
atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
-out_unlock:
- mutex_unlock(&adev->pm.mutex);
-
return ret;
}
@@ -126,9 +115,8 @@ int amdgpu_dpm_set_gfx_power_up_by_imu(struct amdgpu_device
*adev)
struct smu_context *smu = adev->powerplay.pp_handle;
int ret = -EOPNOTSUPP;
- mutex_lock(&adev->pm.mutex);
- ret = smu_set_gfx_power_up_by_imu(smu);
- mutex_unlock(&adev->pm.mutex);
+ scoped_guard(mutex, &adev->pm.mutex)
+ ret = smu_set_gfx_power_up_by_imu(smu);
msleep(10);
@@ -139,44 +127,31 @@ int amdgpu_dpm_baco_enter(struct amdgpu_device *adev)
{
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
void *pp_handle = adev->powerplay.pp_handle;
- int ret = 0;
if (!pp_funcs || !pp_funcs->set_asic_baco_state)
return -ENOENT;
- mutex_lock(&adev->pm.mutex);
-
+ guard(mutex)(&adev->pm.mutex);
/* enter BACO state */
- ret = pp_funcs->set_asic_baco_state(pp_handle, 1);
-
- mutex_unlock(&adev->pm.mutex);
-
- return ret;
+ return pp_funcs->set_asic_baco_state(pp_handle, 1);
}
int amdgpu_dpm_baco_exit(struct amdgpu_device *adev)
{
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
void *pp_handle = adev->powerplay.pp_handle;
- int ret = 0;
if (!pp_funcs || !pp_funcs->set_asic_baco_state)
return -ENOENT;
- mutex_lock(&adev->pm.mutex);
-
+ guard(mutex)(&adev->pm.mutex);
/* exit BACO state */
- ret = pp_funcs->set_asic_baco_state(pp_handle, 0);
-
- mutex_unlock(&adev->pm.mutex);
-
-
