svn commit: r348688 - head/sys/sys
Andriy Gapon
avg at FreeBSD.org
Wed Jun 5 13:18:01 UTC 2019
Author: avg
Date: Wed Jun 5 13:18:00 2019
New Revision: 348688
URL: https://svnweb.freebsd.org/changeset/base/348688
Log:
first step towards enforcing must-succeed semantics for bus accessors
Unlike BUS_READ_IVAR / BUS_WRITE_IVAR, bus accessors do not have a
return code. It is assumed that there is a tight coupling between a bus
driver and a driver for a device on the bus with respect to instance
variables that the bus defines for its children. So, the driver is
supposed to have only valid accesses to the variables and, thus, the
accessors must always succeed.
Of course, programming errors sometimes happen. At present, such errors
go completely unnoticed. The idea of this change is to start catching
them. As a first step, there will be a warning about a failed accessor
call. This is to give developers a heads-up. I plan to replace the
printf with a KASSERT a week later, so that the warning is harder to
ignore.
Reviewed by: cem, imp, ian
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D20458
Modified:
head/sys/sys/bus.h
Modified: head/sys/sys/bus.h
==============================================================================
--- head/sys/sys/bus.h Wed Jun 5 13:08:21 2019 (r348687)
+++ head/sys/sys/bus.h Wed Jun 5 13:18:00 2019 (r348688)
@@ -810,16 +810,30 @@ DECLARE_MODULE(name##_##busname, name##_##busname##_mo
static __inline type varp ## _get_ ## var(device_t dev) \
{ \
uintptr_t v; \
- BUS_READ_IVAR(device_get_parent(dev), dev, \
+ int e; \
+ e = BUS_READ_IVAR(device_get_parent(dev), dev, \
ivarp ## _IVAR_ ## ivar, &v); \
+ if (e != 0) { \
+ device_printf(dev, "failed to read ivar " \
+ __XSTRING(ivarp ## _IVAR_ ## ivar) " on bus %s, " \
+ "error = %d\n", \
+ device_get_nameunit(device_get_parent(dev)), e); \
+ } \
return ((type) v); \
} \
\
static __inline void varp ## _set_ ## var(device_t dev, type t) \
{ \
uintptr_t v = (uintptr_t) t; \
- BUS_WRITE_IVAR(device_get_parent(dev), dev, \
+ int e; \
+ e = BUS_WRITE_IVAR(device_get_parent(dev), dev, \
ivarp ## _IVAR_ ## ivar, v); \
+ if (e != 0) { \
+ device_printf(dev, "failed to write ivar " \
+ __XSTRING(ivarp ## _IVAR_ ## ivar) " on bus %s, " \
+ "error = %d\n", \
+ device_get_nameunit(device_get_parent(dev)), e); \
+ } \
}
/**
More information about the svn-src-all
mailing list