Page MenuHomeFreeBSD

sysctl_search_oid: remove useless tests
ClosedPublic

Authored by dougm on Sep 27 2022, 6:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 24 2024, 6:02 AM
Unknown Object (File)
Jan 26 2024, 10:20 PM
Unknown Object (File)
Dec 20 2023, 8:01 AM
Unknown Object (File)
Oct 26 2023, 3:10 PM
Unknown Object (File)
Sep 20 2023, 5:53 AM
Unknown Object (File)
Aug 21 2023, 8:36 AM
Unknown Object (File)
Aug 14 2023, 4:13 PM
Unknown Object (File)
Aug 14 2023, 3:44 AM
Subscribers

Details

Summary

sysctl_search_old makes several tests in a loop that can be removed.

The first test in the loop is only ever true on the first loop iteration, and is always true on that iteration, so its work can be done before the loop begins.

The upper and lower bounds on the loop variable 'indx' are each tested on each iteration, but 'indx' is changed in one direction or the other only once within the loop, so only one bound needs to be checked.

Two ways remain in the loop that nodes[indx] can change (after one of them is put before the loop start), and one of them applies exactly when indx has been incremented, so no separate test for that case requires testing.

Test Plan

I've booted a kernel with it, but have no particular insights on how better to test it.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm requested review of this revision.Sep 27 2022, 6:14 AM
dougm created this revision.
sys/kern/kern_sysctl.c
385

Please add a few comments describing what this function does, while at it.

This revision is now accepted and ready to land.Sep 27 2022, 6:13 PM
This revision was automatically updated to reflect the committed changes.