summaryrefslogtreecommitdiffstats
path: root/sys/kern/bus_if.m
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2010-09-13 08:34:20 +0000
committeravg <avg@FreeBSD.org>2010-09-13 08:34:20 +0000
commitab04d6fe3f3cad0bec4d257b1064f6959ac9d358 (patch)
tree539808d49e79487aaff3b88f9d2e441ee2f92092 /sys/kern/bus_if.m
parent367de98e5d9d394f52863740e29b736e24310244 (diff)
downloadFreeBSD-src-ab04d6fe3f3cad0bec4d257b1064f6959ac9d358.zip
FreeBSD-src-ab04d6fe3f3cad0bec4d257b1064f6959ac9d358.tar.gz
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
Diffstat (limited to 'sys/kern/bus_if.m')
-rw-r--r--sys/kern/bus_if.m12
1 files changed, 11 insertions, 1 deletions
diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m
index 688a470..de808de 100644
--- a/sys/kern/bus_if.m
+++ b/sys/kern/bus_if.m
@@ -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
OpenPOWER on IntegriCloud