[PATCH] drm/amd: remove possible condition with no effect (if == else)

2022-08-23 Thread Bernard Zhao
This patch fix cocci warning:
drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c:1816:6-8:
WARNING: possible condition with no effect (if == else).

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
index 85f32206a766..dccc9794e6a2 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
@@ -1813,8 +1813,6 @@ static bool dcn314_resource_construct(
 
if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
dc->debug = debug_defaults_drv;
-   else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS)
-   dc->debug = debug_defaults_diags;
else
dc->debug = debug_defaults_diags;
// Init the vm_helper
-- 
2.33.1



[PATCH] drm/amd: remove duplicated argument to &

2022-08-23 Thread Bernard Zhao
This patch trf to fis cocci warning:
drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c:
2349:8-34: duplicated argument to && or ||
drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c:
3680:8-55: duplicated argument to && or ||

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
index cb2025771646..fa26834daf56 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
@@ -2346,8 +2346,7 @@ void dml32_ModeSupportAndSystemConfigurationFull(struct 
display_mode_lib *mode_l
 
if (mode_lib->vba.DSCEnable[k] && 
mode_lib->vba.ForcedOutputLinkBPP[k] != 0)
mode_lib->vba.DSCOnlyIfNecessaryWithBPP = true;
-   if ((mode_lib->vba.DSCEnable[k] || 
mode_lib->vba.DSCEnable[k])
-   && mode_lib->vba.OutputFormat[k] == 
dm_n422
+   if (mode_lib->vba.DSCEnable[k] && 
mode_lib->vba.OutputFormat[k] == dm_n422
&& !mode_lib->vba.DSC422NativeSupport)
mode_lib->vba.DSC422NativeNotSupported = true;
 
-- 
2.33.1



[PATCH] drm/amd: fix potential memory leak

2022-08-23 Thread Bernard Zhao
This patch fix potential memory leak (clk_src) when function run
into last return NULL.
Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
index 85f32206a766..c7bb76a2a8c2 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
@@ -1643,6 +1643,7 @@ static struct clock_source *dcn31_clock_source_create(
}
 
BREAK_TO_DEBUGGER();
+   kfree(clk_src);
return NULL;
 }
 
-- 
2.33.1



[PATCH v2] drm/amd: remove duplicated argument to &

2022-08-23 Thread Bernard Zhao
This patch trf to fis cocci warning:
drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c:
2349:8-34: duplicated argument to && or ||
drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c:
3680:8-55: duplicated argument to && or ||

Signed-off-by: Bernard Zhao 
---
 .../gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c| 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
index cb2025771646..f99c1696a1f6 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
@@ -2346,8 +2346,7 @@ void dml32_ModeSupportAndSystemConfigurationFull(struct 
display_mode_lib *mode_l
 
if (mode_lib->vba.DSCEnable[k] && 
mode_lib->vba.ForcedOutputLinkBPP[k] != 0)
mode_lib->vba.DSCOnlyIfNecessaryWithBPP = true;
-   if ((mode_lib->vba.DSCEnable[k] || 
mode_lib->vba.DSCEnable[k])
-   && mode_lib->vba.OutputFormat[k] == 
dm_n422
+   if (mode_lib->vba.DSCEnable[k] && 
mode_lib->vba.OutputFormat[k] == dm_n422
&& !mode_lib->vba.DSC422NativeSupport)
mode_lib->vba.DSC422NativeNotSupported = true;
 
@@ -3678,7 +3677,6 @@ void dml32_ModeSupportAndSystemConfigurationFull(struct 
display_mode_lib *mode_l
if (mode_lib->vba.SourcePixelFormat[k] != dm_444_64
&& mode_lib->vba.SourcePixelFormat[k] 
!= dm_444_32
&& mode_lib->vba.SourcePixelFormat[k] 
!= dm_444_16
-   && mode_lib->vba.SourcePixelFormat[k] 
!= dm_444_16
&& mode_lib->vba.SourcePixelFormat[k] 
!= dm_444_8
&& mode_lib->vba.SourcePixelFormat[k] 
!= dm_rgbe) {
if (mode_lib->vba.ViewportWidthChroma[k] > 
mode_lib->vba.SurfaceWidthC[k]
-- 
2.33.1



[PATCH] drm/amd: fix potential memory leak

2022-08-23 Thread Bernard Zhao
This patch fix potential memory leak (clk_src) when function run
into last return NULL.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
index 85f32206a766..76f263846c6b 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn314/dcn314_resource.c
@@ -1715,6 +1715,7 @@ static struct clock_source *dcn30_clock_source_create(
}
 
BREAK_TO_DEBUGGER();
+   free(clk_src);
return NULL;
 }
 
-- 
2.33.1



[PATCH] drm/amd: remove possible condition with no effect (if == else)

2022-08-23 Thread Bernard Zhao
This patch fix cocci warning:
drivers/gpu/drm/amd/display/dc/core/dc.c:3335:2-4: WARNING:
possible condition with no effect (if == else).

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index aeecca68dea7..2d4c44083d79 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -3332,13 +3332,8 @@ static void commit_planes_for_stream(struct dc *dc,
/* Since phantom pipe programming is moved to 
post_unlock_program_front_end,
 * move the SubVP lock to after the phantom pipes have been 
setup
 */
-   if (should_lock_all_pipes && 
dc->hwss.interdependent_update_lock) {
-   if (dc->hwss.subvp_pipe_control_lock)
-   dc->hwss.subvp_pipe_control_lock(dc, context, 
false, should_lock_all_pipes, NULL, subvp_prev_use);
-   } else {
-   if (dc->hwss.subvp_pipe_control_lock)
-   dc->hwss.subvp_pipe_control_lock(dc, context, 
false, should_lock_all_pipes, NULL, subvp_prev_use);
-   }
+   if (dc->hwss.subvp_pipe_control_lock)
+   dc->hwss.subvp_pipe_control_lock(dc, context, false, 
should_lock_all_pipes, NULL, subvp_prev_use);
return;
}
 
-- 
2.33.1



[PATCH] drm/amd/display: remove no need NULL check before kfree

2021-11-16 Thread Bernard Zhao
This change is to cleanup the code a bit.

Signed-off-by: Bernard Zhao 
---
 .../drm/amd/display/dc/dcn10/dcn10_resource.c  | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
index f37551e00023..0090550d4aee 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
@@ -978,10 +978,8 @@ static void dcn10_resource_destruct(struct 
dcn10_resource_pool *pool)
pool->base.mpc = NULL;
}
 
-   if (pool->base.hubbub != NULL) {
-   kfree(pool->base.hubbub);
-   pool->base.hubbub = NULL;
-   }
+   kfree(pool->base.hubbub);
+   pool->base.hubbub = NULL;
 
for (i = 0; i < pool->base.pipe_count; i++) {
if (pool->base.opps[i] != NULL)
@@ -1011,14 +1009,10 @@ static void dcn10_resource_destruct(struct 
dcn10_resource_pool *pool)
for (i = 0; i < pool->base.res_cap->num_ddc; i++) {
if (pool->base.engines[i] != NULL)
dce110_engine_destroy(>base.engines[i]);
-   if (pool->base.hw_i2cs[i] != NULL) {
-   kfree(pool->base.hw_i2cs[i]);
-   pool->base.hw_i2cs[i] = NULL;
-   }
-   if (pool->base.sw_i2cs[i] != NULL) {
-   kfree(pool->base.sw_i2cs[i]);
-   pool->base.sw_i2cs[i] = NULL;
-   }
+   kfree(pool->base.hw_i2cs[i]);
+   pool->base.hw_i2cs[i] = NULL;
+   kfree(pool->base.sw_i2cs[i]);
+   pool->base.sw_i2cs[i] = NULL;
}
 
for (i = 0; i < pool->base.audio_count; i++) {
-- 
2.33.1



[PATCH] drm/amd/display: cleanup the code a bit

2021-11-16 Thread Bernard Zhao
In function dc_sink_destruct, kfree will check pointer, no need
to check again.
This change is to cleanup the code a bit.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc_sink.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_sink.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
index a249a0e5edd0..4b5e4d8e7735 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_sink.c
@@ -33,14 +33,6 @@
  * Private functions
  
**/
 
-static void dc_sink_destruct(struct dc_sink *sink)
-{
-   if (sink->dc_container_id) {
-   kfree(sink->dc_container_id);
-   sink->dc_container_id = NULL;
-   }
-}
-
 static bool dc_sink_construct(struct dc_sink *sink, const struct 
dc_sink_init_data *init_params)
 {
 
@@ -75,7 +67,7 @@ void dc_sink_retain(struct dc_sink *sink)
 static void dc_sink_free(struct kref *kref)
 {
struct dc_sink *sink = container_of(kref, struct dc_sink, refcount);
-   dc_sink_destruct(sink);
+   kfree(sink->dc_container_id);
kfree(sink);
 }
 
-- 
2.33.1



[PATCH v2] drm/amd/amdgpu: cleanup the code style a bit

2021-11-15 Thread Bernard Zhao
This change is to cleanup the code style a bit.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 04cf9b207e62..3fc49823f527 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -283,17 +283,15 @@ static int amdgpu_virt_init_ras_err_handler_data(struct 
amdgpu_device *adev)
 
*data = kmalloc(sizeof(struct amdgpu_virt_ras_err_handler_data), 
GFP_KERNEL);
if (!*data)
-   return -ENOMEM;
+   goto data_failure;
 
bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
-   bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), 
GFP_KERNEL);
+   if (!bps)
+   goto bps_failure;
 
-   if (!bps || !bps_bo) {
-   kfree(bps);
-   kfree(bps_bo);
-   kfree(*data);
-   return -ENOMEM;
-   }
+   bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), 
GFP_KERNEL);
+   if (!bps_bo)
+   goto bps_bo_failure;
 
(*data)->bps = bps;
(*data)->bps_bo = bps_bo;
@@ -303,6 +301,13 @@ static int amdgpu_virt_init_ras_err_handler_data(struct 
amdgpu_device *adev)
virt->ras_init_done = true;
 
return 0;
+
+bps_bo_failure:
+   kfree(bps);
+bps_failure:
+   kfree(*data);
+data_failure:
+   return -ENOMEM;
 }
 
 static void amdgpu_virt_ras_release_bp(struct amdgpu_device *adev)
-- 
2.33.1



[PATCH] drm/amd/amdgpu: remove useless break after return

2021-11-15 Thread Bernard Zhao
This change is to remove useless break after return.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index b200b9e722d9..8318ee8339f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -2092,22 +2092,18 @@ static int dce_v8_0_pick_dig_encoder(struct drm_encoder 
*encoder)
return 1;
else
return 0;
-   break;
case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
if (dig->linkb)
return 3;
else
return 2;
-   break;
case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
if (dig->linkb)
return 5;
else
return 4;
-   break;
case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
return 6;
-   break;
default:
DRM_ERROR("invalid encoder_id: 0x%x\n", 
amdgpu_encoder->encoder_id);
return 0;
-- 
2.33.1



[PATCH] drm/amd/amdgpu: cleanup the code style a bit

2021-11-15 Thread Bernard Zhao
This change is to cleanup the code style a bit.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 04cf9b207e62..90070b41136a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -286,12 +286,14 @@ static int amdgpu_virt_init_ras_err_handler_data(struct 
amdgpu_device *adev)
return -ENOMEM;
 
bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+   if (!bps) {
+   kfree(*data);
+   return -ENOMEM;
+   }
bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), 
GFP_KERNEL);
-
-   if (!bps || !bps_bo) {
-   kfree(bps);
-   kfree(bps_bo);
+   if (!bps_bo) {
kfree(*data);
+   kfree(bps);
return -ENOMEM;
}
 
-- 
2.33.1



[PATCH] drm/amd/amdgpu: fix potential memleak

2021-11-15 Thread Bernard Zhao
In function amdgpu_get_xgmi_hive, when kobject_init_and_add failed
There is a potential memleak if not call kobject_put.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
index 0fad2bf854ae..567df2db23ac 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
@@ -386,6 +386,7 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct 
amdgpu_device *adev)
"%s", "xgmi_hive_info");
if (ret) {
dev_err(adev->dev, "XGMI: failed initializing kobject for xgmi 
hive\n");
+   kobject_put(>kobj);
kfree(hive);
hive = NULL;
goto pro_end;
-- 
2.33.1



[PATCH] drm/radeon: delete useless function return values & remove meaningless if(r) check code

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
the function type maybe coule be changed to void.
This patch first delete the check of the return
value of the function call radeon_fence_driver_init, then,
optimise the function declaration and function to void type.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/cik.c  | 4 +---
 drivers/gpu/drm/radeon/evergreen.c| 4 +---
 drivers/gpu/drm/radeon/ni.c   | 4 +---
 drivers/gpu/drm/radeon/r100.c | 4 +---
 drivers/gpu/drm/radeon/r300.c | 4 +---
 drivers/gpu/drm/radeon/r420.c | 5 +
 drivers/gpu/drm/radeon/r520.c | 4 +---
 drivers/gpu/drm/radeon/r600.c | 4 +---
 drivers/gpu/drm/radeon/radeon.h   | 2 +-
 drivers/gpu/drm/radeon/radeon_fence.c | 5 +
 drivers/gpu/drm/radeon/rs400.c| 4 +---
 drivers/gpu/drm/radeon/rs600.c| 4 +---
 drivers/gpu/drm/radeon/rs690.c| 4 +---
 drivers/gpu/drm/radeon/rv515.c| 4 +---
 drivers/gpu/drm/radeon/rv770.c| 4 +---
 drivers/gpu/drm/radeon/si.c   | 4 +---
 16 files changed, 16 insertions(+), 48 deletions(-)

diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index 42a8afa839cb..f6cf0b8fdd83 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -8584,9 +8584,7 @@ int cik_init(struct radeon_device *rdev)
radeon_get_clock_info(rdev->ddev);
 
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
 
/* initialize memory controller */
r = cik_mc_init(rdev);
diff --git a/drivers/gpu/drm/radeon/evergreen.c 
b/drivers/gpu/drm/radeon/evergreen.c
index 8e9e88bf1f43..36a888e1b179 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -5208,9 +5208,7 @@ int evergreen_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* initialize AGP */
if (rdev->flags & RADEON_IS_AGP) {
r = radeon_agp_init(rdev);
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index ab7bd3080217..4a364ca7a1be 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -2375,9 +2375,7 @@ int cayman_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* initialize memory controller */
r = evergreen_mc_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index fcfcaec25a9e..aa6800b0e198 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -4056,9 +4056,7 @@ int r100_init(struct radeon_device *rdev)
/* initialize VRAM */
r100_mc_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 92643dfdd8a8..621ff174dff3 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -1549,9 +1549,7 @@ int r300_init(struct radeon_device *rdev)
/* initialize memory controller */
r300_mc_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r420.c b/drivers/gpu/drm/radeon/r420.c
index 1ed4407b91aa..7e6320e8c6a0 100644
--- a/drivers/gpu/drm/radeon/r420.c
+++ b/drivers/gpu/drm/radeon/r420.c
@@ -425,10 +425,7 @@ int r420_init(struct radeon_device *rdev)
r300_mc_init(rdev);
r420_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r) {
-   return r;
-   }
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r) {
diff --git a/drivers/gpu/drm/radeon/r520.c b/drivers/gpu/drm/radeon/r520.c
index fc78e64ae727..6cbcaa845192 100644
--- a/drivers/gpu/drm/radeon/r520.c
+++ b/drivers/gpu/drm/radeon/r520.c
@@ -299,9 +299,7 @@ int r520_init(struct radeon_device *rdev)
r520_mc_init(rdev);
rv515_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = rad

[PATCH 2/4] drm/radeon: remove meaningless if(r) check code

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
remove meaningless if(r) check code.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/r100.c | 4 +---
 drivers/gpu/drm/radeon/r300.c | 4 +---
 drivers/gpu/drm/radeon/r420.c | 5 +
 drivers/gpu/drm/radeon/r520.c | 4 +---
 drivers/gpu/drm/radeon/r600.c | 4 +---
 5 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index fcfcaec25a9e..aa6800b0e198 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -4056,9 +4056,7 @@ int r100_init(struct radeon_device *rdev)
/* initialize VRAM */
r100_mc_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 92643dfdd8a8..621ff174dff3 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -1549,9 +1549,7 @@ int r300_init(struct radeon_device *rdev)
/* initialize memory controller */
r300_mc_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r420.c b/drivers/gpu/drm/radeon/r420.c
index 1ed4407b91aa..7e6320e8c6a0 100644
--- a/drivers/gpu/drm/radeon/r420.c
+++ b/drivers/gpu/drm/radeon/r420.c
@@ -425,10 +425,7 @@ int r420_init(struct radeon_device *rdev)
r300_mc_init(rdev);
r420_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r) {
-   return r;
-   }
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r) {
diff --git a/drivers/gpu/drm/radeon/r520.c b/drivers/gpu/drm/radeon/r520.c
index fc78e64ae727..6cbcaa845192 100644
--- a/drivers/gpu/drm/radeon/r520.c
+++ b/drivers/gpu/drm/radeon/r520.c
@@ -299,9 +299,7 @@ int r520_init(struct radeon_device *rdev)
r520_mc_init(rdev);
rv515_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 7444dc0e0c0e..ca3fcae2adb5 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -3282,9 +3282,7 @@ int r600_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
if (rdev->flags & RADEON_IS_AGP) {
r = radeon_agp_init(rdev);
if (r)
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 0/4] delete useless function return values & remove meaningless if(r) check code

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
the function type maybe coule be changed to void.
This patch series will first delete the check of the return
value of the function call radeon_fence_driver_init, then,
optimise the function declaration and function to void type.

Signed-off-by: Bernard Zhao 

Bernard Zhao (4):
  drm/radeon: remove meaningless if(r) check code
  drm/radeon: remove meaningless if(r) check code
  drm/radeon: remove meaningless if(r) check code
  drm/radeon: delete useless return values

 drivers/gpu/drm/radeon/cik.c  | 4 +---
 drivers/gpu/drm/radeon/evergreen.c| 4 +---
 drivers/gpu/drm/radeon/ni.c   | 4 +---
 drivers/gpu/drm/radeon/r100.c | 4 +---
 drivers/gpu/drm/radeon/r300.c | 4 +---
 drivers/gpu/drm/radeon/r420.c | 5 +
 drivers/gpu/drm/radeon/r520.c | 4 +---
 drivers/gpu/drm/radeon/r600.c | 4 +---
 drivers/gpu/drm/radeon/radeon.h   | 2 +-
 drivers/gpu/drm/radeon/radeon_fence.c | 5 +
 drivers/gpu/drm/radeon/rs400.c| 4 +---
 drivers/gpu/drm/radeon/rs600.c| 4 +---
 drivers/gpu/drm/radeon/rs690.c| 4 +---
 drivers/gpu/drm/radeon/rv515.c| 4 +---
 drivers/gpu/drm/radeon/rv770.c| 4 +---
 drivers/gpu/drm/radeon/si.c   | 4 +---
 16 files changed, 16 insertions(+), 48 deletions(-)

-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re:Re: [PATCH 0/4] delete useless function return values & remove meaningless if(r) check code

2021-06-21 Thread Bernard

From: "Christian König" 
Date: 2021-06-21 00:59:27
To:  Bernard Zhao ,Alex Deucher 
,David Airlie ,Daniel Vetter 
,amd-gfx@lists.freedesktop.org,dri-de...@lists.freedesktop.org,linux-ker...@vger.kernel.org
Subject: Re: [PATCH 0/4] delete useless function return values & remove 
meaningless if(r) check code>Am 19.06.21 um 08:43 schrieb Bernard Zhao:
>> Function radeon_fence_driver_init always returns success,
>> the function type maybe coule be changed to void.
>> This patch series will first delete the check of the return
>> value of the function call radeon_fence_driver_init, then,
>> optimise the function declaration and function to void type.
>
>Please merge all of this into a single patch, I don't see any point 
>separating this.
>
>Christian.

Hi
Sure, i will resubmit one new ptach, thanks!
BR//Bernard

>>
>> Signed-off-by: Bernard Zhao 
>>
>> Bernard Zhao (4):
>>drm/radeon: remove meaningless if(r) check code
>>drm/radeon: remove meaningless if(r) check code
>>drm/radeon: remove meaningless if(r) check code
>>drm/radeon: delete useless return values
>>
>>   drivers/gpu/drm/radeon/cik.c  | 4 +---
>>   drivers/gpu/drm/radeon/evergreen.c| 4 +---
>>   drivers/gpu/drm/radeon/ni.c   | 4 +---
>>   drivers/gpu/drm/radeon/r100.c | 4 +---
>>   drivers/gpu/drm/radeon/r300.c | 4 +---
>>   drivers/gpu/drm/radeon/r420.c | 5 +
>>   drivers/gpu/drm/radeon/r520.c | 4 +---
>>   drivers/gpu/drm/radeon/r600.c | 4 +---
>>   drivers/gpu/drm/radeon/radeon.h   | 2 +-
>>   drivers/gpu/drm/radeon/radeon_fence.c | 5 +
>>   drivers/gpu/drm/radeon/rs400.c| 4 +---
>>   drivers/gpu/drm/radeon/rs600.c| 4 +---
>>   drivers/gpu/drm/radeon/rs690.c| 4 +---
>>   drivers/gpu/drm/radeon/rv515.c| 4 +---
>>   drivers/gpu/drm/radeon/rv770.c| 4 +---
>>   drivers/gpu/drm/radeon/si.c   | 4 +---
>>   16 files changed, 16 insertions(+), 48 deletions(-)
>>
>


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/4] drm/radeon: remove meaningless if(r) check code

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
remove meaningless if(r) check code.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/cik.c   | 4 +---
 drivers/gpu/drm/radeon/evergreen.c | 4 +---
 drivers/gpu/drm/radeon/ni.c| 4 +---
 drivers/gpu/drm/radeon/si.c| 4 +---
 4 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index 42a8afa839cb..f6cf0b8fdd83 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -8584,9 +8584,7 @@ int cik_init(struct radeon_device *rdev)
