Re: [PATCH] mdeia: ipu3: ipu33-mmu: Replace macro IPU3_ADDR2PTE() with a function

From: Dan Carpenter
Date: Wed Jan 25 2023 - 10:27:17 EST


I'm sorry, but I don't think this is a worthwhile approach.

If you created a tool to automatically re-write macros as functions,
that's super impressive. But the choice between using a macro and a
function is just a style debate. The note in Coding Style is more
talking about complicated macros instead of these simple ones. And
anyway, when it comes to gray areas in the style guidelines, we
generally defer to the original author because that's who is doing all
the work.

There are some sorts of bugs associated with using macros like Macro
Expansion Precedence Bugs where there isn't parentheses around a macro,
or Double Evaluation Bugs where a parameter is evaluated twice. But
these sorts of bugs are very rare in the Linux kernel. Generally kernel
programmers have always been good about this sort of stuff. Also
checkpatch insists on parentheses. And it's not like error paths where
the bugs are difficult to find in testing. Probably we get a macro
bug every three years (compared to uninitialized variable bugs where we
get several per week). I have a Smatch check for both of these kinds of
macro bugs.

Another kind of bug would be type related bugs, because macros don't
have type checking. But I think those are caught in testing so they're
extremely rare. I don't think I have seen a real life example of one of
those.

regards,
dan carpenter