dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: allocate large structures dynamically
@ 2020-05-05 14:01 Arnd Bergmann
  2020-05-05 14:07 ` Christian König
  2020-05-06 19:01 ` Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2020-05-05 14:01 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David (ChunMing) Zhou,
	David Airlie, Daniel Vetter, Hawking Zhang, John Clements
  Cc: Arnd Bergmann, Guchun Chen, Tao Zhou, linux-kernel, amd-gfx,
	dri-devel, Dennis Li

After the structure was padded to 1024 bytes, it is no longer
suitable for being a local variable, as the function surpasses
the warning limit for 32-bit architectures:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:587:5: error: stack frame size of 1072 bytes in function 'amdgpu_ras_feature_enable' [-Werror,-Wframe-larger-than=]
int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
    ^

Use kzalloc() instead to get it from the heap.

Fixes: a0d254820f43 ("drm/amdgpu: update RAS TA to Host interface")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 31 +++++++++++++++++--------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 538895cfd862..7348619253c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -588,19 +588,23 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 		struct ras_common_if *head, bool enable)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
-	union ta_ras_cmd_input info;
+	union ta_ras_cmd_input *info;
 	int ret;
 
 	if (!con)
 		return -EINVAL;
 
+        info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
 	if (!enable) {
-		info.disable_features = (struct ta_ras_disable_features_input) {
+		info->disable_features = (struct ta_ras_disable_features_input) {
 			.block_id =  amdgpu_ras_block_to_ta(head->block),
 			.error_type = amdgpu_ras_error_to_ta(head->type),
 		};
 	} else {
-		info.enable_features = (struct ta_ras_enable_features_input) {
+		info->enable_features = (struct ta_ras_enable_features_input) {
 			.block_id =  amdgpu_ras_block_to_ta(head->block),
 			.error_type = amdgpu_ras_error_to_ta(head->type),
 		};
@@ -609,26 +613,33 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 	/* Do not enable if it is not allowed. */
 	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
 	/* Are we alerady in that state we are going to set? */
-	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
-		return 0;
+	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head))) {
+		ret = 0;
+		goto out;
+	}
 
 	if (!amdgpu_ras_intr_triggered()) {
-		ret = psp_ras_enable_features(&adev->psp, &info, enable);
+		ret = psp_ras_enable_features(&adev->psp, info, enable);
 		if (ret) {
 			amdgpu_ras_parse_status_code(adev,
 						     enable ? "enable":"disable",
 						     ras_block_str(head->block),
 						    (enum ta_ras_status)ret);
 			if (ret == TA_RAS_STATUS__RESET_NEEDED)
-				return -EAGAIN;
-			return -EINVAL;
+				ret = -EAGAIN;
+			else
+				ret = -EINVAL;
+
+			goto out;
 		}
 	}
 
 	/* setup the obj */
 	__amdgpu_ras_feature_enable(adev, head, enable);
-
-	return 0;
+	ret = 0;
+out:
+	kfree(info);
+	return ret;
 }
 
 /* Only used in device probe stage and called only once. */
-- 
2.26.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/amdgpu: allocate large structures dynamically
  2020-05-05 14:01 [PATCH] drm/amdgpu: allocate large structures dynamically Arnd Bergmann