radeon_get_clock_info(rdev->ddev);
 
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
 
/* initialize memory controller */
r = cik_mc_init(rdev);
diff --git a/drivers/gpu/drm/radeon/evergreen.c 
b/drivers/gpu/drm/radeon/evergreen.c
index 8e9e88bf1f43..36a888e1b179 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -5208,9 +5208,7 @@ int evergreen_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* initialize AGP */
if (rdev->flags & RADEON_IS_AGP) {
r = radeon_agp_init(rdev);
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index ab7bd3080217..4a364ca7a1be 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -2375,9 +2375,7 @@ int cayman_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* initialize memory controller */
r = evergreen_mc_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index d0e94b10e4c0..013e44ed0f39 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -6857,9 +6857,7 @@ int si_init(struct radeon_device *rdev)
radeon_get_clock_info(rdev->ddev);
 
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
 
/* initialize memory controller */
r = si_mc_init(rdev);
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 3/4] drm/radeon: remove meaningless if(r) check code

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
remove meaningless if(r) check code.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/rs400.c | 4 +---
 drivers/gpu/drm/radeon/rs600.c | 4 +---
 drivers/gpu/drm/radeon/rs690.c | 4 +---
 drivers/gpu/drm/radeon/rv515.c | 4 +---
 drivers/gpu/drm/radeon/rv770.c | 4 +---
 5 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c
