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)
Oct 18 2024, 2:09 AM
Unknown Object (File)
Oct 18 2024, 2:09 AM
Unknown Object (File)
Oct 18 2024, 2:09 AM
Unknown Object (File)
Oct 18 2024, 2:09 AM
Unknown Object (File)
Oct 17 2024, 11:28 PM
Unknown Object (File)
Oct 14 2024, 12:14 PM
Unknown Object (File)
Oct 3 2024, 11:09 PM
Unknown Object (File)
Oct 2 2024, 10:13 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.