Skip to contentSkip to conversation

Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

DISCUSSION Nathan Chancellor 7 participants 10 messages Mar 20, 2019 – Mar 21, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") introduces the following Clang warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                .block_id = info->head.block,
                            ~~~~~~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                .inject_error_type = info->head.type,
                                     ~~~~~~~~~~~^~~~

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Thank you,
Nathan

#1 lore raw

these two enumerated types are same for now. both of them might change in the future.

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") introduces the following Clang warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                .block_id = info->head.block,
                            ~~~~~~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                .inject_error_type = info->head.type,
                                     ~~~~~~~~~~~^~~~

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Thank you,
Nathan

#2 lore raw
Quoted 38 lines · Xinhui

these two enumerated types are same for now. both of them might change in the future.

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") introduces the following Clang warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                        .block_id =  head->block,
                                     ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                        .error_type = head->type,
                                      ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                .block_id = info->head.block,
                            ~~~~~~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                .inject_error_type = info->head.type,
                                     ~~~~~~~~~~~^~~~
Quoted 6 lines

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Thank you for the quick response!
Nathan

#3 lore raw

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 41 lines · Xinhui
Quoted 40 lines

these two enumerated types are same for now. both of them might change in the future.

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") introduces the following Clang warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

                         .block_id =  head->block,
                                      ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                         .error_type = head->type,
                                       ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                         .block_id =  head->block,
                                      ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                         .error_type = head->type,
                                       ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                 .block_id = info->head.block,
                             ~~~~~~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                 .inject_error_type = info->head.type,
                                      ~~~~~~~~~~~^~~~

6 warnings generated.

Quoted 8 lines
Quoted 4 lines

Normally, I would sent a fix for this myself but I am not entirely sure why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Another question is if it is such a good idea to just silence the warning?

Maybe add a amdgpu_ras_error_to_ta() helper to do this casting?

When the enums drift away from each other then we can still add warnings to that helper to make sure we don't accidentally cast invalid values around.

Regards,
Christian.

Quoted 3 lines

Thank you for the quick response!
Nathan

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw
In reply to a message not in the archive

Why are there 2 different enums for this same thing at all? By casting, you are reducing type safety in the kernel, which can cause bugs later (should the two enums diverge in encoding). In my opinion, the proper solution is to remove one of the enums or provide an explicit helper that does the conversion (along with assertions for handling any unexpected cases). The helper function should not be doing a direct cast, since a bug could change the integer value of one (or both) of these enums so that they don't match up.

Thanks,
Steve

Quoted 88 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 2 lines · Xinhui
Quoted 1 line

these two enumerated types are same for now. both of them might change

in the future.

Quoted 2 lines
Quoted 2 lines

I have not used clang, but would .block_id = (int)head->block fix

your warning? If such change is acceptable, I can make one then.

Quoted 9 lines
Quoted 9 lines

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <

[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>

Quoted 1 line
Quoted 1 line

[email protected]; clang-built-linux-/[email protected]

Quoted 5 lines
Quoted 5 lines

Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add

amdgpu_ras.c to support ras (v2)") introduces the following Clang

Quoted 3 lines
Quoted 3 lines

warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                 .block_id = info->head.block,
                             ~~~~~~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 5 lines
Quoted 5 lines
                 .inject_error_type = info->head.type,
                                      ~~~~~~~~~~~^~~~

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure

why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Quoted 7 lines
Quoted 3 lines

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Another question is if it is such a good idea to just silence the warning?

Maybe add a amdgpu_ras_error_to_ta() helper to do this casting?

When the enums drift away from each other then we can still add warnings to that helper to make sure we don't accidentally cast invalid values around.

Regards,
Christian.

Quoted 3 lines

Thank you for the quick response!
Nathan

Quoted 11 lines

--
You received this message because you are subscribed to the Google Groups
"Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to clang-built-linux+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to clang-built-linux-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web visit
https://groups.google.com/d/msgid/clang-built-linux/63518f1f-b808-77b0-aac6-ee1ece669c4b%40amd.com
.
For more options, visit https://groups.google.com/d/optout.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw

Resending as plain-text to rest of list.

Steve

Quoted 80 lines · Stephen Hines

Why are there 2 different enums for this same thing at all? By casting, you are reducing type safety in the kernel, which can cause bugs later (should the two enums diverge in encoding). In my opinion, the proper solution is to remove one of the enums or provide an explicit helper that does the conversion (along with assertions for handling any unexpected cases). The helper function should not be doing a direct cast, since a bug could change the integer value of one (or both) of these enums so that they don't match up.

Thanks,
Steve

Quoted 73 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 41 lines · Xinhui
Quoted 40 lines

these two enumerated types are same for now. both of them might change in the future.

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add amdgpu_ras.c to support ras (v2)") introduces the following Clang warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

                         .block_id =  head->block,
                                      ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                         .error_type = head->type,
                                       ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                         .block_id =  head->block,
                                      ~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                         .error_type = head->type,
                                       ~~~~~~^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]
                 .block_id = info->head.block,
                             ~~~~~~~~~~~^~~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]
                 .inject_error_type = info->head.type,
                                      ~~~~~~~~~~~^~~~

