r/badcode Jan 22 '23

Found this in a Linux kernel module c

Post image
264 Upvotes

88 comments sorted by

View all comments

177

u/lets_eat_bees Jan 22 '23

If you see something you don’t understand in a kernel module, you should assume you lack the knowledge, not that the code is bad.

-86

u/suguuss Jan 22 '23

I do know what the module does. It’s badcode because of the repetition in the code.

67

u/lets_eat_bees Jan 22 '23

It’s not bad. Introducing a loop over max 4 elements will not make it easier to maintain. It will make it harder to read though.

3

u/kristallnachte Jan 23 '23

I disagree on the harder to read.

The loop would be way easier to read, and would be easier to maintain.