index 8423bcc3302b..6383f7a34bd8 100644
--- a/drivers/gpu/drm/radeon/rs400.c
+++ b/drivers/gpu/drm/radeon/rs400.c
@@ -555,9 +555,7 @@ int rs400_init(struct radeon_device *rdev)
/* initialize memory controller */
rs400_mc_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index 5bf26058eec0..b2d22e25eee1 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -1132,9 +1132,7 @@ int rs600_init(struct radeon_device *rdev)
rs600_mc_init(rdev);
r100_debugfs_rbbm_init(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
index 7bc302a89232..14fb0819b8c1 100644
--- a/drivers/gpu/drm/radeon/rs690.c
+++ b/drivers/gpu/drm/radeon/rs690.c
@@ -850,9 +850,7 @@ int rs690_init(struct radeon_device *rdev)
rs690_mc_init(rdev);
rv515_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/rv515.c b/drivers/gpu/drm/radeon/rv515.c
index 46a53dd38079..63fb06e8e2d7 100644
--- a/drivers/gpu/drm/radeon/rv515.c
+++ b/drivers/gpu/drm/radeon/rv515.c
@@ -648,9 +648,7 @@ int rv515_init(struct radeon_device *rdev)
rv515_mc_init(rdev);
rv515_debugfs(rdev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* Memory manager */
r = radeon_bo_init(rdev);
if (r)
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 88e29ebaad46..74499307285b 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -1941,9 +1941,7 @@ int rv770_init(struct radeon_device *rdev)
/* Initialize clocks */
radeon_get_clock_info(rdev->ddev);
/* Fence driver */
-   r = radeon_fence_driver_init(rdev);
-   if (r)
-   return r;
+   radeon_fence_driver_init(rdev);
/* initialize AGP */
if (rdev->flags & RADEON_IS_AGP) {
r = radeon_agp_init(rdev);
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 4/4] drm/radeon: delete useless return values

2021-06-21 Thread Bernard Zhao
Function radeon_fence_driver_init always returns success,
the function type maybe coule be changed to void.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/radeon.h   | 2 +-
 drivers/gpu/drm/radeon/radeon_fence.c | 5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 56ed5634cebe..8a15f490a390 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -384,7 +384,7 @@ struct radeon_fence {
 };
 
 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
-int radeon_fence_driver_init(struct radeon_device *rdev);
+void radeon_fence_driver_init(struct radeon_device *rdev);
 void radeon_fence_driver_fini(struct radeon_device *rdev);
 void radeon_fence_driver_force_completion(struct radeon_device *rdev, int 
ring);
 int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, 
int ring);
diff --git a/drivers/gpu/drm/radeon/radeon_fence.c 
b/drivers/gpu/drm/radeon/radeon_fence.c
index 0d8ef2368adf..b2ce642ca4fa 100644
--- a/drivers/gpu/drm/radeon/radeon_fence.c
+++ b/drivers/gpu/drm/radeon/radeon_fence.c
@@ -905,9 +905,8 @@ static void radeon_fence_driver_init_ring(struct 
radeon_device *rdev, int ring)
  * Not all asics have all rings, so each asic will only
  * start the fence driver on the rings it has using
  * radeon_fence_driver_start_ring().
- * Returns 0 for success.
  */
-int radeon_fence_driver_init(struct radeon_device *rdev)
+void radeon_fence_driver_init(struct radeon_device *rdev)
 {
int ring;
 
@@ -917,8 +916,6 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
}
 
radeon_debugfs_fence_init(rdev);
-
-   return 0;
 }
 
 /**
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/display: remove no need variable

2021-06-07 Thread Bernard Zhao
remove no need variable, just return the DC_OK

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
index f962b905e79e..7daadb6a5233 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
@@ -1266,8 +1266,6 @@ static enum dc_status dcn10_validate_global(struct dc 
*dc, struct dc_state *cont
 
 static enum dc_status dcn10_patch_unknown_plane_state(struct dc_plane_state 
*plane_state)
 {
-   enum dc_status result = DC_OK;
-
enum surface_pixel_format surf_pix_format = plane_state->format;
unsigned int bpp = resource_pixel_format_to_bpp(surf_pix_format);
 
@@ -1279,7 +1277,7 @@ static enum dc_status 
dcn10_patch_unknown_plane_state(struct dc_plane_state *pla
swizzle = DC_SW_64KB_S;
 
plane_state->tiling_info.gfx9.swizzle = swizzle;
-   return result;
+   return DC_OK;
 }
 
 struct stream_encoder *dcn10_find_first_free_match_stream_enc_for_link(
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: remove not needed conversion to bool

2021-04-02 Thread Bernard Zhao
Fix coccicheck warning:
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c:573:39-44: WARNING: conversion to bool 
not needed here
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c:575:39-44: WARNING: conversion to bool 
not needed here

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c
index ab9be5ad5a5f..0734e8ef5e41 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c
@@ -570,9 +570,9 @@ static int mmhub_v2_3_set_clockgating(struct amdgpu_device 
*adev,
return 0;
 
mmhub_v2_3_update_medium_grain_clock_gating(adev,
-   state == AMD_CG_STATE_GATE ? true : false);
+   (state == AMD_CG_STATE_GATE));
mmhub_v2_3_update_medium_grain_light_sleep(adev,
-   state == AMD_CG_STATE_GATE ? true : false);
+   (state == AMD_CG_STATE_GATE));
 
return 0;
 }
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: cleanup coding style a bit

2021-03-31 Thread Bernard Zhao
Fix patch check warning:
WARNING: suspect code indent for conditional statements (8, 17)
+   if (obj && obj->use < 0) {
+DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", 
obj->head.name);

WARNING: braces {} are not necessary for single statement blocks
+   if (obj && obj->use < 0) {
+DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", 
obj->head.name);
+   }

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 1fb2a91ad30a..43d17b72c265 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -449,11 +449,10 @@ static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
 
 static inline void put_obj(struct ras_manager *obj)
 {
-   if (obj && --obj->use == 0)
+   if (obj && (--obj->use == 0))
list_del(>node);
-   if (obj && obj->use < 0) {
-DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", 
obj->head.name);
-   }
+   if (obj && (obj->use < 0))
+   DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", obj->head.name);
 }
 
 /* make one obj and return it. */
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amd/amdgpu: code refactoring to clean code style a bit

