[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: static functions are your friends (Was GPIO revisited)
On Aug,Sunday 9 2009, at 12:58 PM, Marc Balmer wrote:
On Jul 25, 2009, at 3:53 AM, Marc Balmer wrote:
One more comment...
+int gpio_pinbyname(struct gpio_softc *, char *gp_name);
+/* Old API version */
+int gpio_ioctl_oapi(struct gpio_softc *, u_long cmd, void
*data, int flag,
+ int pinset);
KNF: no variables names in the declaration.
Also, any reason why these are not static?
While it certainly can make sense to declare functions static in
some userland programs for the sole reason to include a command in
a crunched binary, it does not make sense in kernel code; much to
the contrary, it makes debugging harder.
static functions make great sense in kernel code. In fact, we have
too many public functions as is and even more of the kernel should
be using static.
When a component only has a relatively small on entry points, it
allows the compiler to treat the component as one single unit to
compiled. This allows it to inline, follow the scope of variables,
and lots of other thing to generate better code.
The other reason to use static it prevents code from calling your
function that should never have never called it in the first place.
I want to quickly come back to this and explain my reasoning for not
making all functions static in the kernel, although I am totally
aware of all the positive effects of static in general.
I do mostly low-level driver development, something where you see
the ddb prompt more often than you like... Now with the functions
not being declared static, the trace command is my friend, I see
immediately in which function my driver crashed, this is an immense
I took the time to write a function that crahses the kernel on
purpose. Compiled as non static function, ddb showed me the
function name and function call trace with proper function names.
Quite easy to locate the faulty spot. To complete my test, I
compiled the very same code with all functions declared static. Now
the ddb trace does not show me the function names, making it a lot
harder to locate the faulty spot.
Can you show code which worked and not worked with static function
declarations. I'm pretty sure that this works
for me for a long time.
Main Index |
Thread Index |