Skip to contentSkip to conversation

drm/scheduler: Use ternary operator in standardized manner

PATCH In review Philipp Stanner 3 participants 3 messages Jul 15, 2024 – Jul 24, 2024

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

PATCH 1/1 drm/scheduler: Use ternary operator in standardized manner

drm_sched_init() omits the middle operand when using the ternary operator to set the timeout_wq if one has been passed.

This is a non-standardized GNU extension to the C language [1].

It decreases code readability and might be read as a bug. Furthermore, it is not consistent with all other places in drm/scheduler where the ternary operator is used.

Replace the expression with the standard one.

[1] https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Conditionals.html

---
 drivers/gpu/drm/scheduler/sched_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..02cf9c37a232 100644
@@ -1257,7 +1257,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 	sched->credit_limit = credit_limit;
 	sched->name = name;
 	sched->timeout = timeout;
-	sched->timeout_wq = timeout_wq ? : system_wq;
+	sched->timeout_wq = timeout_wq ? timeout_wq : system_wq;
 	sched->hang_limit = hang_limit;
 	sched->score = score ? score : &sched->_score;
 	sched->dev = dev;
Signature · 1 line
2.45.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Philipp Stanner

drm_sched_init() omits the middle operand when using the ternary operator to set the timeout_wq if one has been passed.

This is a non-standardized GNU extension to the C language [1].

It decreases code readability and might be read as a bug. Furthermore, it is not consistent with all other places in drm/scheduler where the ternary operator is used.

Quoted 6 lines

Replace the expression with the standard one.

[1] https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Conditionals.html

Quoted 20 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..02cf9c37a232 100644
@@ -1257,7 +1257,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 	sched->credit_limit = credit_limit;
 	sched->name = name;
 	sched->timeout = timeout;
-	sched->timeout_wq = timeout_wq ? : system_wq;
+	sched->timeout_wq = timeout_wq ? timeout_wq : system_wq;
 	sched->hang_limit = hang_limit;
 	sched->score = score ? score : &sched->_score;
 	sched->dev = dev;
Signature · 1 line
2.45.0
#2 lore raw
In reply to Philipp Stanner
Quoted 10 lines · Philipp Stanner

drm_sched_init() omits the middle operand when using the ternary operator to set the timeout_wq if one has been passed.

This is a non-standardized GNU extension to the C language [1].

It decreases code readability and might be read as a bug. Furthermore, it is not consistent with all other places in drm/scheduler where the ternary operator is used.

Replace the expression with the standard one.

The GCC extension is widely used in the kernel for brevity. Arguably duplicating the first operand is more error prone than omitting it.

Consistency within scheduler may be a valid point, but I'd consider removing the redundant middle operand instead.

BR,
Jani.

Quoted 22 lines

[1] https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Conditionals.html

---
 drivers/gpu/drm/scheduler/sched_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..02cf9c37a232 100644
@@ -1257,7 +1257,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 	sched->credit_limit = credit_limit;
 	sched->name = name;
 	sched->timeout = timeout;
-	sched->timeout_wq = timeout_wq ? : system_wq;
+	sched->timeout_wq = timeout_wq ? timeout_wq : system_wq;
 	sched->hang_limit = hang_limit;
 	sched->score = score ? score : &sched->_score;
 	sched->dev = dev;
Signature · 1 line
Jani Nikula, Intel