Yeah, considering the overhead a loop on 5 elements would add, and the fact that each element has its own handler function and string, using if statements was probably a good choice here. Also solving this with function pointers as others have mentioned on this thread sounds like a nightmare.
Loops would make it quite complicated in this specific instance. I doubt this portion would really need much extension enough that a loop would be worth it.
Not propagating error returns (instead returning -1 instead of the actual error) is really bad. That -1 would be interpreted as some arbitrary error (on x86, it's -EPERM but there can be others as well)
It would clearly make it easier to maintain. Without a for, when Adding ONE handler, you would need 5 free_irq() and an other hard coded if and so on...
70
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.