bus_add_child: add specialized default implementation that calls panic
If a kobj method doesn't have any explicitly provided default implementation, then it is auto-assigned kobj_error_method. kobj_error_method is proper only for methods that return error code, because it just returns ENXIO. So, in the case of unimplemented bus_add_child caller would get (device_t)ENXIO as a return value, which would cause the mistake to go unnoticed, because return value is typically checked for NULL. Thus, a specialized null_add_child is added. It would have sufficied for correctness to return NULL, but this type of mistake was deemed to be rare and serious enough to call panic instead. Watch out for this kind of problem with other kobj methods. Suggested by: jhb, imp MFC after: 2 weeks
This commit is contained in:
parent
80dfae5fe2
commit
b7d28b2e0b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=212544
@ -26,6 +26,8 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/bus.h>
|
||||
|
||||
/**
|
||||
@ -56,6 +58,14 @@ CODE {
|
||||
return (BUS_REMAP_INTR(dev, NULL, irq));
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
static device_t
|
||||
null_add_child(device_t bus, int order, const char *name,
|
||||
int unit)
|
||||
{
|
||||
|
||||
panic("bus_add_child is not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -203,7 +213,7 @@ METHOD device_t add_child {
|
||||
u_int _order;
|
||||
const char *_name;
|
||||
int _unit;
|
||||
};
|
||||
} DEFAULT null_add_child;
|
||||
|
||||
/**
|
||||
* @brief Allocate a system resource
|
||||
|
Loading…
Reference in New Issue
Block a user