6 warnings generated.

Quoted 8 lines
Quoted 4 lines

Normally, I would sent a fix for this myself but I am not entirely sure why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Another question is if it is such a good idea to just silence the warning?

Maybe add a amdgpu_ras_error_to_ta() helper to do this casting?

When the enums drift away from each other then we can still add warnings to that helper to make sure we don't accidentally cast invalid values around.

Regards,
Christian.

Quoted 3 lines

Thank you for the quick response!
Nathan

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/63518f1f-b808-77b0-aac6-ee1ece669c4b%40amd.com.
For more options, visit https://groups.google.com/d/optout.

#7 lore raw
In reply to Stephen Hines
Quoted 9 lines · Stephen Hines

Why are there 2 different enums for this same thing at all? By casting, you are reducing type safety in the kernel, which can cause bugs later (should the two enums diverge in encoding). In my opinion, the proper solution is to remove one of the enums or provide an explicit helper that does the conversion (along with assertions for handling any unexpected cases). The helper function should not be doing a direct cast, since a bug could change the integer value of one (or both) of these enums so that they don't match up.

Quoted 3 lines

Thanks,
Steve

Indeed, I would suggest something like this (if this was to be a build time error, this would need to be a macro instead of a function):

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +6 -6
index a71668b8a7d0..451478cf4f35 100644
@@ -541,13 +541,13 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 
 	if (!enable) {
 		info.disable_features = (struct ta_ras_disable_features_input) {
-			.block_id =  head->block,
-			.error_type = head->type,
+			.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) {
-			.block_id =  head->block,
-			.error_type = head->type,
+			.block_id =  amdgpu_ras_block_to_ta(head->block),
+			.error_type = amdgpu_ras_error_to_ta(head->type),
 		};
 	}
 
