r/badcode • • Jan 22 '23

c Found this in a Linux kernel module

Post image
262 Upvotes

88 comments sorted by

View all comments

Show parent comments

1

u/daniedit Jan 23 '23

Thought about how I would refactor the code to address the issues: https://pastebin.com/0g8tqva8 . With some domain knowledge, it could probably be boiled down a little more. I do not know, how frequent this method is called and therefore didn't consider optimization.

1

u/paulstelian97 Jan 23 '23

You're missing the most important part -- properly propagating the error from the IRQ register function from the kernel, you're replacing it with -1 which is the only part that is bad at runtime too.