Page MenuHomeFreeBSD

Reduce the scope of possible allocation failures in subr_kobj.c.
ClosedPublic

Authored by markj on Jan 29 2019, 6:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 17, 11:03 PM
Unknown Object (File)
Dec 20 2023, 8:25 AM
Unknown Object (File)
Dec 11 2023, 7:39 AM
Unknown Object (File)
Oct 28 2023, 1:43 AM
Unknown Object (File)
Sep 6 2023, 9:21 AM
Unknown Object (File)
Sep 1 2023, 5:41 PM
Unknown Object (File)
Sep 1 2023, 5:39 PM
Unknown Object (File)
Sep 1 2023, 5:39 PM
Subscribers
None

Details

Summary

Previously kobj_class_compile() would panic if its internal allocation
failed. kobj_class_compile() may be called from kobj_create() via
kobj_init(), and kobj_create() allows the caller to specify the wait
flags, so kobj_create(M_WAITOK) may trigger a panic due to an allocation
failure, which is silly.

Take a step towards fixing this: plumb the wait flags from kobj_create()
to kobj_class_compile(). I verified that all external callers of
kobj_class_compile() use it in a sleepable context.

There is still a problem: kobj_init() does not provide a return value,
yet may fail due to the allocation failure. Moreover, it is sometimes
called in a non-sleepable context (e.g., device probe). I considered
adding an mflags parameter there, but wanted to get some feedback
on this incremental step first.

Test Plan

Peter reported the problem and is testing the patch.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj edited the test plan for this revision. (Show Details)
markj added reviewers: kib, imp, jhb.
kib added inline comments.
sys/kern/subr_kobj.c
276 ↗(On Diff #53395)

I think this is better written as while (cl->ops == NULL) {

This revision is now accepted and ready to land.Jan 29 2019, 6:50 PM
  • for -> while
  • Handle errors from kobj_init1() in kobj_create().
This revision now requires review to proceed.Jan 29 2019, 7:00 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jan 31 2019, 10:27 PM
This revision was automatically updated to reflect the committed changes.