missing error check in lwkt_alloc_thread

Matthew Dillon dillon at apollo.backplane.com
Fri Feb 23 10:58:26 PST 2007

:I just ran (via a programming mistake on my side) into a mall bug in lwkt=
:    if (stack =3D=3D NULL) {
:#ifdef _KERNEL
:        stack =3D (void *)kmem_alloc(&kernel_map, stksize);
:        stack =3D libcaps_alloc_stack(stksize);
:        flags |=3D TDF_ALLOCATED_STACK;
:    }
:kmem_alloc() however can return NULL if there is no free memory.  Arguabl=
:y, if there is no free memory to satisfy a thread stack, you're hosed any=
:ways, but nevertheless.
:I'm not sure how to fix this.  Maybe something like this will be sufficie=
:while (stack =3D=3D NULL) {
:  stack =3D (void *)kmem_alloc(&kernel_map, stksize);
:  if (stack =3D=3D NULL)
:    tsleep(&kernel_map, 0, "stckalc", hz);
:I know that there is nobody waking us up in this case, but one second sho=
:uld help the situation.  Or we add the possibility of an error return to =
:  simon

    I think kmem_alloc() should probably be passed allocation flags just
    like kmalloc() is, and panic if it would otherwise return NULL and
    M_NULLOK wasn't passed to it.


More information about the Kernel mailing list