@@ -647,8 +647,8 @@ int amdgpu_ras_error_inject(struct amdgpu_device *adev,
 {
 	struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
 	struct ta_ras_trigger_error_input block_info = {
-		.block_id = info->head.block,
-		.inject_error_type = info->head.type,
+		.block_id = amdgpu_ras_block_to_ta(info->head.block),
+		.inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
 		.sub_block_index = info->head.sub_block_index,
 		.address = info->address,
 		.value = info->value,
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +58 -0

64 lines not on this page · raw message

Quoted 102 lines
Quoted 99 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 2 lines · Xinhui
Quoted 1 line

these two enumerated types are same for now. both of them might change

in the future.

Quoted 2 lines
Quoted 2 lines

I have not used clang, but would .block_id = (int)head->block fix

your warning? If such change is acceptable, I can make one then.

Quoted 9 lines
Quoted 9 lines

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <

[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>

Quoted 1 line
Quoted 1 line

[email protected]; [email protected]

Quoted 5 lines
Quoted 5 lines

Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add

amdgpu_ras.c to support ras (v2)") introduces the following Clang

Quoted 3 lines
Quoted 3 lines

warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                 .block_id = info->head.block,
                             ~~~~~~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 5 lines
Quoted 5 lines
                 .inject_error_type = info->head.type,
                                      ~~~~~~~~~~~^~~~

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure

why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Quoted 7 lines
Quoted 3 lines

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Another question is if it is such a good idea to just silence the warning?

Maybe add a amdgpu_ras_error_to_ta() helper to do this casting?

When the enums drift away from each other then we can still add warnings to that helper to make sure we don't accidentally cast invalid values around.

Regards,
Christian.

Quoted 3 lines

Thank you for the quick response!
Nathan

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/clang-built-linux/63518f1f-b808-77b0-aac6-ee1ece669c4b%40amd.com
.
For more options, visit https://groups.google.com/d/optout.

#9 lore raw
In reply to Koenig, Christian
Quoted 4 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 2 lines · Xinhui
Quoted 1 line

these two enumerated types are same for now. both of them might change in the future.

Please consider if the YAGNI principle applies here.
https://martinfowler.com/bliki/Yagni.html

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

My preference on solutions, in order:
1. One enum (this is the simplest most type safe solution). Add another enum when you actually need it. Otherwise, YAGNI.
2. Safe casting function (like the one Nathan supplied, maybe with WARN_ONCE rather than WARN). This ensures that at least if the types diverge you get a runtime warning. A compile-time warning would be preferred, but I haven't taken the time to think through how that might be implemented.
3. Cast to int (this has been used in other places throughout the kernel, but provides the weakest type safety and doesn't catch future divergence).
4. Disabling the warning. (I almost never advocate for this).

Quoted 1 line

Another question is if it is such a good idea to just silence the warning?

For the kernel, it seems that each maintainer can choose what to apply to their subsystem. I would recommend against disabling additional warnings that aren't disable kernel-wide for most cases. -Wenum-conversion has spotted many bugs. While the enums in question today are not different, they MIGHT eventually diverge and lead to bugs, like the others we've found and fixed throughout the kernel. So I would recommend fixing now, and be insulated in the future.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#10 lore raw
Quoted 12 lines · Nick Desaulniers
Quoted 4 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 2 lines · Xinhui
Quoted 1 line

these two enumerated types are same for now. both of them might change in the future.

Please consider if the YAGNI principle applies here.
https://martinfowler.com/bliki/Yagni.html

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

I have not used clang, but would .block_id = (int)head->block fix your warning? If such change is acceptable, I can make one then.

My preference on solutions, in order:
1. One enum (this is the simplest most type safe solution). Add another enum when you actually need it. Otherwise, YAGNI.

It make sense to have two enums. One is a firmware interface that is only used by some asics and the other is for the general driver interface (non-asic specific for the ras features.

Quoted 5 lines

2. Safe casting function (like the one Nathan supplied, maybe with WARN_ONCE rather than WARN). This ensures that at least if the types diverge you get a runtime warning. A compile-time warning would be preferred, but I haven't taken the time to think through how that might be implemented.

I'd prefer this one.

Alex

Quoted 22 lines

3. Cast to int (this has been used in other places throughout the kernel, but provides the weakest type safety and doesn't catch future divergence).
4. Disabling the warning. (I almost never advocate for this).

Quoted 1 line

Another question is if it is such a good idea to just silence the warning?

For the kernel, it seems that each maintainer can choose what to apply to their subsystem. I would recommend against disabling additional warnings that aren't disable kernel-wide for most cases. -Wenum-conversion has spotted many bugs. While the enums in question today are not different, they MIGHT eventually diverge and lead to bugs, like the others we've found and fixed throughout the kernel. So I would recommend fixing now, and be insulated in the future.

--
Thanks,
~Nick Desaulniers
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#8 lore raw
In reply to Nathan Chancellor

I am going to apply your fix patch in my branch.

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 23:45
To: Stephen Hines <[email protected]>
Cc: Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; Zhou, David(ChunMing) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Quoted 9 lines · Stephen Hines

Why are there 2 different enums for this same thing at all? By casting, you are reducing type safety in the kernel, which can cause bugs later (should the two enums diverge in encoding). In my opinion, the proper solution is to remove one of the enums or provide an explicit helper that does the conversion (along with assertions for handling any unexpected cases). The helper function should not be doing a direct cast, since a bug could change the integer value of one (or both) of these enums so that they don't match up.

Quoted 3 lines

Thanks,
Steve

Indeed, I would suggest something like this (if this was to be a build time error, this would need to be a macro instead of a function):

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +6 -6
index a71668b8a7d0..451478cf4f35 100644
@@ -541,13 +541,13 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 
 	if (!enable) {
 		info.disable_features = (struct ta_ras_disable_features_input) {
-			.block_id =  head->block,
-			.error_type = head->type,
+			.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) {
-			.block_id =  head->block,
-			.error_type = head->type,
+			.block_id =  amdgpu_ras_block_to_ta(head->block),
+			.error_type = amdgpu_ras_error_to_ta(head->type),
 		};
 	}
 
@@ -647,8 +647,8 @@ int amdgpu_ras_error_inject(struct amdgpu_device *adev,  {
 	struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
 	struct ta_ras_trigger_error_input block_info = {
-		.block_id = info->head.block,
-		.inject_error_type = info->head.type,
+		.block_id = amdgpu_ras_block_to_ta(info->head.block),
+		.inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
 		.sub_block_index = info->head.sub_block_index,
 		.address = info->address,
 		.value = info->value,
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +56 -0

62 lines not on this page · raw message

Quoted 101 lines
Quoted 97 lines · Christian

Am 20.03.19 um 05:34 schrieb Nathan Chancellor:

Quoted 3 lines · Xinhui
Quoted 2 lines

these two enumerated types are same for now. both of them might change

in the future.

Quoted 3 lines
Quoted 3 lines

I have not used clang, but would .block_id = (int)head->block fix

your warning? If such change is acceptable, I can make one then.

Quoted 10 lines
Quoted 10 lines

Thanks
xinhui

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: 2019年3月20日 8:54
To: Deucher, Alexander <[email protected]>; Koenig, Christian <

[email protected]>; Zhou, David(ChunMing) <[email protected]>; Pan, Xinhui <[email protected]>

Quoted 2 lines
Quoted 2 lines

Cc: [email protected];
[email protected];

[email protected]; [email protected]

Quoted 6 lines
Quoted 6 lines

Subject: Clang warning in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

Hi all,

The introduction of this file in commit dbd249c24427 ("drm/amdgpu: add

amdgpu_ras.c to support ras (v2)") introduces the following Clang

Quoted 3 lines
Quoted 3 lines

warnings:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:544:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:545:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:549:23: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .block_id =  head->block,
                                      ~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:550:24: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                         .error_type = head->type,
                                       ~~~~~~^~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:650:26: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_block' to different enumeration type 'enum ta_ras_block' [-Wenum-conversion]

Quoted 3 lines
Quoted 3 lines
                 .block_id = info->head.block,
                             ~~~~~~~~~~~^~~~~

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:651:35: warning: implicit

conversion from enumeration type 'enum amdgpu_ras_error_type' to different enumeration type 'enum ta_ras_error_type' [-Wenum-conversion]

Quoted 6 lines
Quoted 6 lines
                 .inject_error_type = info->head.type,
                                      ~~~~~~~~~~~^~~~

6 warnings generated.

Normally, I would sent a fix for this myself but I am not entirely sure

why these two enumerated types exist when one would do since they have the same values minus the prefix. In fact, the ta_ras_{block,error_type} values are never used aside from being defined. Some clarification would be appreciated.

Quoted 7 lines
Quoted 3 lines

Thank you,
Nathan

Hi Xinhui,

Yes, explicitly casting these six spots to int would resolve this warning.

Another question is if it is such a good idea to just silence the warning?

Maybe add a amdgpu_ras_error_to_ta() helper to do this casting?

When the enums drift away from each other then we can still add warnings to that helper to make sure we don't accidentally cast invalid values around.

Regards,
Christian.

Quoted 3 lines

Thank you for the quick response!
Nathan

Quoted 12 lines
Quoted 12 lines

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/clang-built-linux/63518f1f-b808-77
b0-aac6-ee1ece669c4b%40amd.com
.
For more options, visit https://groups.google.com/d/optout.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx