All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] amdgpu: assign adev after null check
@ 2022-02-15  1:59 Qing Wang
  2022-02-15  8:58 ` Christian König
  0 siblings, 1 reply; 2+ messages in thread
From: Qing Wang @ 2022-02-15  1:59 UTC (permalink / raw)
  To: Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, amd-gfx, dri-devel, linux-kernel
  Cc: Wang Qing

From: Wang Qing <wangqing@vivo.com>

adev should be assigned after a null check

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 2c929fa..da114f7
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -259,12 +259,13 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
 static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
 					u32 *stable_pstate)
 {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
 	enum amd_dpm_forced_level current_level;
 
 	if (!ctx)
 		return -EINVAL;
 
+	adev = ctx->adev;
 	current_level = amdgpu_dpm_get_performance_level(adev);
 
 	switch (current_level) {
@@ -290,13 +291,14 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
 static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
 					u32 stable_pstate)
 {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
 	enum amd_dpm_forced_level level;
 	int r;
 
 	if (!ctx)
 		return -EINVAL;
 
+	adev = ctx->adev;
 	mutex_lock(&adev->pm.stable_pstate_ctx_lock);
 	if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
 		r = -EBUSY;
-- 
2.7.4


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

* Re: [PATCH] amdgpu: assign adev after null check
  2022-02-15  1:59 [PATCH] amdgpu: assign adev after null check Qing Wang
@ 2022-02-15  8:58 ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2022-02-15  8:58 UTC (permalink / raw)
  To: Qing Wang, Alex Deucher, Pan, Xinhui, David Airlie,
	Daniel Vetter, amd-gfx, dri-devel, linux-kernel

Am 15.02.22 um 02:59 schrieb Qing Wang:
> From: Wang Qing <wangqing@vivo.com>
>
> adev should be assigned after a null check

I would rather remove the NULL check altogether.

The caller is supposed to make sure that the context is valid and even 
if it isn't that's not a recoverable error here.

Regards,
Christian.

>
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> index 2c929fa..da114f7
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> @@ -259,12 +259,13 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
>   static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
>   					u32 *stable_pstate)
>   {
> -	struct amdgpu_device *adev = ctx->adev;
> +	struct amdgpu_device *adev;
>   	enum amd_dpm_forced_level current_level;
>   
>   	if (!ctx)
>   		return -EINVAL;
>   
> +	adev = ctx->adev;
>   	current_level = amdgpu_dpm_get_performance_level(adev);
>   
>   	switch (current_level) {
> @@ -290,13 +291,14 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
>   static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
>   					u32 stable_pstate)
>   {
> -	struct amdgpu_device *adev = ctx->adev;
> +	struct amdgpu_device *adev;
>   	enum amd_dpm_forced_level level;
>   	int r;
>   
>   	if (!ctx)
>   		return -EINVAL;
>   
> +	adev = ctx->adev;
>   	mutex_lock(&adev->pm.stable_pstate_ctx_lock);
>   	if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
>   		r = -EBUSY;


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

end of thread, other threads:[~2022-02-15  8:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15  1:59 [PATCH] amdgpu: assign adev after null check Qing Wang
2022-02-15  8:58 ` Christian König

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