Skip to content

Commit 0f92cdf

Browse files
author
Peter Zijlstra
committed
sched: Simplify sysctl_sched_uclamp_handler()
Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Valentin Schneider <vschneid@redhat.com> Link: https://lore.kernel.org/r/20230801211811.896559109@infradead.org
1 parent 7537b90 commit 0f92cdf

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

kernel/sched/core.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,8 @@ static int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
18271827
int old_min, old_max, old_min_rt;
18281828
int result;
18291829

1830-
mutex_lock(&uclamp_mutex);
1830+
guard(mutex)(&uclamp_mutex);
1831+
18311832
old_min = sysctl_sched_uclamp_util_min;
18321833
old_max = sysctl_sched_uclamp_util_max;
18331834
old_min_rt = sysctl_sched_uclamp_util_min_rt_default;
@@ -1836,7 +1837,7 @@ static int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
18361837
if (result)
18371838
goto undo;
18381839
if (!write)
1839-
goto done;
1840+
return 0;
18401841

18411842
if (sysctl_sched_uclamp_util_min > sysctl_sched_uclamp_util_max ||
18421843
sysctl_sched_uclamp_util_max > SCHED_CAPACITY_SCALE ||
@@ -1872,16 +1873,12 @@ static int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
18721873
* Otherwise, keep it simple and do just a lazy update at each next
18731874
* task enqueue time.
18741875
*/
1875-
1876-
goto done;
1876+
return 0;
18771877

18781878
undo:
18791879
sysctl_sched_uclamp_util_min = old_min;
18801880
sysctl_sched_uclamp_util_max = old_max;
18811881
sysctl_sched_uclamp_util_min_rt_default = old_min_rt;
1882-
done:
1883-
mutex_unlock(&uclamp_mutex);
1884-
18851882
return result;
18861883
}
18871884
#endif

0 commit comments

Comments
 (0)