resource.c - use of recursion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I am pretty new to the Linux kernel and go thru the sources  out of
curiosity.

I was going through the resource.c in 2.4 and saw the function called
do_resource_list


static char * do_resource_list(struct resource *entry, const char *fmt, int
offset, char *buf, char *end)
{
/* code that I am deleting to make this short*/


                if (entry->child)
                        buf = do_resource_list(entry->child, fmt, offset-2,
buf, end);
                entry = entry->sibling;

..
..
}


We are usually advised not to use recursion in the kernel code .... and i
guess the reasons are
1. The kernel stack is limited to the 2 four KB pages (8KB) for x86
2.  This is slow coz it requires pushing and popping of stuff from the
stack.

-1  But ofcourse the readability is much better above.

The above can be rewritten in non recursive way as way.  Now my problem is
not why the above is not non-recursive but i want to ask that upto what
limits is it ok to use recursion.   Was some calculation done on the max
possible limit of the global resource tree.
The use of recursion may be pretty desirable for itz simplicity and easy of
use.
Also wouldn't it be better that in order to match the readability as above,
a kernel programmer should implement the non - recursive code and put in a
comment as shown below

void f(int n)
{
/*lot of code to get the non - recursive part done*/

/* comment by the programmer */
/*  the above chunk is as good as making a recursive call f(n-1);   */

}

-mohit

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux