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, Nov 20, 10:57 AM
Unknown Object (File)
Sep 27 2024, 2:08 PM
Unknown Object (File)
Sep 27 2024, 1:00 PM
Unknown Object (File)
Sep 22 2024, 7:10 PM
Unknown Object (File)
Sep 19 2024, 10:38 AM
Unknown Object (File)
Sep 16 2024, 9:58 PM
Unknown Object (File)
Sep 5 2024, 4:19 PM
Unknown Object (File)
Aug 30 2024, 3:25 AM
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.