Re: [PATCH v2] x86/pmc_atom: Fix warning when CONFIG_DEBUG_FS=n

Martin Kelly
2014-09-17T04:04:27Z

On 09/16/2014 08:44 PM, Li, Aubrey wrote:
>
> Why do you want to call pmc_dbgfs_register() anyway even if
> CONFIG_DEBUG_FS=n?
>
> Thanks,
> -Aubrey
>

The compiler will optimize away the call when CONFIG_DEBUG_FS=n, as the function body is just "return 0". Since the line following the call is "if (ret)" and since ret will always be 0, the compiler will likely optimize away the branch as well.

The reasoning for doing it this way is that it gives you a uniform code flow, which is easier to follow and reason about than having to think about branching #ifdefs sprinkled throughout the functions. The link I pasted gives full detail, but here's a snippet from Linus:

"Code cluttered with ifdefs is difficult to read and maintain. Don't do
it. Instead, put your ifdefs in a header, and conditionally define
'static inline' functions, or macros, which are used in the code.
Let the compiler optimize away the "no-op" case."

https://www.kernel.org/doc/Documentation/SubmittingPatches
(section 2.2, "#ifdefs are ugly")

In addition, Ingo Molnar suggested that I revise the patch in this way.

Thanks,
Martin