Page MenuHomeFreeBSD

spi: switch to switch
ClosedPublic

Authored by reviews-freebsd-org412_ketas.si.pri.ee on Jan 17 2026, 4:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 29, 12:04 AM
Unknown Object (File)
Mon, May 18, 8:07 PM
Unknown Object (File)
Mon, May 18, 4:26 PM
Unknown Object (File)
Mon, May 18, 4:26 PM
Unknown Object (File)
Mon, May 18, 10:33 AM
Unknown Object (File)
Mon, May 18, 10:32 AM
Unknown Object (File)
Mon, May 18, 2:37 AM
Unknown Object (File)
Sun, May 17, 4:38 PM
Subscribers
None

Details

Summary

use recommended switch with default case to catch invalid values

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 69959
Build 66842: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Jan 17 2026, 5:02 PM

I'm not sure I'm convinced that dir is actually always set, but I haven't spent that much time reading the above logic. An assertion on that here might be good to try and do something useful instead of infinitely looping, but I don't insist

this uses saner code variant for change just done recently

When you do that, you want to use a Fixes: <shorthash> (title) line at the bottom of the commit message, that way the commits stay together for all the interesting things that can happen with branches or downstream.

I'm not sure I'm convinced that dir is actually always set, but I haven't spent that much time reading the above logic. An assertion on that here might be good to try and do something useful instead of infinitely looping, but I don't insist

i tried to read too, seems like it has error checks for not set conditions

but,

while (stream && fdir != DIR_NONE && !err && !feof(stdin));

then?

This revision now requires review to proceed.Jan 17 2026, 11:51 PM

put {} back info if blocks because that's actually good idea

This revision is now accepted and ready to land.Thu, May 28, 4:20 PM
usr.sbin/spi/spi.c
367–368

note - assert doesn't always get compiled in. It's only compiled in with -DDEBUG.

I recommend handling it in a case statement with a default:

switch (fdir) {
case DIR_READ:

<foo>
break;

case DIR_WRITE:

<foo>
break;

case DIR_READWRITE:

<foo>
break;

default:

fprintf(stderr, "Invalid state (%d)\n", fdir);
err = EINVAL;
break;

}

That way you handle all of the valid ones and capture any other states.

reviews-freebsd-org412_ketas.si.pri.ee retitled this revision from spi: use better logic for earlier change to spi: switch to switch.
reviews-freebsd-org412_ketas.si.pri.ee edited the summary of this revision. (Show Details)
This revision now requires review to proceed.Fri, May 29, 12:15 AM
This revision is now accepted and ready to land.Fri, May 29, 4:58 PM
This revision was automatically updated to reflect the committed changes.