Skip to contentSkip to conversation

drm/amd/display: Pass app_tf by value rather than by reference

PATCH Applied Nathan Chancellor 5 participants 10 messages Dec 10, 2018 – Feb 28, 2019

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

PATCH 1/1 drm/amd/display: Pass app_tf by value rather than by reference

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
 		const struct mod_vrr_params *vrr,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket)
 {
 	unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
 	build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
 	build_vrr_infopacket_data(vrr, infopacket);
 
-	if (app_tf != NULL)
-		build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+	build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
 	build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
 		const struct dc_stream_state *stream,
 		const struct mod_vrr_params *vrr,
 		enum vrr_packet_type packet_type,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket)
 {
 	/* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
index 949a8b62aa98..063af6258fd9 100644
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
 		const struct dc_stream_state *stream,
 		const struct mod_vrr_params *vrr,
 		enum vrr_packet_type packet_type,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket);
 
 void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
Signature · 1 line
2.20.0
#1 lore raw
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

- NULL,
+ transfer_func_unknown,

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Either way, I suspect without the change to drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c, that this fails to compile?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 31 lines · Nick Desaulniers
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 9 lines
Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time to do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Thanks for confirming!

Quoted 55 lines
Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

Review

Quoted 2 lines
(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Quoted 3 lines

Either way, I suspect without the change to drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c, that this fails to compile?

Correct so this is targeted at -next, rather than mainline, probably should get in the habit of adding '-next' to my patch subjects...

Quoted 3 lines
Signature · 2 lines
Thanks,
~Nick Desaulniers

Thank you for the review!
Nathan

Reviewed-by
#3 lore raw
Quoted 107 lines · Nathan Chancellor
Quoted 31 lines · Nick Desaulniers
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 9 lines
Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time to do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Thanks for confirming!

Quoted 54 lines
Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

Ah! Sorry, I was looking at mainline. I should have noticed bb47de736661 wasn't there.

Shouldn't that change fail to compile, as transfer_func_unknown is an enum color_transfer_func value, but mod_freesync_build_vrr_infopacket takes a *pointer* to an enum color_transfer_func value?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/amd/display/modules/freesync/freesync.c#n675

Quoted 24 lines
        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

Quoted 2 lines

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Don't worry about it, I think it's fine.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw
Quoted 117 lines · Nick Desaulniers
Quoted 107 lines · Nathan Chancellor
Quoted 31 lines · Nick Desaulniers
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 9 lines
Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time to do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Thanks for confirming!

Quoted 54 lines
Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

Quoted 9 lines

Ah! Sorry, I was looking at mainline. I should have noticed bb47de736661 wasn't there.

Shouldn't that change fail to compile, as transfer_func_unknown is an enum color_transfer_func value, but mod_freesync_build_vrr_infopacket takes a *pointer* to an enum color_transfer_func value?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/amd/display/modules/freesync/freesync.c#n675

Unfortunately, no. GCC does not warn like Clang does when an expression that equals zero is passed to a function requiring a pointer (it just silently treats it as NULL, whereas Clang audibly complains).

They both do when the expression is something other than zero.

https://godbolt.org/z/goo91G

Nathan

Quoted 33 lines
Quoted 24 lines
        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

Quoted 2 lines

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Don't worry about it, I think it's fine.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw
Quoted 149 lines · Nathan Chancellor
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines · Nathan Chancellor

On Tue, Dec 11, 2018 at 01:25:00PM -0800, Nick Desaulniers wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null

pointer

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set

FreeSync

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

state using drm VRR properties") and it could be solved by using

NULL

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN

as a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointer. However, after looking into it, there doesn't appear to

be a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

good reason to pass app_tf by reference as it is never mutated

along the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or

build_vrr_infopacket_v2

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

modify app_tf's value and build_vrr_infopacket_fs2_data expects

just

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the

same

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

as not calling build_vrr_infopacket_fs2_data at all like before

this

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review

sooner,

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time

to

Quoted 7 lines
Quoted 7 lines

do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Quoted 6 lines
Quoted 6 lines

Thanks for confirming!

Quoted 4 lines
Quoted 4 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7

+++----

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git

a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/modules/freesync/freesync.c static void build_vrr_infopacket_v1(enum

Quoted 4 lines

index 620a171620ee..520665a9d81a 100644

drivers/gpu/drm/amd/display/modules/freesync/freesync.c +0 -0
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum

signal_type signal,

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/display/modules/freesync/freesync.c static void build_vrr_infopacket_v2(enum

Quoted 9 lines
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +1 -1
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum

signal_type signal,

Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/display/modules/freesync/freesync.c static void build_vrr_infopacket_v2(enum · line 664

Quoted 1 line
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +0 -0
        build_vrr_infopacket_header_v2(signal, infopacket,

&payload_size);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/display/modules/freesync/freesync.c void mod_freesync_build_vrr_infopacket(struct

Quoted 9 lines
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +1 -2
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct

mod_freesync *mod_freesync,

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +1 -1
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */

diff --git

a/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h b/drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct

Quoted 4 lines

index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct

mod_freesync *mod_freesync,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of

mod_freesync_build_vrr_infopacket in

Quoted 11 lines
Quoted 10 lines

Review

Quoted 6 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

Quoted 8 lines

Ah! Sorry, I was looking at mainline. I should have noticed bb47de736661 wasn't there.

Shouldn't that change fail to compile, as transfer_func_unknown is an enum color_transfer_func value, but mod_freesync_build_vrr_infopacket takes a *pointer* to an enum color_transfer_func value?

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/amd/display/modules/freesync/freesync.c#n675

Quoted 1 line

Unfortunately, no. GCC does not warn like Clang does when an expression that equals zero is passed to a function requiring a pointer (it just silently treats it as NULL, whereas Clang audibly complains).

That C allows this is troubling to me. I may need to go seek therapy to deal with my anguish this has caused me...

Quoted 41 lines

They both do when the expression is something other than zero.

https://godbolt.org/z/goo91G

Nathan

Quoted 33 lines
Quoted 24 lines
        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

Quoted 2 lines

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Don't worry about it, I think it's fine.

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers

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

maintainer Reviewed-by
#6 lore raw
In reply to Nick Desaulniers
Quoted 150 lines · Nick Desaulniers
Quoted 107 lines · Nathan Chancellor
Quoted 31 lines · Nick Desaulniers
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 9 lines
Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time to do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Thanks for confirming!

Quoted 54 lines
Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

Ah! Sorry, I was looking at mainline. I should have noticed bb47de736661 wasn't there.

Shouldn't that change fail to compile, as transfer_func_unknown is an enum color_transfer_func value, but mod_freesync_build_vrr_infopacket takes a *pointer* to an enum color_transfer_func value?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/amd/display/modules/freesync/freesync.c#n675

Quoted 24 lines
        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

Quoted 6 lines
Quoted 2 lines

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Don't worry about it, I think it's fine.

Sorry for being late to the game. FWIW, code is also

We can change the comparison separately later.

Not sure why this was ever passed as a pointer.

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

#7 lore raw
Quoted 158 lines · Harry
Quoted 150 lines · Nick Desaulniers
Quoted 107 lines · Nathan Chancellor
Quoted 31 lines · Nick Desaulniers
Quoted 29 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

Quoted 9 lines
Quoted 4 lines

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

Nathan,
Thanks for sending this patch. I was hoping to provide review sooner, but have been quite busy lately.

Late review is better than no review, I appeciate you taking the time to do this!

Quoted 4 lines

Yeah, especially for LP64 targets, the pointer to enum is larger than just the enum, and if it's not being updated ("in/out paramter") there's no need to pass by pointer.

Thanks for confirming!

Quoted 54 lines
Quoted 44 lines
---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
                const struct mod_vrr_params *vrr,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
        build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
        build_vrr_infopacket_data(vrr, infopacket);
 
-       if (app_tf != NULL)
-               build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+       build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
        build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,
                struct dc_info_packet *infopacket)
 {
        /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +0 -0
index 949a8b62aa98..063af6258fd9 100644

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, · line 148

Quoted 5 lines
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
                const struct dc_stream_state *stream,
                const struct mod_vrr_params *vrr,
                enum vrr_packet_type packet_type,
-               const enum color_transfer_func *app_tf,
+               enum color_transfer_func app_tf,

Don't you need to update the callsite of mod_freesync_build_vrr_infopacket in

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c#4949:

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
-                                           NULL,
+                                          transfer_func_unknown,

That change in commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") in -next is what prompted this patch (the warning in the commit message is not present in mainline):

Ah! Sorry, I was looking at mainline. I should have noticed bb47de736661 wasn't there.

Shouldn't that change fail to compile, as transfer_func_unknown is an enum color_transfer_func value, but mod_freesync_build_vrr_infopacket takes a *pointer* to an enum color_transfer_func value?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/amd/display/modules/freesync/freesync.c#n675

Quoted 24 lines
        mod_freesync_build_vrr_infopacket(
                dm->freesync_module,
                new_stream,
                &vrr,
                packet_type_vrr,
                transfer_func_unknown,
                &vrr_infopacket);
Quoted 6 lines

Maybe at that point the if (app_tf != NULL) could be replaced with if (app_tf != transfer_func_unknown) hoisted from build_vrr_infopacket_fs2_data? (There's only one caller of build_vrr_infopacket_fs2_data today, maybe fine to leave the unconditional call and check).

Hmmm that's not unreasonable I suppose. I guess it depends on if build_vrr_infopacket_fs2_data could ever be called from outside of build_vrr_infopacket_v2; if it can, it makes sense to leave the conditional check for 'app_tf != transfer_func_unknown' in build_vrr_infopacket_fs2_data and leaving the unconditional call to it in build_vrr_infopacket_v2 (since app_tf is no longer a pointer, no need to check against NULL).

Quoted 6 lines
Quoted 2 lines

I'm happy to do a v2 if the maintainers feel strongly about it, thank you for bringing that up.

Don't worry about it, I think it's fine.

Quoted 8 lines

Sorry for being late to the game. FWIW, code is also

We can change the comparison separately later.

Not sure why this was ever passed as a pointer.

Harry

Thanks Harry, could you (or someone) pick this up? This warning is now in mainline.

Nathan

#8 lore raw
In reply to Nathan Chancellor
Quoted 87 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
 		const struct mod_vrr_params *vrr,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket)
 {
 	unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
 	build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
 	build_vrr_infopacket_data(vrr, infopacket);
 
-	if (app_tf != NULL)
-		build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+	build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
 	build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
 		const struct dc_stream_state *stream,
 		const struct mod_vrr_params *vrr,
 		enum vrr_packet_type packet_type,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket)
 {
 	/* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -1
index 949a8b62aa98..063af6258fd9 100644
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
 		const struct dc_stream_state *stream,
 		const struct mod_vrr_params *vrr,
 		enum vrr_packet_type packet_type,
-		const enum color_transfer_func *app_tf,
+		enum color_transfer_func app_tf,
 		struct dc_info_packet *infopacket);
 
 void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
Signature · 1 line
2.20.0

Gentle ping on this patch, it would be nice to get this fixed and into 5.1!

Thanks,
Nathan

Applied
#9 lore raw

Applied. Sorry for the delay.

Alex

Quoted 99 lines · Nathan Chancellor
Quoted 85 lines · Nathan Chancellor

Clang warns when an expression that equals zero is used as a null pointer constant (in lieu of NULL):

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:4435:3:
warning: expression which evaluates to zero treated as a null pointer constant of type 'const enum color_transfer_func *' [-Wnon-literal-null-conversion]

                TRANSFER_FUNC_UNKNOWN,
                ^~~~~~~~~~~~~~~~~~~~~

1 warning generated.

This warning is caused by commit bb47de736661 ("drm/amdgpu: Set FreeSync state using drm VRR properties") and it could be solved by using NULL instead of TRANSFER_FUNC_UNKNOWN or casting TRANSFER_FUNC_UNKNOWN as a pointer. However, after looking into it, there doesn't appear to be a good reason to pass app_tf by reference as it is never mutated along the way. This is the only code path in which app_tf is used:

mod_freesync_build_vrr_infopacket ->

    build_vrr_infopacket_v2 ->
        build_vrr_infopacket_fs2_data

Neither mod_freesync_build_vrr_infopacket or build_vrr_infopacket_v2 modify app_tf's value and build_vrr_infopacket_fs2_data expects just the value so we can avoid dereferencing anything by just passing in app_tf's value to mod_freesync_build_vrr_infopacket and build_vrr_infopacket_v2.

There is no functional change because build_vrr_infopacket_fs2_data doesn't do anything if TRANSFER_FUNC_UNKNOWN is passed to it, the same as not calling build_vrr_infopacket_fs2_data at all like before this change when NULL was used for app_tf.

---
 drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 7 +++----
 drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/modules/freesync/freesync.c +3 -4
index 620a171620ee..520665a9d81a 100644
@@ -656,7 +656,7 @@ static void build_vrr_infopacket_v1(enum signal_type signal,
 
 static void build_vrr_infopacket_v2(enum signal_type signal,
              const struct mod_vrr_params *vrr,
-             const enum color_transfer_func *app_tf,
+             enum color_transfer_func app_tf,
              struct dc_info_packet *infopacket)
 {
      unsigned int payload_size = 0;
@@ -664,8 +664,7 @@ static void build_vrr_infopacket_v2(enum signal_type signal,
      build_vrr_infopacket_header_v2(signal, infopacket, &payload_size);
      build_vrr_infopacket_data(vrr, infopacket);
 
-     if (app_tf != NULL)
-             build_vrr_infopacket_fs2_data(*app_tf, infopacket);
+     build_vrr_infopacket_fs2_data(app_tf, infopacket);
 
      build_vrr_infopacket_checksum(&payload_size, infopacket);
 
@@ -676,7 +675,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
              const struct dc_stream_state *stream,
              const struct mod_vrr_params *vrr,
              enum vrr_packet_type packet_type,
-             const enum color_transfer_func *app_tf,
+             enum color_transfer_func app_tf,
              struct dc_info_packet *infopacket)
 {
      /* SPD info packet for FreeSync */
drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h +1 -2
index 949a8b62aa98..063af6258fd9 100644
@@ -145,7 +145,7 @@ void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
              const struct dc_stream_state *stream,
              const struct mod_vrr_params *vrr,
              enum vrr_packet_type packet_type,
-             const enum color_transfer_func *app_tf,
+             enum color_transfer_func app_tf,
              struct dc_info_packet *infopacket);
 
 void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
--
Quoted 2 lines

2.20.0

Gentle ping on this patch, it would be nice to get this fixed and into 5.1!

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