@ 2020-05-05 14:07 ` Christian König
  2020-05-05 15:34   ` Alex Deucher
  2020-05-06 19:01 ` Joe Perches
  1 sibling, 1 reply; 6+ messages in thread
From: Christian König @ 2020-05-05 14:07 UTC (permalink / raw)
  To: Arnd Bergmann, Alex Deucher, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Hawking Zhang, John Clements
  Cc: Guchun Chen, Tao Zhou, linux-kernel, amd-gfx, dri-devel, Dennis Li

Am 05.05.20 um 16:01 schrieb Arnd Bergmann:
> After the structure was padded to 1024 bytes, it is no longer
> suitable for being a local variable, as the function surpasses
> the warning limit for 32-bit architectures:
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:587:5: error: stack frame size of 1072 bytes in function 'amdgpu_ras_feature_enable' [-Werror,-Wframe-larger-than=]
> int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>      ^
>
> Use kzalloc() instead to get it from the heap.
>
> Fixes: a0d254820f43 ("drm/amdgpu: update RAS TA to Host interface")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Christian König <christian.koenig@amd.com>

We have a bunch of those warnings in the DAL code as well.

Christian.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 31 +++++++++++++++++--------
>   1 file changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> index 538895cfd862..7348619253c7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> @@ -588,19 +588,23 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>   		struct ras_common_if *head, bool enable)
>   {
>   	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
> -	union ta_ras_cmd_input info;
> +	union ta_ras_cmd_input *info;
>   	int ret;
>   
>   	if (!con)
>   		return -EINVAL;
>   
> +        info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
> +	if (!info)
> +		return -ENOMEM;
> +
>   	if (!enable) {
> -		info.disable_features = (struct ta_ras_disable_features_input) {
> +		info->disable_features = (struct ta_ras_disable_features_input) {
>   			.block_id =  amdgpu_ras_block_to_ta(head->block),
>   			.error_type = amdgpu_ras_error_to_ta(head->type),
>   		};
>   	} else {
> -		info.enable_features = (struct ta_ras_enable_features_input) {
> +		info->enable_features = (struct ta_ras_enable_features_input) {
>   			.block_id =  amdgpu_ras_block_to_ta(head->block),
>   			.error_type = amdgpu_ras_error_to_ta(head->type),
>   		};
> @@ -609,26 +613,33 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>   	/* Do not enable if it is not allowed. */
>   	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
>   	/* Are we alerady in that state we are going to set? */
> -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> -		return 0;
> +	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head))) {
> +		ret = 0;
> +		goto out;
> +	}
>   
>   	if (!amdgpu_ras_intr_triggered()) {
> -		ret = psp_ras_enable_features(&adev->psp, &info, enable);
> +		ret = psp_ras_enable_features(&adev->psp, info, enable);
>   		if (ret) {
>   			amdgpu_ras_parse_status_code(adev,
>   						     enable ? "enable":"disable",
>   						     ras_block_str(head->block),
>   						    (enum ta_ras_status)ret);
>   			if (ret == TA_RAS_STATUS__RESET_NEEDED)
> -				return -EAGAIN;
> -			return -EINVAL;
> +				ret = -EAGAIN;
> +			else
> +				ret = -EINVAL;
> +
> +			goto out;
>   		}
>   	}
>   
>   	/* setup the obj */
>   	__amdgpu_ras_feature_enable(adev, head, enable);
> -
> -	return 0;
> +	ret = 0;
> +out:
> +	kfree(info);
> +	return ret;
>   }
>   
>   /* Only used in device probe stage and called only once. */

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/amdgpu: allocate large structures dynamically
  2020-05-05 14:07 ` Christian König
@ 2020-05-05 15:34   ` Alex Deucher
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2020-05-05 15:34 UTC (permalink / raw)
  To: Christian König
  Cc: Guchun Chen, Arnd Bergmann, David Airlie, Tao Zhou, LKML,
	amd-gfx list, Maling list - DRI developers, Alex Deucher,
	John Clements, Dennis Li, Hawking Zhang

On Tue, May 5, 2020 at 10:07 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 05.05.20 um 16:01 schrieb Arnd Bergmann:
> > After the structure was padded to 1024 bytes, it is no longer
> > suitable for being a local variable, as the function surpasses
> > the warning limit for 32-bit architectures:
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:587:5: error: stack frame size of 1072 bytes in function 'amdgpu_ras_feature_enable' [-Werror,-Wframe-larger-than=]
> > int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
> >      ^
> >
> > Use kzalloc() instead to get it from the heap.
> >
> > Fixes: a0d254820f43 ("drm/amdgpu: update RAS TA to Host interface")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Acked-by: Christian König <christian.koenig@amd.com>

Applied.  Thanks!

Alex

>
> We have a bunch of those warnings in the DAL code as well.
>
> Christian.
>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 31 +++++++++++++++++--------
> >   1 file changed, 21 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> > index 538895cfd862..7348619253c7 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> > @@ -588,19 +588,23 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
> >               struct ras_common_if *head, bool enable)
> >   {
> >       struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
> > -     union ta_ras_cmd_input info;
> > +     union ta_ras_cmd_input *info;
> >       int ret;
> >
> >       if (!con)
> >               return -EINVAL;
> >
> > +        info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
> > +     if (!info)
> > +             return -ENOMEM;
> > +
> >       if (!enable) {
> > -             info.disable_features = (struct ta_ras_disable_features_input) {
> > +             info->disable_features = (struct ta_ras_disable_features_input) {
> >                       .block_id =  amdgpu_ras_block_to_ta(head->block),
> >                       .error_type = amdgpu_ras_error_to_ta(head->type),
> >               };
> >       } else {
> > -             info.enable_features = (struct ta_ras_enable_features_input) {
> > +             info->enable_features = (struct ta_ras_enable_features_input) {
> >                       .block_id =  amdgpu_ras_block_to_ta(head->block),
> >                       .error_type = amdgpu_ras_error_to_ta(head->type),
> >               };
> > @@ -609,26 +613,33 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
> >       /* Do not enable if it is not allowed. */
> >       WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
> >       /* Are we alerady in that state we are going to set? */
> > -     if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> > -             return 0;
> > +     if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head))) {
> > +             ret = 0;
> > +             goto out;
> > +     }
> >
> >       if (!amdgpu_ras_intr_triggered()) {
> > -             ret = psp_ras_enable_features(&adev->psp, &info, enable);
> > +             ret = psp_ras_enable_features(&adev->psp, info, enable);
> >               if (ret) {
> >                       amdgpu_ras_parse_status_code(adev,
> >                                                    enable ? "enable":"disable",
> >                                                    ras_block_str(head->block),
> >                                                   (enum ta_ras_status)ret);
> >                       if (ret == TA_RAS_STATUS__RESET_NEEDED)
> > -                             return -EAGAIN;
> > -                     return -EINVAL;
> > +                             ret = -EAGAIN;
> > +                     else
> > +                             ret = -EINVAL;
> > +
> > +                     goto out;
> >               }
> >       }
> >
> >       /* setup the obj */
> >       __amdgpu_ras_feature_enable(adev, head, enable);
> > -
> > -     return 0;
> > +     ret = 0;
> > +out:
> > +     kfree(info);
> > +     return ret;
> >   }
> >
> >   /* Only used in device probe stage and called only once. */
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/amdgpu: allocate large structures dynamically
  2020-05-05 14:01 [PATCH] drm/amdgpu: allocate large structures dynamically Arnd Bergmann
  2020-05-05 14:07 ` Christian König
@ 2020-05-06 19:01 ` Joe Perches
  2020-05-07  6:42   ` Christian König
  1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2020-05-06 19:01 UTC (permalink / raw)
  To: Arnd Bergmann, Alex Deucher, Christian König,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Hawking Zhang, John Clements
  Cc: Guchun Chen, Tao Zhou, linux-kernel, amd-gfx, dri-devel, Dennis Li

On Tue, 2020-05-05 at 16:01 +0200, Arnd Bergmann wrote:
> After the structure was padded to 1024 bytes, it is no longer
> suitable for being a local variable, as the function surpasses
> the warning limit for 32-bit architectures:
> 
> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:587:5: error: stack frame size of 1072 bytes in function 'amdgpu_ras_feature_enable' [-Werror,-Wframe-larger-than=]
> int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>     ^
> 
> Use kzalloc() instead to get it from the heap.
[]
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
[]
> @@ -588,19 +588,23 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>  		struct ras_common_if *head, bool enable)
>  {
>  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
> -	union ta_ras_cmd_input info;
> +	union ta_ras_cmd_input *info;
>  	int ret;
>  
>  	if (!con)
>  		return -EINVAL;
>  
> +        info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);

Spaces were used for indentation here not a tab.
It might be useful to run your proposed patches through checkpatch

Is this an actual bug fix as the previous use didn't
zero unused info members?

> +	if (!info)
> +		return -ENOMEM;
> +
>  	if (!enable) {
> -		info.disable_features = (struct ta_ras_disable_features_input) {
> +		info->disable_features = (struct ta_ras_disable_features_input) {
>  			.block_id =  amdgpu_ras_block_to_ta(head->block),
>  			.error_type = amdgpu_ras_error_to_ta(head->type),
>  		};
>  	} else {
> -		info.enable_features = (struct ta_ras_enable_features_input) {
> +		info->enable_features = (struct ta_ras_enable_features_input) {
>  			.block_id =  amdgpu_ras_block_to_ta(head->block),
>  			.error_type = amdgpu_ras_error_to_ta(head->type),
>  		};
> @@ -609,26 +613,33 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>  	/* Do not enable if it is not allowed. */
>  	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
>  	/* Are we alerady in that state we are going to set? */
> -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> -		return 0;
> +	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head))) {

And trivia:

The !! uses with bool seem unnecessary and it's probably better
to make amdgpu_ras_is_feature_enabled to return bool.

Maybe something like:
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 538895cfd862..05c4eaf0ddfa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -526,16 +526,16 @@ void amdgpu_ras_parse_status_code(struct amdgpu_device* adev,
 }
 
 /* feature ctl begin */
-static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
-		struct ras_common_if *head)
+static bool amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
+					  struct ras_common_if *head)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 
 	return con->hw_supported & BIT(head->block);
 }
 
-static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
-		struct ras_common_if *head)
+static bool amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
+					  struct ras_common_if *head)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 
@@ -560,7 +560,7 @@ static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 	 */
 	if (!amdgpu_ras_is_feature_allowed(adev, head))
 		return 0;
-	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
+	if (!(enable ^ amdgpu_ras_is_feature_enabled(adev, head)))
 		return 0;
 
 	if (enable) {
@@ -609,7 +609,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 	/* Do not enable if it is not allowed. */
 	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
 	/* Are we alerady in that state we are going to set? */
-	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
+	if (!(enable ^ amdgpu_ras_is_feature_enabled(adev, head)))
 		return 0;
 
 	if (!amdgpu_ras_intr_triggered()) {



_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/amdgpu: allocate large structures dynamically
  2020-05-06 19:01 ` Joe Perches
@ 2020-05-07  6:42   ` Christian König
  2020-05-07  6:55     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2020-05-07  6:42 UTC (permalink / raw)
  To: Joe Perches, Arnd Bergmann, Alex Deucher, Christian König,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Hawking Zhang, John Clements
  Cc: Guchun Chen, Tao Zhou, linux-kernel, amd-gfx, dri-devel, Dennis Li

Am 06.05.20 um 21:01 schrieb Joe Perches:
> On Tue, 2020-05-05 at 16:01 +0200, Arnd Bergmann wrote:
>> After the structure was padded to 1024 bytes, it is no longer
>> suitable for being a local variable, as the function surpasses
>> the warning limit for 32-bit architectures:
>>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:587:5: error: stack frame size of 1072 bytes in function 'amdgpu_ras_feature_enable' [-Werror,-Wframe-larger-than=]
>> int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>>      ^
>>
>> Use kzalloc() instead to get it from the heap.
> []
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> []
>> @@ -588,19 +588,23 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>>   		struct ras_common_if *head, bool enable)
>>   {
>>   	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
>> -	union ta_ras_cmd_input info;
>> +	union ta_ras_cmd_input *info;
>>   	int ret;
>>   
>>   	if (!con)
>>   		return -EINVAL;
>>   
>> +        info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
> Spaces were used for indentation here not a tab.
> It might be useful to run your proposed patches through checkpatch
>
> Is this an actual bug fix as the previous use didn't
> zero unused info members?
>
>> +	if (!info)
>> +		return -ENOMEM;
>> +
>>   	if (!enable) {
>> -		info.disable_features = (struct ta_ras_disable_features_input) {
>> +		info->disable_features = (struct ta_ras_disable_features_input) {
>>   			.block_id =  amdgpu_ras_block_to_ta(head->block),
>>   			.error_type = amdgpu_ras_error_to_ta(head->type),
>>   		};
>>   	} else {
>> -		info.enable_features = (struct ta_ras_enable_features_input) {
>> +		info->enable_features = (struct ta_ras_enable_features_input) {
>>   			.block_id =  amdgpu_ras_block_to_ta(head->block),
>>   			.error_type = amdgpu_ras_error_to_ta(head->type),
>>   		};
>> @@ -609,26 +613,33 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>>   	/* Do not enable if it is not allowed. */
>>   	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
>>   	/* Are we alerady in that state we are going to set? */
>> -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
>> -		return 0;
>> +	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head))) {
> And trivia:
>
> The !! uses with bool seem unnecessary and it's probably better
> to make amdgpu_ras_is_feature_enabled to return bool.
>
> Maybe something like:
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> index 538895cfd862..05c4eaf0ddfa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> @@ -526,16 +526,16 @@ void amdgpu_ras_parse_status_code(struct amdgpu_device* adev,
>   }
>   
>   /* feature ctl begin */
> -static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
> -		struct ras_common_if *head)
> +static bool amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
> +					  struct ras_common_if *head)
>   {
>   	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
>   
>   	return con->hw_supported & BIT(head->block);
>   }
>   
> -static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
> -		struct ras_common_if *head)
> +static bool amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
> +					  struct ras_common_if *head)
>   {
>   	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
>   
> @@ -560,7 +560,7 @@ static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>   	 */
>   	if (!amdgpu_ras_is_feature_allowed(adev, head))
>   		return 0;
> -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> +	if (!(enable ^ amdgpu_ras_is_feature_enabled(adev, head)))

And while we are at improving coding style I think that writing this as 
"if (enabled == amdgpu_ras_is_feature_enabled(adev, head))" would be 
much more readable.

Christian.

>   		return 0;
>   
>   	if (enable) {
> @@ -609,7 +609,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
>   	/* Do not enable if it is not allowed. */
>   	WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
>   	/* Are we alerady in that state we are going to set? */
> -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> +	if (!(enable ^ amdgpu_ras_is_feature_enabled(adev, head)))
>   		return 0;
>   
>   	if (!amdgpu_ras_intr_triggered()) {
>
>
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/amdgpu: allocate large structures dynamically
  2020-05-07  6:42   ` Christian König
@ 2020-05-07  6:55     ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2020-05-07  6:55 UTC (permalink / raw)
  To: christian.koenig, Arnd Bergmann, Alex Deucher,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Hawking Zhang, John Clements
  Cc: Guchun Chen, Tao Zhou, linux-kernel, amd-gfx, dri-devel, Dennis Li

On Thu, 2020-05-07 at 08:42 +0200, Christian König wrote:
> Am 06.05.20 um 21:01 schrieb Joe Perches:
[]
> > And trivia:
> > 
> > The !! uses with bool seem unnecessary and it's probably better
> > to make amdgpu_ras_is_feature_enabled to return bool.
[]
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
[]
> > @@ -560,7 +560,7 @@ static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
> >   	 */
> >   	if (!amdgpu_ras_is_feature_allowed(adev, head))
> >   		return 0;
> > -	if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
> > +	if (!(enable ^ amdgpu_ras_is_feature_enabled(adev, head)))
> 
> And while we are at improving coding style I think that writing this as 
> "if (enabled == amdgpu_ras_is_feature_enabled(adev, head))" would be 
> much more readable.

<blink, chuckle> that's decidedly true...


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2020-05-07  6:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 14:01 [PATCH] drm/amdgpu: allocate large structures dynamically Arnd Bergmann
2020-05-05 14:07 ` Christian König
2020-05-05 15:34   ` Alex Deucher
2020-05-06 19:01 ` Joe Perches
2020-05-07  6:42   ` Christian König
2020-05-07  6:55     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).