2021-03-31 Thread Bernard Zhao
Fix checkpatch.pl warning:
Too many leading tabs - consider code refactoring
WARNING: Too many leading tabs - consider code refactoring
+   for (j = 0; j < 
profile->ucLeakageBinNum; j++) {

WARNING: Too many leading tabs - consider code refactoring
+   if (vbios_voltage_id <= 
leakage_bin[j]) {

WARNING: Too many leading tabs - consider code refactoring
+   for (j = 0; j < 
profile->ucLeakageBinNum; j++) {

WARNING: Too many leading tabs - consider code refactoring
+   if (vbios_voltage_id <= 
leakage_bin[j]) {

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 84 
 1 file changed, 35 insertions(+), 49 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 86add0f4ea4d..9968ff8ddc9c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -1283,65 +1283,51 @@ int 
amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_devic
profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
(adev->mode_info.atom_context->bios + data_offset);
 
-   switch (frev) {
-   case 1:
+   if ((frev != 2) || (crev != 1)) {
+   DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
return -EINVAL;
-   case 2:
-   switch (crev) {
-   case 1:
-   if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
-   return -EINVAL;
-   leakage_bin = (u16 *)
-   (adev->mode_info.atom_context->bios + 
data_offset +
-le16_to_cpu(profile->usLeakageBinArrayOffset));
-   vddc_id_buf = (u16 *)
-   (adev->mode_info.atom_context->bios + 
data_offset +
-le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
-   vddc_buf = (u16 *)
-   (adev->mode_info.atom_context->bios + 
data_offset +
-
le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
-   vddci_id_buf = (u16 *)
-   (adev->mode_info.atom_context->bios + 
data_offset +
-
le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
-   vddci_buf = (u16 *)
-   (adev->mode_info.atom_context->bios + 
data_offset +
-
le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
-
-   if (profile->ucElbVDDC_Num > 0) {
-   for (i = 0; i < profile->ucElbVDDC_Num; i++) {
-   if (vddc_id_buf[i] == 
virtual_voltage_id) {
-   for (j = 0; j < 
profile->ucLeakageBinNum; j++) {
-   if (vbios_voltage_id <= 
leakage_bin[j]) {
-   *vddc = 
vddc_buf[j * profile->ucElbVDDC_Num + i];
-   break;
-   }
-   }
+   }
+
+   if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
+   return -EINVAL;
+
+   leakage_bin = (u16 *)(adev->mode_info.atom_context->bios + data_offset +
+le16_to_cpu(profile->usLeakageBinArrayOffset));
+   vddc_id_buf = (u16 *)(adev->mode_info.atom_context->bios + data_offset +
+le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
+   vddc_buf = (u16 *)(adev->mode_info.atom_context->bios + data_offset +
+le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
+   vddci_id_buf = (u16 *)(adev->mode_info.atom_context->bios + data_offset 
+
+le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
+   vddci_buf = (u16 *)(adev->mode_info.atom_context->bios + data_offset +
+le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
+
+   if (profile->ucElbVDDC_Num > 0) {
+   for (i = 0; i < profile->ucElbVDDC_Num; i++) {
+   if (vddc_id_buf[i] == virtual_voltage_id) {
+   for (j = 0; j < profile->ucLeakageBinNum; j++) {
+   if (vbios_voltage_id <= leakage_bin[j]) 
{
+   *vddc = vddc_buf[j * 
profile->ucElbVDDC_

[PATCH] drm/amd: use kmalloc_array over kmalloc with multiply

2021-03-31 Thread Bernard Zhao
Fix patch check warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply
+   buf = kmalloc(MAX_KFIFO_SIZE * sizeof(*buf), GFP_KERNEL);

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
index 17d1736367ea..246522423559 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
@@ -81,7 +81,7 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char 
__user *user,
struct kfd_smi_client *client = filep->private_data;
unsigned char *buf;
 
-   buf = kmalloc(MAX_KFIFO_SIZE * sizeof(*buf), GFP_KERNEL);
+   buf = kmalloc_array(MAX_KFIFO_SIZE, sizeof(*buf), GFP_KERNEL);
if (!buf)
return -ENOMEM;
 
-- 
2.31.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amd/display: remove unneeded variable: "pattern"

2021-02-02 Thread Bernard Zhao
Remove unneeded variable: "pattern".

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
index f95bade59624..d77ae58210f6 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
@@ -126,9 +126,7 @@ static void dpcd_set_training_pattern(
 static enum dc_dp_training_pattern decide_cr_training_pattern(
const struct dc_link_settings *link_settings)
 {
-   enum dc_dp_training_pattern pattern = DP_TRAINING_PATTERN_SEQUENCE_1;
-
-   return pattern;
+   return DP_TRAINING_PATTERN_SEQUENCE_1;
 }
 
 static enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link 
*link,
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amd/amdgpu: optimise CONFIG_X||CONFIG_X_MODULE to IS_ENABLED(X)

2020-11-18 Thread Bernard Zhao
Optimise CONFIG_ || CONFIG__MODULE to IS_ENABLED().
This change also fix check_patch.pl warning:
WARNING: Prefer IS_ENABLED() to CONFIG_ ||
CONFIG__MODULE
+#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined
(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index 165b02e267b0..f1980cd1f402 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -64,7 +64,7 @@ struct amdgpu_atif {
struct amdgpu_atif_notifications notifications;
struct amdgpu_atif_functions functions;
struct amdgpu_atif_notification_cfg notification_cfg;
-#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || 
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
struct backlight_device *bd;
 #endif
struct amdgpu_dm_backlight_caps backlight_caps;
@@ -447,7 +447,7 @@ static int amdgpu_atif_handler(struct amdgpu_device *adev,
DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
 
if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
-#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || 
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
if (atif->bd) {
DRM_DEBUG_DRIVER("Changing brightness to %d\n",
 req.backlight_level);
@@ -806,7 +806,7 @@ int amdgpu_acpi_init(struct amdgpu_device *adev)
}
adev->atif = atif;
 
-#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || 
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
+#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
if (atif->notifications.brightness_change) {
if (amdgpu_device_has_dc_support(adev)) {
 #if defined(CONFIG_DRM_AMD_DC)
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amd/amdgpu: use kmalloc_array to replace kmalloc with multiply

2020-11-17 Thread Bernard Zhao
Fix check_patch.pl warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply
+bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
WARNING: Prefer kmalloc_array over kmalloc with multiply
+bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo),
GFP_KERNEL);
kmalloc_array has multiply overflow check, which will be safer.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index d0aea5e39531..f2a0851c804f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -280,8 +280,8 @@ static int amdgpu_virt_init_ras_err_handler_data(struct 
amdgpu_device *adev)
if (!*data)
return -ENOMEM;
 
-   bps = kmalloc(align_space * sizeof((*data)->bps), GFP_KERNEL);
-   bps_bo = kmalloc(align_space * sizeof((*data)->bps_bo), GFP_KERNEL);
+   bps = kmalloc_array(align_space, sizeof((*data)->bps), GFP_KERNEL);
+   bps_bo = kmalloc_array(align_space, sizeof((*data)->bps_bo), 
GFP_KERNEL);
 
if (!bps || !bps_bo) {
kfree(bps);
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amdgpu/amdgpu_ids: fix kmalloc_array not uses number as first arg

2020-11-17 Thread Bernard Zhao
Fix check_patch.pl warning:
kmalloc_array uses number as first arg, sizeof is generally wrong.
+fences = kmalloc_array(sizeof(void *), id_mgr->num_ids,
GFP_KERNEL);

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index 6e9a9e5dbea0..f2bd4b0e06f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -208,7 +208,7 @@ static int amdgpu_vmid_grab_idle(struct amdgpu_vm *vm,
if (ring->vmid_wait && !dma_fence_is_signaled(ring->vmid_wait))
return amdgpu_sync_fence(sync, ring->vmid_wait);
 
-   fences = kmalloc_array(sizeof(void *), id_mgr->num_ids, GFP_KERNEL);
+   fences = kmalloc_array(id_mgr->num_ids, sizeof(void *), GFP_KERNEL);
if (!fences)
return -ENOMEM;
 
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amd/display/amdgpu_dm: delete same check in if condition

2020-11-10 Thread Bernard Zhao
In function amdgpu_dm_connector_get_modes, drm_edid_is_valid
will check weather (!edid), no need to check again in the if
branch.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index e93e18c06c0e..0a283d07fe10 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -6352,7 +6352,7 @@ static int amdgpu_dm_connector_get_modes(struct 
drm_connector *connector)
 
encoder = amdgpu_dm_connector_to_encoder(connector);
 
-   if (!edid || !drm_edid_is_valid(edid)) {
+   if (!drm_edid_is_valid(edid)) {
amdgpu_dm_connector->num_modes =
drm_add_modes_noedid(connector, 640, 480);
} else {
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: fix typoes

2020-11-02 Thread Bernard Zhao
Fix typoes.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/calcs/dce_calcs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/calcs/dce_calcs.c 
b/drivers/gpu/drm/amd/display/dc/calcs/dce_calcs.c
index 2c6db379afae..e994d233aa21 100644
--- a/drivers/gpu/drm/amd/display/dc/calcs/dce_calcs.c
+++ b/drivers/gpu/drm/amd/display/dc/calcs/dce_calcs.c
@@ -1980,7 +1980,7 @@ static void calculate_bandwidth(
else {
data->latency_for_non_mcifwr_clients = bw_int_to_fixed(0);
}
-   /*dmif mc urgent latency suppported in high sclk and yclk*/
+   /*dmif mc urgent latency supported in high sclk and yclk*/
data->dmifmc_urgent_latency_supported_in_high_sclk_and_yclk = 
bw_div((bw_sub(data->min_read_buffer_size_in_time, 
data->dmif_burst_time[high][s_high])), data->total_dmifmc_urgent_trips);
/*dram speed/p-state change margin*/
/*in the multi-display case the nb p-state change watermark cannot 
exceed the average lb size plus the dmif size or the cursor dcp buffer size*/
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: move DRM_ERROR log out of the mutex protect area

2020-11-02 Thread Bernard Zhao
In function amdgpu_register_gpu_instance, there is no need to
protect DRM_ERROR in mutex mgpu_info.mutex.
This change is to make the code to run a bit fast.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index efda38349a03..cc61b0a5b8d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -104,8 +104,8 @@ void amdgpu_register_gpu_instance(struct amdgpu_device 
*adev)
mutex_lock(_info.mutex);
 
if (mgpu_info.num_gpu >= MAX_GPU_INSTANCE) {
-   DRM_ERROR("Cannot register more gpu instance\n");
mutex_unlock(_info.mutex);
+   DRM_ERROR("Cannot register more gpu instance\n");
return;
}
 
-- 
2.29.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: remove unnecessary conversion from bool value to bool

2020-10-14 Thread Bernard Zhao
In functions vegam_is_dpm_running & vegam_populate_avfs_parameters,
maybe there is no need to conver bool condition to bool variable
or bool return value.
This change is to make the code a bit more readable.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
index 0ecc18b55ffb..32ca472f58a6 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
@@ -296,8 +296,9 @@ static int vegam_process_firmware_header(struct pp_hwmgr 
*hwmgr)
 static bool vegam_is_dpm_running(struct pp_hwmgr *hwmgr)
 {
return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
-   CGS_IND_REG__SMC, FEATURE_STATUS, 
VOLTAGE_CONTROLLER_ON))
-   ? true : false;
+CGS_IND_REG__SMC,
+FEATURE_STATUS,
+VOLTAGE_CONTROLLER_ON));
 }
 
 static uint32_t vegam_get_mac_definition(uint32_t value)
@@ -1661,7 +1662,7 @@ static int vegam_populate_avfs_parameters(struct pp_hwmgr 
*hwmgr)
(avfs_params.ucEnableGB_FUSE_TABLE_CKSON << 
AVFSGB0_Vdroop_Enable_SHIFT) |
(avfs_params.ucEnableGB_FUSE_TABLE_CKSOFF << 
AVFSGB1_Vdroop_Enable_SHIFT);
data->apply_avfs_cks_off_voltage =
-   (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage 
== 1) ? true : false;
+   (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage 
== 1);
}
return result;
 }
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/display: remove no need return value

2020-10-12 Thread Bernard Zhao
Functions (disable_all_writeback_pipes_for_stream &
dc_enable_stereo & dc_post_update_surfaces_to_stream)
always return true, there is no need to keep the return value.
This change is to make the code a bit more readable.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc.c   | 17 +
 drivers/gpu/drm/amd/display/dc/dc.h|  2 +-
 drivers/gpu/drm/amd/display/dc/dc_stream.h |  2 +-
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 92eb1ca1634f..8dc598a632b5 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -761,7 +761,7 @@ static bool dc_construct(struct dc *dc,
return false;
 }
 
-static bool disable_all_writeback_pipes_for_stream(
+static void disable_all_writeback_pipes_for_stream(
const struct dc *dc,
struct dc_stream_state *stream,
struct dc_state *context)
@@ -770,8 +770,6 @@ static bool disable_all_writeback_pipes_for_stream(
 
for (i = 0; i < stream->num_wb_info; i++)
stream->writeback_info[i].wb_enabled = false;
-
-   return true;
 }
 
 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, 
struct dc_stream_state *stream, bool lock)
@@ -1213,13 +1211,12 @@ bool dc_validate_seamless_boot_timing(const struct dc 
*dc,
return true;
 }
 
-bool dc_enable_stereo(
+void dc_enable_stereo(
struct dc *dc,
struct dc_state *context,
struct dc_stream_state *streams[],
uint8_t stream_count)
 {
-   bool ret = true;
int i, j;
struct pipe_ctx *pipe;
 
@@ -1234,8 +1231,6 @@ bool dc_enable_stereo(
dc->hwss.setup_stereo(pipe, dc);
}
}
-
-   return ret;
 }
 
 /*
@@ -1448,18 +1443,18 @@ static bool is_flip_pending_in_pipes(struct dc *dc, 
struct dc_state *context)
return false;
 }
 
-bool dc_post_update_surfaces_to_stream(struct dc *dc)
+void dc_post_update_surfaces_to_stream(struct dc *dc)
 {
int i;
struct dc_state *context = dc->current_state;
 
if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
-   return true;
+   return;
 
post_surface_trace(dc);
 
if (is_flip_pending_in_pipes(dc, context))
-   return true;
+   return;
 
for (i = 0; i < dc->res_pool->pipe_count; i++)
if (context->res_ctx.pipe_ctx[i].stream == NULL ||
@@ -1472,8 +1467,6 @@ bool dc_post_update_surfaces_to_stream(struct dc *dc)
 
dc->optimized_required = false;
dc->wm_optimized_required = false;
-
-   return true;
 }
 
 struct dc_state *dc_create_state(struct dc *dc)
diff --git a/drivers/gpu/drm/amd/display/dc/dc.h 
b/drivers/gpu/drm/amd/display/dc/dc.h
index f50ef4255020..f79a3c318757 100644
--- a/drivers/gpu/drm/amd/display/dc/dc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc.h
@@ -962,7 +962,7 @@ struct dc_flip_addrs {
bool triplebuffer_flips;
 };
 
-bool dc_post_update_surfaces_to_stream(
+void dc_post_update_surfaces_to_stream(
struct dc *dc);
 
 #include "dc_stream.h"
diff --git a/drivers/gpu/drm/amd/display/dc/dc_stream.h 
b/drivers/gpu/drm/amd/display/dc/dc_stream.h
index d9888f316da6..0047ab33f88e 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_stream.h
+++ b/drivers/gpu/drm/amd/display/dc/dc_stream.h
@@ -391,7 +391,7 @@ enum dc_status dc_validate_stream(struct dc *dc, struct 
dc_stream_state *stream)
  * Enable stereo when commit_streams is not required,
  * for example, frame alternate.
  */
-bool dc_enable_stereo(
+void dc_enable_stereo(
struct dc *dc,
struct dc_state *context,
struct dc_stream_state *streams[],
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH RFC PKS/PMEM 10/58] drivers/rdma: Utilize new kmap_thread()

2020-10-12 Thread Bernard Metzler
-ira.we...@intel.com wrote: -

>To: "Andrew Morton" , "Thomas Gleixner"
>, "Ingo Molnar" , "Borislav
>Petkov" , "Andy Lutomirski" , "Peter
>Zijlstra" 
>From: ira.we...@intel.com
>Date: 10/09/2020 09:52PM
>Cc: "Ira Weiny" , "Mike Marciniszyn"
>, "Dennis Dalessandro"
>, "Doug Ledford" ,
>"Jason Gunthorpe" , "Faisal Latif"
>, "Shiraz Saleem" ,
>"Bernard Metzler" , x...@kernel.org, "Dave Hansen"
>, "Dan Williams"
>, "Fenghua Yu" ,
>linux-...@vger.kernel.org, linux-ker...@vger.kernel.org,
>linux-nvd...@lists.01.org, linux-fsde...@vger.kernel.org,
>linux...@kvack.org, linux-kselft...@vger.kernel.org,
>linuxppc-...@lists.ozlabs.org, k...@vger.kernel.org,
>net...@vger.kernel.org, b...@vger.kernel.org,
>ke...@lists.infradead.org, linux-bca...@vger.kernel.org,
>linux-...@lists.infradead.org, de...@driverdev.osuosl.org,
>linux-...@vger.kernel.org, linux-...@vger.kernel.org,
>linux-s...@vger.kernel.org, target-de...@vger.kernel.org,
>linux-...@vger.kernel.org, ceph-de...@vger.kernel.org,
>linux-e...@vger.kernel.org, linux-...@kvack.org,
>io-ur...@vger.kernel.org, linux-er...@lists.ozlabs.org,
>linux...@lists.infradead.org, linux-ntfs-...@lists.sourceforge.net,
>reiserfs-de...@vger.kernel.org,
>linux-f2fs-de...@lists.sourceforge.net, linux-ni...@vger.kernel.org,
>cluster-de...@redhat.com, ecryp...@vger.kernel.org,
>linux-c...@vger.kernel.org, linux-bt...@vger.kernel.org,
>linux-...@lists.infradead.org, linux-r...@vger.kernel.org,
>amd-gfx@lists.freedesktop.org, dri-de...@lists.freedesktop.org,
>intel-...@lists.freedesktop.org, drbd-...@tron.linbit.com,
>linux-bl...@vger.kernel.org, xen-de...@lists.xenproject.org,
>linux-cach...@redhat.com, samba-techni...@lists.samba.org,
>intel-wired-...@lists.osuosl.org
>Subject: [EXTERNAL] [PATCH RFC PKS/PMEM 10/58] drivers/rdma: Utilize
>new kmap_thread()
>
>From: Ira Weiny 
>
>The kmap() calls in these drivers are localized to a single thread.
>To
>avoid the over head of global PKRS updates use the new kmap_thread()
>call.
>
>Cc: Mike Marciniszyn 
>Cc: Dennis Dalessandro 
>Cc: Doug Ledford 
>Cc: Jason Gunthorpe 
>Cc: Faisal Latif 
>Cc: Shiraz Saleem 
>Cc: Bernard Metzler 
>Signed-off-by: Ira Weiny 
>---
> drivers/infiniband/hw/hfi1/sdma.c  |  4 ++--
> drivers/infiniband/hw/i40iw/i40iw_cm.c | 10 +-
> drivers/infiniband/sw/siw/siw_qp_tx.c  | 14 +++---
> 3 files changed, 14 insertions(+), 14 deletions(-)
>
>diff --git a/drivers/infiniband/hw/hfi1/sdma.c
>b/drivers/infiniband/hw/hfi1/sdma.c
>index 04575c9afd61..09d206e3229a 100644
>--- a/drivers/infiniband/hw/hfi1/sdma.c
>+++ b/drivers/infiniband/hw/hfi1/sdma.c
>@@ -3130,7 +3130,7 @@ int ext_coal_sdma_tx_descs(struct hfi1_devdata
>*dd, struct sdma_txreq *tx,
>   }
> 
>   if (type == SDMA_MAP_PAGE) {
>-  kvaddr = kmap(page);
>+  kvaddr = kmap_thread(page);
>   kvaddr += offset;
>   } else if (WARN_ON(!kvaddr)) {
>   __sdma_txclean(dd, tx);
>@@ -3140,7 +3140,7 @@ int ext_coal_sdma_tx_descs(struct hfi1_devdata
>*dd, struct sdma_txreq *tx,
>   memcpy(tx->coalesce_buf + tx->coalesce_idx, kvaddr, len);
>   tx->coalesce_idx += len;
>   if (type == SDMA_MAP_PAGE)
>-  kunmap(page);
>+  kunmap_thread(page);
> 
>   /* If there is more data, return */
>   if (tx->tlen - tx->coalesce_idx)
>diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c
>b/drivers/infiniband/hw/i40iw/i40iw_cm.c
>index a3b95805c154..122d7a5642a1 100644
>--- a/drivers/infiniband/hw/i40iw/i40iw_cm.c
>+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
>@@ -3721,7 +3721,7 @@ int i40iw_accept(struct iw_cm_id *cm_id, struct
>iw_cm_conn_param *conn_param)
>   ibmr->device = iwpd->ibpd.device;
>   iwqp->lsmm_mr = ibmr;
>   if (iwqp->page)
>-  iwqp->sc_qp.qp_uk.sq_base = kmap(iwqp->page);
>+  iwqp->sc_qp.qp_uk.sq_base = kmap_thread(iwqp->page);
>   dev->iw_priv_qp_ops->qp_send_lsmm(>sc_qp,
>   iwqp->ietf_mem.va,
>   (accept.size + 
> conn_param->private_data_len),
>@@ -3729,12 +3729,12 @@ int i40iw_accept(struct iw_cm_id *cm_id,
>struct iw_cm_conn_param *conn_param)
> 
>   } else {
>   if (iwqp->page)
>

[PATCH] drm/amd/display: remove no need return value

2020-10-10 Thread Bernard Zhao
Functions (disable_all_writeback_pipes_for_stream &
dc_enable_stereo & dc_post_update_surfaces_to_stream)
always return true, there is no need to keep the return value.
This change is to make the code a bit more readable.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc.c   | 17 +
 drivers/gpu/drm/amd/display/dc/dc.h|  2 +-
 drivers/gpu/drm/amd/display/dc/dc_stream.h |  2 +-
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 92eb1ca1634f..8dc598a632b5 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -761,7 +761,7 @@ static bool dc_construct(struct dc *dc,
return false;
 }
 
-static bool disable_all_writeback_pipes_for_stream(
+static void disable_all_writeback_pipes_for_stream(
const struct dc *dc,
struct dc_stream_state *stream,
struct dc_state *context)
@@ -770,8 +770,6 @@ static bool disable_all_writeback_pipes_for_stream(
 
for (i = 0; i < stream->num_wb_info; i++)
stream->writeback_info[i].wb_enabled = false;
-
-   return true;
 }
 
 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, 
struct dc_stream_state *stream, bool lock)
@@ -1213,13 +1211,12 @@ bool dc_validate_seamless_boot_timing(const struct dc 
*dc,
return true;
 }
 
-bool dc_enable_stereo(
+void dc_enable_stereo(
struct dc *dc,
struct dc_state *context,
struct dc_stream_state *streams[],
uint8_t stream_count)
 {
-   bool ret = true;
int i, j;
struct pipe_ctx *pipe;
 
@@ -1234,8 +1231,6 @@ bool dc_enable_stereo(
dc->hwss.setup_stereo(pipe, dc);
}
}
-
-   return ret;
 }
 
 /*
@@ -1448,18 +1443,18 @@ static bool is_flip_pending_in_pipes(struct dc *dc, 
struct dc_state *context)
return false;
 }
 
-bool dc_post_update_surfaces_to_stream(struct dc *dc)
+void dc_post_update_surfaces_to_stream(struct dc *dc)
 {
int i;
struct dc_state *context = dc->current_state;
 
if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
-   return true;
+   return;
 
post_surface_trace(dc);
 
if (is_flip_pending_in_pipes(dc, context))
-   return true;
+   return;
 
for (i = 0; i < dc->res_pool->pipe_count; i++)
if (context->res_ctx.pipe_ctx[i].stream == NULL ||
@@ -1472,8 +1467,6 @@ bool dc_post_update_surfaces_to_stream(struct dc *dc)
 
dc->optimized_required = false;
dc->wm_optimized_required = false;
-
-   return true;
 }
 
 struct dc_state *dc_create_state(struct dc *dc)
diff --git a/drivers/gpu/drm/amd/display/dc/dc.h 
b/drivers/gpu/drm/amd/display/dc/dc.h
index f50ef4255020..f79a3c318757 100644
--- a/drivers/gpu/drm/amd/display/dc/dc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc.h
@@ -962,7 +962,7 @@ struct dc_flip_addrs {
bool triplebuffer_flips;
 };
 
-bool dc_post_update_surfaces_to_stream(
+void dc_post_update_surfaces_to_stream(
struct dc *dc);
 
 #include "dc_stream.h"
diff --git a/drivers/gpu/drm/amd/display/dc/dc_stream.h 
b/drivers/gpu/drm/amd/display/dc/dc_stream.h
index d9888f316da6..0047ab33f88e 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_stream.h
+++ b/drivers/gpu/drm/amd/display/dc/dc_stream.h
@@ -391,7 +391,7 @@ enum dc_status dc_validate_stream(struct dc *dc, struct 
dc_stream_state *stream)
  * Enable stereo when commit_streams is not required,
  * for example, frame alternate.
  */
-bool dc_enable_stereo(
+void dc_enable_stereo(
struct dc *dc,
struct dc_state *context,
struct dc_stream_state *streams[],
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/radeon:fix typoes in comments

2020-09-22 Thread Bernard Zhao
Change the comment typo: "programm" -> "program".

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/uvd_v1_0.c | 4 ++--
 drivers/gpu/drm/radeon/uvd_v2_2.c | 2 +-
 drivers/gpu/drm/radeon/uvd_v4_2.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/uvd_v1_0.c 
b/drivers/gpu/drm/radeon/uvd_v1_0.c
index 800721153d51..58557c2263a7 100644
--- a/drivers/gpu/drm/radeon/uvd_v1_0.c
+++ b/drivers/gpu/drm/radeon/uvd_v1_0.c
@@ -117,7 +117,7 @@ int uvd_v1_0_resume(struct radeon_device *rdev)
if (r)
return r;
 
-   /* programm the VCPU memory controller bits 0-27 */
+   /* program the VCPU memory controller bits 0-27 */
addr = (rdev->uvd.gpu_addr >> 3) + 16;
size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size) >> 3;
WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
@@ -360,7 +360,7 @@ int uvd_v1_0_start(struct radeon_device *rdev)
/* Set the write pointer delay */
WREG32(UVD_RBC_RB_WPTR_CNTL, 0);
 
-   /* programm the 4GB memory segment for rptr and ring buffer */
+   /* program the 4GB memory segment for rptr and ring buffer */
WREG32(UVD_LMI_EXT40_ADDR, upper_32_bits(ring->gpu_addr) |
   (0x7 << 16) | (0x1 << 31));
 
diff --git a/drivers/gpu/drm/radeon/uvd_v2_2.c 
b/drivers/gpu/drm/radeon/uvd_v2_2.c
index 23b18edda20e..6266167886d9 100644
--- a/drivers/gpu/drm/radeon/uvd_v2_2.c
+++ b/drivers/gpu/drm/radeon/uvd_v2_2.c
@@ -109,7 +109,7 @@ int uvd_v2_2_resume(struct radeon_device *rdev)
if (r)
return r;
 
-   /* programm the VCPU memory controller bits 0-27 */
+   /* program the VCPU memory controller bits 0-27 */
addr = rdev->uvd.gpu_addr >> 3;
size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) >> 3;
WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
diff --git a/drivers/gpu/drm/radeon/uvd_v4_2.c 
b/drivers/gpu/drm/radeon/uvd_v4_2.c
index dc54fa4aaea8..f9e97fa63674 100644
--- a/drivers/gpu/drm/radeon/uvd_v4_2.c
+++ b/drivers/gpu/drm/radeon/uvd_v4_2.c
@@ -40,7 +40,7 @@ int uvd_v4_2_resume(struct radeon_device *rdev)
uint64_t addr;
uint32_t size;
 
-   /* programm the VCPU memory controller bits 0-27 */
+   /* program the VCPU memory controller bits 0-27 */
 
/* skip over the header of the new firmware format */
if (rdev->uvd.fw_header_present)
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd:fix typoes in comments

2020-09-22 Thread Bernard Zhao
Change the comment typo: "programm" -> "program".

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
 drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c  | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c  | 4 ++--
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c  | 4 ++--
 8 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 770025a5e500..7c46937c1c0e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -98,7 +98,7 @@ struct amdgpu_bo_list_entry;
 #define AMDGPU_PTE_MTYPE_NV10(a)   ((uint64_t)(a) << 48)
 #define AMDGPU_PTE_MTYPE_NV10_MASK AMDGPU_PTE_MTYPE_NV10(7ULL)
 
-/* How to programm VM fault handling */
+/* How to program VM fault handling */
 #define AMDGPU_VM_FAULT_STOP_NEVER 0
 #define AMDGPU_VM_FAULT_STOP_FIRST 1
 #define AMDGPU_VM_FAULT_STOP_ALWAYS2
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c 
b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
index 3cafba726587..b0c0c438fc93 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c
@@ -348,7 +348,7 @@ static int uvd_v4_2_start(struct amdgpu_device *adev)
/* Set the write pointer delay */
WREG32(mmUVD_RBC_RB_WPTR_CNTL, 0);
 
-   /* programm the 4GB memory segment for rptr and ring buffer */
+   /* program the 4GB memory segment for rptr and ring buffer */
WREG32(mmUVD_LMI_EXT40_ADDR, upper_32_bits(ring->gpu_addr) |
   (0x7 << 16) | (0x1 << 31));
 
@@ -541,7 +541,7 @@ static void uvd_v4_2_mc_resume(struct amdgpu_device *adev)
uint64_t addr;
uint32_t size;
 
-   /* programm the VCPU memory controller bits 0-27 */
+   /* program the VCPU memory controller bits 0-27 */
addr = (adev->uvd.inst->gpu_addr + AMDGPU_UVD_FIRMWARE_OFFSET) >> 3;
size = AMDGPU_UVD_FIRMWARE_SIZE(adev) >> 3;
WREG32(mmUVD_VCPU_CACHE_OFFSET0, addr);
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c 
b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
index a566ff926e90..6e57001f6d0a 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c
@@ -253,7 +253,7 @@ static void uvd_v5_0_mc_resume(struct amdgpu_device *adev)
uint64_t offset;
uint32_t size;
 
-   /* programm memory controller bits 0-27 */
+   /* program memory controller bits 0-27 */
WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
lower_32_bits(adev->uvd.inst->gpu_addr));
WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,
@@ -404,7 +404,7 @@ static int uvd_v5_0_start(struct amdgpu_device *adev)
/* set the wb address */
WREG32(mmUVD_RBC_RB_RPTR_ADDR, (upper_32_bits(ring->gpu_addr) >> 2));
 
-   /* programm the RB_BASE for ring buffer */
+   /* program the RB_BASE for ring buffer */
WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_LOW,
lower_32_bits(ring->gpu_addr));
WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH,
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
index 0a880bc101b8..d2d90fe5c6f8 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
@@ -583,7 +583,7 @@ static void uvd_v6_0_mc_resume(struct amdgpu_device *adev)
uint64_t offset;
uint32_t size;
 
-   /* programm memory controller bits 0-27 */
+   /* program memory controller bits 0-27 */
WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
lower_32_bits(adev->uvd.inst->gpu_addr));
WREG32(mmUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH,
@@ -825,7 +825,7 @@ static int uvd_v6_0_start(struct amdgpu_device *adev)
/* set the wb address */
WREG32(mmUVD_RBC_RB_RPTR_ADDR, (upper_32_bits(ring->gpu_addr) >> 2));
 
-   /* programm the RB_BASE for ring buffer */
+   /* program the RB_BASE for ring buffer */
WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_LOW,
lower_32_bits(ring->gpu_addr));
WREG32(mmUVD_LMI_RBC_RB_64BIT_BAR_HIGH,
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c
index e07e3fae99b5..b44c8677ce8d 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c
@@ -1073,7 +1073,7 @@ static int uvd_v7_0_start(struct amdgpu_device *adev)
WREG32_SOC15(UVD, k, mmUVD_RBC_RB_RPTR_ADDR,
(upper_32_bits(ring->gpu_addr) >> 2));
 
-   /* programm the RB_BASE for ring buffer */
+   /* program the RB_BASE for ring buffer */

Re:Re: [PATCH] drm/amd/display: optimize code runtime a bit

2020-09-22 Thread Bernard

From: Alex Deucher 
Date: 2020-09-22 03:33:20
To:  Bernard Zhao 
Cc:  Harry Wentland ,Leo Li ,Alex 
Deucher ,"Christian König" 
,David Airlie ,Daniel Vetter 
,Rodrigo Siqueira ,Jun Lei 
,Aric Cyr ,Wenjing Liu 
,abdoulaye berthe ,Michael 
Strauss ,Brandon Syu ,Martin 
Leung ,amd-gfx list 
,Maling list - DRI developers 
,LKML 
,opensource.ker...@vivo.com
Subject: Re: [PATCH] drm/amd/display: optimize code runtime a bit>On Mon, Sep 
21, 2020 at 9:14 AM Bernard Zhao  wrote:
>>
>> Static function dal_ddc_i2c_payloads_destroy is only called
>> in dal_ddc_service_query_ddc_data, the parameter is 
>> , there is no point NULL risk, so no need to check.
>> This change is to make the code run a bit fast.
>>
>
>How about just getting rid of dal_ddc_i2c_payloads_destroy() and just
>call dal_vector_destruct() directly.

Good idea, I will resubmit a patch, thanks!

BR//Bernard

>Alex
>
>
>> Signed-off-by: Bernard Zhao 
>> ---
>>  drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c 
>> b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
>> index b984eecca58b..6dcc666738fc 100644
>> --- a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
>> +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
>> @@ -150,9 +150,6 @@ static uint32_t dal_ddc_i2c_payloads_get_count(struct 
>> i2c_payloads *p)
>>
>>  static void dal_ddc_i2c_payloads_destroy(struct i2c_payloads *p)
>>  {
>> -   if (!p)
>> -   return;
>> -
>> dal_vector_destruct(>payloads);
>>  }
>>
>> --
>> 2.28.0
>>
>> ___
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2] drm/amd/display: optimize code runtime a bit

2020-09-22 Thread Bernard Zhao
In the function dal_ddc_service_query_ddc_data,
get rid of dal_ddc_i2c_payloads_destroy, call
dal_vector_destruct() directly.
This change is to make the code run a bit fast.

Signed-off-by: Bernard Zhao 
Changes since V1:
*get rid of dal_ddc_i2c_payloads_destroy, call
dal_vector_destruct() directly.

Link for V1:
*https://lore.kernel.org/patchwork/patch/1309014/
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
index b984eecca58b..dec12de37642 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
@@ -148,14 +148,6 @@ static uint32_t dal_ddc_i2c_payloads_get_count(struct 
i2c_payloads *p)
return p->payloads.count;
 }
 
-static void dal_ddc_i2c_payloads_destroy(struct i2c_payloads *p)
-{
-   if (!p)
-   return;
-
-   dal_vector_destruct(>payloads);
-}
-
 #define DDC_MIN(a, b) (((a) < (b)) ? (a) : (b))
 
 void dal_ddc_i2c_payloads_add(
@@ -582,7 +574,7 @@ bool dal_ddc_service_query_ddc_data(
ddc->link,
);
 
-   dal_ddc_i2c_payloads_destroy();
+   dal_vector_destruct();
}
 
return success;
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/display: optimize code runtime a bit

2020-09-21 Thread Bernard Zhao
Static function dal_ddc_i2c_payloads_destroy is only called
in dal_ddc_service_query_ddc_data, the parameter is 
, there is no point NULL risk, so no need to check.
This change is to make the code run a bit fast.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
index b984eecca58b..6dcc666738fc 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c
@@ -150,9 +150,6 @@ static uint32_t dal_ddc_i2c_payloads_get_count(struct 
i2c_payloads *p)
 
 static void dal_ddc_i2c_payloads_destroy(struct i2c_payloads *p)
 {
-   if (!p)
-   return;
-
dal_vector_destruct(>payloads);
 }
 
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/display: optimize code runtime a bit

2020-09-10 Thread Bernard Zhao
In fnction is_cr_done & is_ch_eq_done, when done = false
happened once, no need to circle left ln_count.
This change is to make the code run a bit fast.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
index b2be6ad5101d..53e30be8b66a 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
@@ -373,34 +373,30 @@ static void dpcd_set_lt_pattern_and_lane_settings(
 static bool is_cr_done(enum dc_lane_count ln_count,
union lane_status *dpcd_lane_status)
 {
-   bool done = true;
uint32_t lane;
/*LANEx_CR_DONE bits All 1's?*/
for (lane = 0; lane < (uint32_t)(ln_count); lane++) {
if (!dpcd_lane_status[lane].bits.CR_DONE_0)
-   done = false;
+   return false;
}
-   return done;
-
+   return true;
 }
 
 static bool is_ch_eq_done(enum dc_lane_count ln_count,
union lane_status *dpcd_lane_status,
union lane_align_status_updated *lane_status_updated)
 {
-   bool done = true;
uint32_t lane;
if (!lane_status_updated->bits.INTERLANE_ALIGN_DONE)
-   done = false;
+   return false;
else {
for (lane = 0; lane < (uint32_t)(ln_count); lane++) {
if (!dpcd_lane_status[lane].bits.SYMBOL_LOCKED_0 ||
!dpcd_lane_status[lane].bits.CHANNEL_EQ_DONE_0)
-   done = false;
+   return false;
}
}
-   return done;
-
+   return true;
 }
 
 static void update_drive_settings(
-- 
2.28.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re:Re: [PATCH v2] drm/amdkfd: Fix memory leaks according to error branches

2020-06-22 Thread Bernard


From: Julia Lawall 
Date: 2020-06-20 17:37:19
To:  Markus Elfring 
Cc:  Bernard Zhao 
,opensource.ker...@vivo.com,amd-gfx@lists.freedesktop.org,dri-de...@lists.freedesktop.org,kernel-janit...@vger.kernel.org,linux-ker...@vger.kernel.org,Alex
 Deucher ,"Christian König" 
,"Felix Kühling" ,Daniel 
Vetter ,David Airlie 
Subject: Re: [PATCH v2] drm/amdkfd: Fix memory leaks according to error 
branches>
>
>On Sat, 20 Jun 2020, Markus Elfring wrote:
>
>> > The function kobject_init_and_add alloc memory like:
>> > kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs
>> > ->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller
>> > ->kmalloc_slab, in err branch this memory not free. If use
>> > kmemleak, this path maybe catched.
>> > These changes are to add kobject_put in kobject_init_and_add
>> > failed branch, fix potential memleak.
>>
>> I suggest to improve this change description.
>>
>> * Can an other wording variant be nicer?
>
>Markus's suggestion is as usual extremely imprecise.  However, I also find
>the message quite unclear.
>
>It would be good to always use English words.  alloc and err are not
>English words.  Perhaps most people will figure out what they are
>abbreviations for, but it would be better to use a few more letters to
>make it so that no one has to guess.
>
>Then there are a bunch of things that are connected by arrows with no
>spaces between them.  The most obvious meaning of an arrow with no space
>around it is a variable dereference.  After spending some mental effort,
>one can realize that that is not what you mean here.  A layout like:
>
>   first_function ->
> second_function ->
>   third_function
>
>would be much more readable.
>
>I don't know what "this patch maybe catched" means.  Is "catched" supposed
>to be "caught" or "cached"?  Overall, the sentence could be "Kmemleak
>could possibly detect this issue", or something like that.  But I don't
>know what this means.  Did you detect the problem with kmemleak?  if you
>did not detect the problem with kmemleak, and overall you don't know
>whether kmemleak would detect the bug or not, is this information useful
>at all for the patch?

Hi:

Kmemleak detected a memory leak as below:
kobject_init_and_add->
kobject_add_varg->
kobject_set_name_vargs->
kvasprintf_const->
kstrdup_const->
    kstrdup->
kmalloc_track_caller->
kmalloc_slab

If kobject_init_and_add is called, but kobject_put is not called in the error 
branch.
This will be detected by kmemleak.

BR//Bernard

>"These changes are to" makes a lot of words with no information.  While it
>is perhaps not necessary to slavishly follow the rule about using the
>imperative, if it is convenient to use the imperative, doing so eliminates
>such meaningless phrases.
>
>memleak is also not an English word.  Memory leak is only a few more
>characters, and doesn't require the reader to make the small extra effort
>to figure out what you mean.
>
>julia
>
>>
>> * Will the tag “Fixes” become helpful for the commit message?
>>
>> Regards,
>> Markus
>>


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v3] drm/amd: fix potential memleak in err branch

2020-06-22 Thread Bernard Zhao
The function kobject_init_and_add alloc memory like:
kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs
->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller
->kmalloc_slab, in err branch this memory not free. If use
kmemleak, this path maybe catched.
These changes are to add kobject_put in kobject_init_and_add
failed branch, fix potential memleak.

Signed-off-by: Bernard Zhao 
---
Changes since V2:
*remove duplicate kobject_put in kfd_procfs_init.

Link for V1:
*https://lore.kernel.org/patchwork/patch/1258608/
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d27221ddcdeb..0e0c42e9f6a3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -428,6 +428,7 @@ struct kfd_process *kfd_create_process(struct file *filep)
   (int)process->lead_thread->pid);
if (ret) {
pr_warn("Creating procfs pid directory failed");
+   kobject_put(process->kobj);
goto out;
}
 
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2] drm/amd: fix potential memleak in err branch

2020-06-22 Thread Bernard Zhao
The function kobject_init_and_add alloc memory like:
kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs
->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller
->kmalloc_slab, in err branch this memory not free. If use
kmemleak, this path maybe catched.
These changes are to add kobject_put in kobject_init_and_add
failed branch, fix potential memleak.

Signed-off-by: Bernard Zhao 
---
Changes since V1:
*Remove duplicate changed file kfd_topology.c, this file`s fix
already applied to the main line.
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d27221ddcdeb..5ee4d6cfb16d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -124,6 +124,7 @@ void kfd_procfs_init(void)
if (ret) {
pr_warn("Could not create procfs proc folder");
/* If we fail to create the procfs, clean up */
+   kobject_put(procfs.kobj);
kfd_procfs_shutdown();
}
 }
@@ -428,6 +429,7 @@ struct kfd_process *kfd_create_process(struct file *filep)
   (int)process->lead_thread->pid);
if (ret) {
pr_warn("Creating procfs pid directory failed");
+   kobject_put(process->kobj);
goto out;
}
 
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: fix potential memleak in err branch

2020-06-19 Thread Bernard Zhao
The function kobject_init_and_add alloc memory like:
kobject_init_and_add->kobject_add_varg->kobject_set_name_vargs
->kvasprintf_const->kstrdup_const->kstrdup->kmalloc_track_caller
->kmalloc_slab, in err branch this memory not free. If use
kmemleak, this path maybe catched.
These changes are to add kobject_put in kobject_init_and_add
failed branch, fix potential memleak.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  |  2 ++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 20 +++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d27221ddcdeb..5ee4d6cfb16d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -124,6 +124,7 @@ void kfd_procfs_init(void)
if (ret) {
pr_warn("Could not create procfs proc folder");
/* If we fail to create the procfs, clean up */
+   kobject_put(procfs.kobj);
kfd_procfs_shutdown();
}
 }
@@ -428,6 +429,7 @@ struct kfd_process *kfd_create_process(struct file *filep)
   (int)process->lead_thread->pid);
if (ret) {
pr_warn("Creating procfs pid directory failed");
+   kobject_put(process->kobj);
goto out;
}
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index bb77f7af2b6d..dc3c4149f860 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -632,8 +632,10 @@ static int kfd_build_sysfs_node_entry(struct 
kfd_topology_device *dev,
 
ret = kobject_init_and_add(dev->kobj_node, _type,
sys_props.kobj_nodes, "%d", id);
-   if (ret < 0)
+   if (ret < 0) {
+   kobject_put(dev->kobj_node);
return ret;
+   }
 
dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node);
if (!dev->kobj_mem)
@@ -680,8 +682,10 @@ static int kfd_build_sysfs_node_entry(struct 
kfd_topology_device *dev,
return -ENOMEM;
ret = kobject_init_and_add(mem->kobj, _type,
dev->kobj_mem, "%d", i);
-   if (ret < 0)
+   if (ret < 0) {
+   kobject_put(mem->kobj);
return ret;
+   }
 
mem->attr.name = "properties";
mem->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -699,8 +703,10 @@ static int kfd_build_sysfs_node_entry(struct 
kfd_topology_device *dev,
return -ENOMEM;
ret = kobject_init_and_add(cache->kobj, _type,
dev->kobj_cache, "%d", i);
-   if (ret < 0)
+   if (ret < 0) {
+   kobject_put(cache->kobj);
return ret;
+   }
 
cache->attr.name = "properties";
cache->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -718,8 +724,10 @@ static int kfd_build_sysfs_node_entry(struct 
kfd_topology_device *dev,
return -ENOMEM;
ret = kobject_init_and_add(iolink->kobj, _type,
dev->kobj_iolink, "%d", i);
-   if (ret < 0)
+   if (ret < 0) {
+   kobject_put(iolink->kobj);
return ret;
+   }
 
iolink->attr.name = "properties";
iolink->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -798,8 +806,10 @@ static int kfd_topology_update_sysfs(void)
ret = kobject_init_and_add(sys_props.kobj_topology,
_type,  _device->kobj,
"topology");
-   if (ret < 0)
+   if (ret < 0) {
+   kobject_put(sys_props.kobj_topology);
return ret;
+   }
 
sys_props.kobj_nodes = kobject_create_and_add("nodes",
sys_props.kobj_topology);
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: add missing fill of the array`s first element

2020-06-12 Thread Bernard Zhao
In function fill_iram_v_2, the ram_table->bright_neg_gain`s
first element [0][0] seems to be missing. This change is just
to make the code a bit readable.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/display/modules/power/power_helpers.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/display/modules/power/power_helpers.c 
b/drivers/gpu/drm/amd/display/modules/power/power_helpers.c
index 8c37bcc27132..7604a01be19c 100644
--- a/drivers/gpu/drm/amd/display/modules/power/power_helpers.c
+++ b/drivers/gpu/drm/amd/display/modules/power/power_helpers.c
@@ -350,6 +350,7 @@ void fill_iram_v_2(struct iram_table_v_2 *ram_table, struct 
dmcu_iram_parameters
ram_table->bright_pos_gain[4][1] = 0x20;
ram_table->bright_pos_gain[4][2] = 0x20;
ram_table->bright_pos_gain[4][3] = 0x20;
+   ram_table->bright_neg_gain[0][0] = 0x00;
ram_table->bright_neg_gain[0][1] = 0x00;
ram_table->bright_neg_gain[0][2] = 0x00;
ram_table->bright_neg_gain[0][3] = 0x00;
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd: remove unnecessary conversion to bool

2020-06-12 Thread Bernard Zhao
In function is_support_sw_smu, remove unnecessary conversion
to bool return, this change is to make the code a bit readable.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 8c684a6e0156..3e1cfb010378 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -568,7 +568,7 @@ int smu_update_table(struct smu_context *smu, enum 
smu_table_id table_index, int
 bool is_support_sw_smu(struct amdgpu_device *adev)
 {
if (adev->asic_type == CHIP_VEGA20)
-   return (amdgpu_dpm == 2) ? true : false;
+   return (amdgpu_dpm == 2);
else if (adev->asic_type >= CHIP_ARCTURUS) {
  if (amdgpu_sriov_is_pp_one_vf(adev) || !amdgpu_sriov_vf(adev))
return true;
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re:RE: [PATCH v2] drm/amd/amdgpu: cleanup coding style a bit

2020-05-11 Thread Bernard


发件人:"Ruhl, Michael J" 
发送日期:2020-05-08 23:45:07
收件人:Bernard Zhao ,Alex Deucher 
,"Christian König" ,"David 
(ChunMing) Zhou" ,David Airlie ,Daniel 
Vetter ,Tom St Denis ,Sam Ravnborg 
,Ori Messinger 
,"amd-gfx@lists.freedesktop.org" 
,"dri-de...@lists.freedesktop.org" 
,"linux-ker...@vger.kernel.org" 

抄送人:"opensource.ker...@vivo.com" 
主题:RE: [PATCH v2] drm/amd/amdgpu: cleanup coding style a bit>>-Original 
Message-
>>From: dri-devel  On Behalf Of
>>Bernard Zhao
>>Sent: Thursday, May 7, 2020 5:13 AM
>>To: Alex Deucher ; Christian König
>>; David (ChunMing) Zhou
>>; David Airlie ; Daniel Vetter
>>; Tom St Denis ; Sam Ravnborg
>>; Ori Messinger ; Bernard
>>Zhao ; amd-gfx@lists.freedesktop.org; dri-
>>de...@lists.freedesktop.org; linux-ker...@vger.kernel.org
>>Cc: opensource.ker...@vivo.com
>>Subject: [PATCH v2] drm/amd/amdgpu: cleanup coding style a bit
>>
>>There is DEVICE_ATTR mechanism in separate attribute define.
>>So this change is to use attr array, also use
>>sysfs_create_files in init function & sysfs_remove_files in
>>fini function.
>>This maybe make the code a bit readable.
>>
>>Signed-off-by: Bernard Zhao 
>>
>>Changes since V1:
>>*Use DEVICE_ATTR mechanism
>>
>>Link for V1:
>>*https://lore.kernel.org/patchwork/patch/1228076/
>>---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 43 ++-
>>-
>> 1 file changed, 13 insertions(+), 30 deletions(-)
>>
>>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>index 82a3299e53c0..57bbc70662ff 100644
>>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>@@ -148,6 +148,15 @@ static DEVICE_ATTR(mem_info_vis_vram_used,
>>S_IRUGO,
>> static DEVICE_ATTR(mem_info_vram_vendor, S_IRUGO,
>> amdgpu_mem_info_vram_vendor, NULL);
>>
>>+static struct attribute *amdgpu_vram_mgr_attributes[] = {
>>+ _attr_mem_info_vram_total.attr,
>>+ _attr_mem_info_vis_vram_total.attr,
>>+ _attr_mem_info_vram_used.attr,
>>+ _attr_mem_info_vis_vram_used.attr,
>>+ _attr_mem_info_vram_vendor.attr,
>>+ NULL
>>+};
>>+
>> /**
>>  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
>>  *
>>@@ -172,31 +181,9 @@ static int amdgpu_vram_mgr_init(struct
>>ttm_mem_type_manager *man,
>>  man->priv = mgr;
>>
>>  /* Add the two VRAM-related sysfs files */
>>- ret = device_create_file(adev->dev,
>>_attr_mem_info_vram_total);
>>- if (ret) {
>>- DRM_ERROR("Failed to create device file
>>mem_info_vram_total\n");
>>- return ret;
>>- }
>>- ret = device_create_file(adev->dev,
>>_attr_mem_info_vis_vram_total);
>>- if (ret) {
>>- DRM_ERROR("Failed to create device file
>>mem_info_vis_vram_total\n");
>>- return ret;
>>- }
>>- ret = device_create_file(adev->dev,
>>_attr_mem_info_vram_used);
>>- if (ret) {
>>- DRM_ERROR("Failed to create device file
>>mem_info_vram_used\n");
>>- return ret;
>>- }
>>- ret = device_create_file(adev->dev,
>>_attr_mem_info_vis_vram_used);
>>- if (ret) {
>>- DRM_ERROR("Failed to create device file
>>mem_info_vis_vram_used\n");
>>- return ret;
>>- }
>>- ret = device_create_file(adev->dev,
>>_attr_mem_info_vram_vendor);
>>- if (ret) {
>>- DRM_ERROR("Failed to create device file
>>mem_info_vram_vendor\n");
>>- return ret;
>>- }
>>+ ret = sysfs_create_files(>dev->kobj,
>>amdgpu_vram_mgr_attributes);
>>+ if (ret)
>>+ DRM_ERROR("Failed to register sysfs\n");
>
>This looks good to me.
>
>I think that there is a new error macro (drm_err?) that you might
>want to use instead of DRM_ERROR().
>
>Otherwise:
>
>Acked-by: Michael J. Ruhl 
>
>m

Hi
Sure, I am willing to make this modification, also in GPU TODO list, there is 
one content:
"Convert logging to drm_* functions with drm_device paramater,For drivers which 
could 
have multiple instances, it is necessary to differentiate between which is 
which in the logs. 
Since DRM_INFO/WARN/ERROR don’t do this, drivers used dev_info/warn/err to make 
this differentiation. We now have

[PATCH v2] drm/amd/amdgpu: cleanup coding style a bit

2020-05-07 Thread Bernard Zhao
There is DEVICE_ATTR mechanism in separate attribute define.
So this change is to use attr array, also use
sysfs_create_files in init function & sysfs_remove_files in
fini function.
This maybe make the code a bit readable.

Signed-off-by: Bernard Zhao 

Changes since V1:
*Use DEVICE_ATTR mechanism

Link for V1:
*https://lore.kernel.org/patchwork/patch/1228076/
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 43 ++--
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..57bbc70662ff 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -148,6 +148,15 @@ static DEVICE_ATTR(mem_info_vis_vram_used, S_IRUGO,
 static DEVICE_ATTR(mem_info_vram_vendor, S_IRUGO,
   amdgpu_mem_info_vram_vendor, NULL);
 
+static struct attribute *amdgpu_vram_mgr_attributes[] = {
+   _attr_mem_info_vram_total.attr,
+   _attr_mem_info_vis_vram_total.attr,
+   _attr_mem_info_vram_used.attr,
+   _attr_mem_info_vis_vram_used.attr,
+   _attr_mem_info_vram_vendor.attr,
+   NULL
+};
+
 /**
  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
  *
@@ -172,31 +181,9 @@ static int amdgpu_vram_mgr_init(struct 
ttm_mem_type_manager *man,
man->priv = mgr;
 
/* Add the two VRAM-related sysfs files */
-   ret = device_create_file(adev->dev, _attr_mem_info_vram_total);
-   if (ret) {
-   DRM_ERROR("Failed to create device file mem_info_vram_total\n");
-   return ret;
-   }
-   ret = device_create_file(adev->dev, _attr_mem_info_vis_vram_total);
-   if (ret) {
-   DRM_ERROR("Failed to create device file 
mem_info_vis_vram_total\n");
-   return ret;
-   }
-   ret = device_create_file(adev->dev, _attr_mem_info_vram_used);
-   if (ret) {
-   DRM_ERROR("Failed to create device file mem_info_vram_used\n");
-   return ret;
-   }
-   ret = device_create_file(adev->dev, _attr_mem_info_vis_vram_used);
-   if (ret) {
-   DRM_ERROR("Failed to create device file 
mem_info_vis_vram_used\n");
-   return ret;
-   }
-   ret = device_create_file(adev->dev, _attr_mem_info_vram_vendor);
-   if (ret) {
-   DRM_ERROR("Failed to create device file 
mem_info_vram_vendor\n");
-   return ret;
-   }
+   ret = sysfs_create_files(>dev->kobj, amdgpu_vram_mgr_attributes);
+   if (ret)
+   DRM_ERROR("Failed to register sysfs\n");
 
return 0;
 }
@@ -219,11 +206,7 @@ static int amdgpu_vram_mgr_fini(struct 
ttm_mem_type_manager *man)
spin_unlock(>lock);
kfree(mgr);
man->priv = NULL;
-   device_remove_file(adev->dev, _attr_mem_info_vram_total);
-   device_remove_file(adev->dev, _attr_mem_info_vis_vram_total);
-   device_remove_file(adev->dev, _attr_mem_info_vram_used);
-   device_remove_file(adev->dev, _attr_mem_info_vis_vram_used);
-   device_remove_file(adev->dev, _attr_mem_info_vram_vendor);
+   sysfs_remove_files(>dev->kobj, amdgpu_vram_mgr_attributes);
return 0;
 }
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re:Re: [PATCH] drm/radeon: cleanup coding style a bit

2020-04-30 Thread Bernard


发件人:Joe Perches 
发送日期:2020-04-27 01:53:06
收件人:"Christian König" ,Bernard Zhao 
,Alex Deucher ,"David (ChunMing) 
Zhou" ,David Airlie ,Daniel Vetter 
,amd-gfx@lists.freedesktop.org,dri-de...@lists.freedesktop.org,linux-ker...@vger.kernel.org
抄送人:opensource.ker...@vivo.com
主题:Re: [PATCH] drm/radeon: cleanup coding style a bit>On Sun, 2020-04-26 at 
15:18 +0200, Christian König wrote:
>> Am 26.04.20 um 15:12 schrieb Bernard Zhao:
>> > Maybe no need to check ws before kmalloc, kmalloc will check
>> > itself, kmalloc`s logic is if ptr is NULL, kmalloc will just
>> > return
>> > 
>> > Signed-off-by: Bernard Zhao 
>> 
>> Reviewed-by: Christian König 
>> 
>> I'm wondering why the automated scripts haven't found that one before.
>
>because this pattern is
>
>   if (foo)
>   kfree(bar);
>
>and the pattern looked for is:
>
>   if (foo)
>   kfree(foo);
>
>> > diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
>[]
>> > @@ -1211,8 +1211,7 @@ static int atom_execute_table_locked(struct 
>> > atom_context *ctx, int index, uint32
>> >SDEBUG("<<\n");
>> >   
>> >   free:
>> > -  if (ws)
>> > -  kfree(ectx.ws);
>> > +  kfree(ectx.ws);
>> >return ret;
>> >   }
>
>I'm wondering if this removal is correct as the function
>is named _locked and it may be recursive or called under
>some external lock.
>
Hi
I am a little confused about this. I understand that the caller guarantees the 
lock protection
that we will not release the wrong pointer. And the NULL check is the same with 
the first check in kfree?
Maybe we do not need check twich.

Regards,
Bernard



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/radeon: cleanup coding style a bit

2020-04-27 Thread Bernard Zhao
Maybe no need to check ws before kmalloc, kmalloc will check
itself, kmalloc`s logic is if ptr is NULL, kmalloc will just
return

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/radeon/atom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
index 2c27627b6659..f15b20da5315 100644
--- a/drivers/gpu/drm/radeon/atom.c
+++ b/drivers/gpu/drm/radeon/atom.c
@@ -1211,8 +1211,7 @@ static int atom_execute_table_locked(struct atom_context 
*ctx, int index, uint32
SDEBUG("<<\n");
 
 free:
-   if (ws)
-   kfree(ectx.ws);
+   kfree(ectx.ws);
return ret;
 }
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v5] drm/amdgpu: cleanup coding style in amdkfd a bit

2020-04-22 Thread Bernard Zhao
Make the code a bit more readable by using a common
error handling pattern.
With that done the patch is Reviewed-by: Christian König
.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve
*code style refactoring

Changes since V2:
*code style adjust

Changes since V3:
*find the best way to merge unnecessary if/else check branch

Changes since V4:
*Improve the subject line and commit message

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226587/
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 20 +--
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 9dff792c9290..acb612c53b9c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -660,15 +660,15 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else {
-   pr_err("Failed to reserve buffers in ttm\n");
+   if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
+   return ret;
}
 
-   return ret;
+   ctx->reserved = true;
+   return 0;
 }
 
 /**
@@ -733,17 +733,15 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else
-   pr_err("Failed to reserve buffers in ttm.\n");
-
if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
+   return ret;
}
 
-   return ret;
+   ctx->reserved = true;
+   return 0;
 }
 
 /**
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V4] amdgpu: reduce no need mutex_lock area

2020-04-21 Thread Bernard Zhao
Maybe we could reduce the mutex_lock(>lock)`s protected code area,
and no need to protect pr_debug.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve

Changes since V2:
*move comment along with the mutex_unlock

Changes since V3:
*lock protect the if check, there is some possibility of multi-threaded
 racing modify.

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226588/
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 327317c54f7c..549bdb429883 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1289,9 +1289,9 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
mutex_lock(>lock);
 
if (mem->mapped_to_gpu_memory > 0) {
+   mutex_unlock(>lock);
pr_debug("BO VA 0x%llx size 0x%lx is still mapped.\n",
mem->va, bo_size);
-   mutex_unlock(>lock);
return -EBUSY;
}
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v4] amdgpu: remove unnecessary condition check

2020-04-21 Thread Bernard Zhao
There is no need to if check again, maybe we could merge
into the above else branch.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve
*code style refactoring

Changes since V2:
*code style adjust

Changes since V3:
*find the best way to merge unnecessary if/else check branch

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226587/
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 20 +--
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 9dff792c9290..acb612c53b9c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -660,15 +660,15 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else {
-   pr_err("Failed to reserve buffers in ttm\n");
+   if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
+   return ret;
}
 
-   return ret;
+   ctx->reserved = true;
+   return 0;
 }
 
 /**
@@ -733,17 +733,15 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else
-   pr_err("Failed to reserve buffers in ttm.\n");
-
if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
+   return ret;
}
 
-   return ret;
+   ctx->reserved = true;
+   return 0;
 }
 
 /**
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V3] amdgpu: remove unnecessary condition check

2020-04-21 Thread Bernard Zhao
There is no need to if check again, maybe we could merge
into the above else branch.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve
*code style refactoring

Changes since V2:
*code style adjust

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226587/
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c   | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 9dff792c9290..5424bd921a7b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -660,13 +660,12 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else {
-   pr_err("Failed to reserve buffers in ttm\n");
+   if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
-   }
+   } else
+   ctx->reserved = true;
 
return ret;
 }
@@ -733,15 +732,12 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else
-   pr_err("Failed to reserve buffers in ttm.\n");
-
if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
-   }
+   } else
+   ctx->reserved = true;
 
return ret;
 }
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amdgpu: fixes memleak issue when init failed

2020-04-21 Thread Bernard Zhao
VRAM manager and DRM MM when init failed, there is no operaction
to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..4c5fb153e6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct 
ttm_mem_type_manager *man,
ret = device_create_file(adev->dev, _attr_mem_info_vram_total);
if (ret) {
DRM_ERROR("Failed to create device file mem_info_vram_total\n");
-   return ret;
+   goto VRAM_TOTAL_FAIL;
}
ret = device_create_file(adev->dev, _attr_mem_info_vis_vram_total);
if (ret) {
DRM_ERROR("Failed to create device file 
mem_info_vis_vram_total\n");
-   return ret;
+   goto VIS_VRAM_TOTA_FAIL;
}
ret = device_create_file(adev->dev, _attr_mem_info_vram_used);
if (ret) {
DRM_ERROR("Failed to create device file mem_info_vram_used\n");
-   return ret;
+   goto VRAM_USED_FAIL;
}
ret = device_create_file(adev->dev, _attr_mem_info_vis_vram_used);
if (ret) {
DRM_ERROR("Failed to create device file 
mem_info_vis_vram_used\n");
-   return ret;
+   goto VIS_VRAM_USED_FAIL;
}
ret = device_create_file(adev->dev, _attr_mem_info_vram_vendor);
if (ret) {
DRM_ERROR("Failed to create device file 
mem_info_vram_vendor\n");
-   return ret;
+   goto VRAM_VERDOR_FAIL;
}
 
return 0;
+
+VRAM_VERDOR_FAIL:
+   device_remove_file(adev->dev, _attr_mem_info_vis_vram_used);
+VIS_VRAM_USED_FAIL:
+   device_remove_file(adev->dev, _attr_mem_info_vram_used);
+RVAM_USED_FAIL:
+   device_remove_file(adev->dev, _attr_mem_info_vis_vram_total);
+VIS_VRAM_TOTA_FAIL:
+   device_remove_file(adev->dev, _attr_mem_info_vram_total);
+VRAM_TOTAL_FAIL:
+   kfree(mgr);
+   man->priv = NULL;
+
+   return ret;
 }
 
 /**
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V2] amdgpu: optimization-- reduce noneed mutex_lock area

2020-04-21 Thread Bernard Zhao
Maybe we could reduce the mutex_lock(>lock)`s protected code area,
and noneed to protect pr_debug.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226588/
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 327317c54f7c..3c3769e57174 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1285,17 +1285,18 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
struct bo_vm_reservation_context ctx;
struct ttm_validate_buffer *bo_list_entry;
int ret;
+   unsigned int mapped_to_gpu_memory;
 
mutex_lock(>lock);
+   mapped_to_gpu_memory = mem->mapped_to_gpu_memory;
+   mutex_unlock(>lock);
 
-   if (mem->mapped_to_gpu_memory > 0) {
+   if (mapped_to_gpu_memory > 0) {
pr_debug("BO VA 0x%llx size 0x%lx is still mapped.\n",
mem->va, bo_size);
-   mutex_unlock(>lock);
return -EBUSY;
}
 
-   mutex_unlock(>lock);
/* lock is not needed after this, since mem is unused and will
 * be freed anyway
 */
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2] amdgpu: fixes error branch not return errno issue

2020-04-21 Thread Bernard Zhao
The "if(!encoder)" branch return the same value 0 of the success
branch, maybe return -EINVAL is more better.

Signed-off-by: Bernard Zhao 

---
Changes since V1:
* commit message improve
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index f355d9a..1f8c6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -474,12 +474,12 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
if (!amdgpu_encoder->enc_priv)
-   return 0;
+   return -EINVAL;
 
dig = amdgpu_encoder->enc_priv;
new_coherent_mode = val ? true : false;
@@ -494,7 +494,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -509,7 +509,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -523,7 +523,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -537,7 +537,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -551,7 +551,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V2] amdgpu: remove unnecessary condition check

2020-04-21 Thread Bernard Zhao
There is no need to if check again, maybe we could merge
into the above else branch.

Signed-off-by: Bernard Zhao 

---
Changes since V1:
*commit message improve
*code style refactoring

Link for V1:
* https://lore.kernel.org/patchwork/patch/1226587/
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 9dff792c9290..a64eeb07bec4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -660,13 +660,15 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else {
+
+   if (ret) {
pr_err("Failed to reserve buffers in ttm\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
}
+   else {
+   ctx->reserved = true;
+   }
 
return ret;
 }
@@ -733,15 +735,15 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 
ret = ttm_eu_reserve_buffers(>ticket, >list,
 false, >duplicates);
-   if (!ret)
-   ctx->reserved = true;
-   else
-   pr_err("Failed to reserve buffers in ttm.\n");
 
if (ret) {
+   pr_err("Failed to reserve buffers in ttm.\n");
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
}
+   else {
+   ctx->reserved = true;
+   }
 
return ret;
 }
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V3] amdgpu:optimization-- reduce no need mutex_lock area

2020-04-21 Thread Bernard Zhao
Maybe we could reduce the mutex_lock(>lock)`s protected code area,
and no need to protect pr_debug.

Signed-off-by: Bernard Zhao 

Changes since V1:
*commit message improve

Changes since V2:
*move comment along with the mutex_unlock

Link for V1:
*https://lore.kernel.org/patchwork/patch/1226588/
Link for V2:
*https://lore.kernel.org/patchwork/patch/1227907/
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 327317c54f7c..f03d9843d723 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1285,21 +1285,21 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
struct bo_vm_reservation_context ctx;
struct ttm_validate_buffer *bo_list_entry;
int ret;
+   unsigned int mapped_to_gpu_memory;
 
mutex_lock(>lock);
+   mapped_to_gpu_memory = mem->mapped_to_gpu_memory;
+   mutex_unlock(>lock);
+   /* lock is not needed after this, since mem is unused and will
+* be freed anyway
+*/
 
-   if (mem->mapped_to_gpu_memory > 0) {
+   if (mapped_to_gpu_memory > 0) {
pr_debug("BO VA 0x%llx size 0x%lx is still mapped.\n",
mem->va, bo_size);
-   mutex_unlock(>lock);
return -EBUSY;
}
 
-   mutex_unlock(>lock);
-   /* lock is not needed after this, since mem is unused and will
-* be freed anyway
-*/
-
/* No more MMU notifiers */
amdgpu_mn_unregister(mem->bo);
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V2] amdgpu, fix unnessary check "info" NULL branch

2020-04-20 Thread Bernard Zhao
kvfree ensure that the null pointer will do nothing.
If addr is NULL, first is_vmalloc_addr will not enter,
and kfree function just return when addr is NULL. There
will be no risk here.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index af91627b..814bd5d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -98,8 +98,7 @@ static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser 
*p,
return 0;
 
 error_free:
-   if (info)
-   kvfree(info);
+   kvfree(info);
 
return r;
 }
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amdgpu_cs_bo_handles_chunk, remove check info NULL branch

2020-04-19 Thread Bernard Zhao
kvfree ensure that the null pointer will do nothing.
If addr is NULL, first is_vmalloc_addr will not enter,
and kfree function just return when addr is NULL. There
will be no risk here.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index af91627b..814bd5d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -98,8 +98,7 @@ static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser 
*p,
return 0;
 
 error_free:
-   if (info)
-   kvfree(info);
+   kvfree(info);
 
return r;
 }
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amdgpu_connector_set_property, fix error branch not return errno

2020-04-19 Thread Bernard Zhao
The "if(!encoder)" branch return the same value 0 of the success
branch, maybe return -EINVAL is more better.

Signed-off-by: Bernard Zhao 
w
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index f355d9a..1f8c6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -474,12 +474,12 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
if (!amdgpu_encoder->enc_priv)
-   return 0;
+   return -EINVAL;
 
dig = amdgpu_encoder->enc_priv;
new_coherent_mode = val ? true : false;
@@ -494,7 +494,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -509,7 +509,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -523,7 +523,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -537,7 +537,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
@@ -551,7 +551,7 @@ static int amdgpu_connector_set_property(struct 
drm_connector *connector,
/* need to find digital encoder on connector */
encoder = amdgpu_connector_find_encoder(connector, 
DRM_MODE_ENCODER_TMDS);
if (!encoder)
-   return 0;
+   return -EINVAL;
 
amdgpu_encoder = to_amdgpu_encoder(encoder);
 
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] reserve_bo_and_cond_vms: Remove unnecessary condition check

2020-04-18 Thread Bernard Zhao
There is no need to if check again, maybe we could merge
into the above else branch.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 9dff792..327317c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -735,10 +735,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 false, >duplicates);
if (!ret)
ctx->reserved = true;
-   else
+   else {
pr_err("Failed to reserve buffers in ttm.\n");
-
-   if (ret) {
kfree(ctx->vm_pd);
ctx->vm_pd = NULL;
}
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] amdgpu_amdkfd_gpuvm_free_memory_of_gpu, reduce noneed mutex_lock area

2020-04-18 Thread Bernard Zhao
Maybe we could reduce the mutex_lock(>lock)`s protected code area,
and noneed to protect pr_debug.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 327317c..3c3769e5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1285,17 +1285,18 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
struct bo_vm_reservation_context ctx;
struct ttm_validate_buffer *bo_list_entry;
int ret;
+   unsigned int mapped_to_gpu_memory;
 
mutex_lock(>lock);
+   mapped_to_gpu_memory = mem->mapped_to_gpu_memory;
+   mutex_unlock(>lock);
 
-   if (mem->mapped_to_gpu_memory > 0) {
+   if (mapped_to_gpu_memory > 0) {
pr_debug("BO VA 0x%llx size 0x%lx is still mapped.\n",
mem->va, bo_size);
-   mutex_unlock(>lock);
return -EBUSY;
}
 
-   mutex_unlock(>lock);
/* lock is not needed after this, since mem is unused and will
 * be freed anyway
 */
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] Optimized division operation to shift operation

2020-04-14 Thread Bernard Zhao
On some processors, the / operate will call the compiler`s div lib,
which is low efficient, We can replace the / operation with shift,
so that we can replace the call of the division library with one
shift assembly instruction.

Signed-off-by: Bernard Zhao 
---
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index b205039..66cd078 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -175,10 +175,10 @@ static int gmc_v6_0_mc_load_microcode(struct 
amdgpu_device *adev)
amdgpu_ucode_print_mc_hdr(>header);
 
adev->gmc.fw_version = le32_to_cpu(hdr->header.ucode_version);
-   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
+   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) >> 3;
new_io_mc_regs = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->io_debug_array_offset_bytes));
-   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
+   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) >> 2;
new_fw_data = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->header.ucode_array_offset_bytes));
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 9da9596..ca26d63 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -193,10 +193,10 @@ static int gmc_v7_0_mc_load_microcode(struct 
amdgpu_device *adev)
amdgpu_ucode_print_mc_hdr(>header);
 
adev->gmc.fw_version = le32_to_cpu(hdr->header.ucode_version);
-   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
+   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) >> 3;
io_mc_regs = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->io_debug_array_offset_bytes));
-   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
+   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) >> 2;
fw_data = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->header.ucode_array_offset_bytes));
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 27d83204..295039c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -318,10 +318,10 @@ static int gmc_v8_0_tonga_mc_load_microcode(struct 
amdgpu_device *adev)
amdgpu_ucode_print_mc_hdr(>header);
 
adev->gmc.fw_version = le32_to_cpu(hdr->header.ucode_version);
-   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
+   regs_size = le32_to_cpu(hdr->io_debug_size_bytes) >> 3;
io_mc_regs = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->io_debug_array_offset_bytes));
-   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
+   ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) >> 2;
fw_data = (const __le32 *)
(adev->gmc.fw->data + 
le32_to_cpu(hdr->header.ucode_array_offset_bytes));
 
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx