Changeset View
Standalone View
sys/kern/subr_bus.c
Show First 20 Lines • Show All 6,092 Lines • ▼ Show 20 Lines | ||||||||||||
static void | static void | |||||||||||
devctl2_init(void) | devctl2_init(void) | |||||||||||
{ | { | |||||||||||
make_dev_credf(MAKEDEV_ETERNAL, &devctl2_cdevsw, 0, NULL, | make_dev_credf(MAKEDEV_ETERNAL, &devctl2_cdevsw, 0, NULL, | |||||||||||
UID_ROOT, GID_WHEEL, 0644, "devctl2"); | UID_ROOT, GID_WHEEL, 0644, "devctl2"); | |||||||||||
} | } | |||||||||||
/* | /* | |||||||||||
* For maintaining device 'at' location info to avoid recomputing it | ||||||||||||
*/ | ||||||||||||
struct device_location_node { | ||||||||||||
const char *dln_locator; | ||||||||||||
const char *dln_path; | ||||||||||||
TAILQ_ENTRY(device_location_node) dln_link; | ||||||||||||
}; | ||||||||||||
typedef TAILQ_HEAD(device_location_list, device_location_node) device_location_list_t; | ||||||||||||
struct device_location_cache { | ||||||||||||
device_location_list_t dlc_list; | ||||||||||||
}; | ||||||||||||
/* | ||||||||||||
* Location cache for wired devices. | ||||||||||||
jhbUnsubmitted Not Done Inline Actions
jhb: | ||||||||||||
*/ | ||||||||||||
device_location_cache_t * | ||||||||||||
dev_wired_cache_init(void) | ||||||||||||
{ | ||||||||||||
device_location_cache_t *dcp; | ||||||||||||
dcp = malloc(sizeof(*dcp), M_BUS, M_WAITOK | M_ZERO); | ||||||||||||
TAILQ_INIT(&dcp->dlc_list); | ||||||||||||
return (dcp); | ||||||||||||
} | ||||||||||||
void | ||||||||||||
dev_wired_cache_fini(device_location_cache_t *dcp) | ||||||||||||
{ | ||||||||||||
struct device_location_node *dln, *tdln; | ||||||||||||
TAILQ_FOREACH_SAFE(dln, &dcp->dlc_list, dln_link, tdln) { | ||||||||||||
/* Note: one allocation for both node and locator, but not path */ | ||||||||||||
free(__DECONST(void *, dln->dln_path), M_BUS); | ||||||||||||
free(dln, M_BUS); | ||||||||||||
} | ||||||||||||
free(dcp, M_BUS); | ||||||||||||
} | ||||||||||||
static struct device_location_node * | ||||||||||||
dev_wired_cache_lookup(device_location_cache_t *dcp, const char *locator) | ||||||||||||
{ | ||||||||||||
struct device_location_node *dln; | ||||||||||||
TAILQ_FOREACH(dln, &dcp->dlc_list, dln_link) { | ||||||||||||
if (strcmp(locator, dln->dln_locator) == 0) | ||||||||||||
return (dln); | ||||||||||||
} | ||||||||||||
return (NULL); | ||||||||||||
Not Done Inline ActionsYou could simplify this a fair bit by just donating the allocated path pointer and then just malloc'ing the dln here. It does mean the fini routine above has to free dln->dln_path explicitly, but that seems like a lot simpler in implementation. jhb: You could simplify this a fair bit by just donating the allocated path pointer and then just… | ||||||||||||
Done Inline ActionsThat assumes that all the callers will have allocated this string and are cool with donating it. I don't think that's the case, especially for a cache miss. Then we'd have to pass back to the caller whether or not to free this thing. imp: That assumes that all the callers will have allocated this string and are cool with donating it. | ||||||||||||
Not Done Inline ActionsThe only caller is the one call below that uses device_get_path which always has an allocated string (this is a static function, it's not one of the public APIs). jhb: The only caller is the one call below that uses device_get_path which always has an allocated… | ||||||||||||
Done Inline Actions
You're correct. I was confusing this with a different interface. Those are great suggestions for improvement. Will roll them into next revision. imp: > The only caller is the one call below that uses device_get_path which always has an allocated… | ||||||||||||
} | ||||||||||||
static struct device_location_node * | ||||||||||||
dev_wired_cache_add(device_location_cache_t *dcp, const char *locator, const char *path) | ||||||||||||
{ | ||||||||||||
struct device_location_node *dln; | ||||||||||||
char *l; | ||||||||||||
dln = malloc(sizeof(*dln) + strlen(locator) + 1, M_BUS, M_WAITOK | M_ZERO); | ||||||||||||
dln->dln_locator = l = (char *)(dln + 1); | ||||||||||||
memcpy(l, locator, strlen(locator) + 1); | ||||||||||||
dln->dln_path = path; | ||||||||||||
TAILQ_INSERT_HEAD(&dcp->dlc_list, dln, dln_link); | ||||||||||||
return (dln); | ||||||||||||
} | ||||||||||||
bool | ||||||||||||
dev_wired_cache_match(device_location_cache_t *dcp, device_t dev, const char *at) | ||||||||||||
{ | ||||||||||||
const char *cp, *path; | ||||||||||||
char locator[32]; | ||||||||||||
int len; | ||||||||||||
struct device_location_node *res; | ||||||||||||
cp = strchr(at, ':'); | ||||||||||||
if (cp == NULL) | ||||||||||||
return (false); | ||||||||||||
len = cp - at; | ||||||||||||
Not Done Inline ActionsYou can make path a char * now that device_get_path returns that and then remove the need for the __DECONST below. jhb: You can make `path` a `char *` now that `device_get_path` returns that and then remove the need… | ||||||||||||
Done Inline ActionsSure. imp: Sure. | ||||||||||||
if (len > sizeof(locator) - 1) /* Skip too long locator */ | ||||||||||||
return (false); | ||||||||||||
memcpy(locator, at, len); | ||||||||||||
locator[len] = '\0'; | ||||||||||||
cp++; | ||||||||||||
/* maybe cache this inside device_t and look that up, but not yet */ | ||||||||||||
res = dev_wired_cache_lookup(dcp, locator); | ||||||||||||
if (res == NULL) { | ||||||||||||
path = device_get_path(dev, locator); | ||||||||||||
res = dev_wired_cache_add(dcp, locator, path); | ||||||||||||
} | ||||||||||||
if (res == NULL || res->dln_path == NULL) | ||||||||||||
return (false); | ||||||||||||
Not Done Inline Actions
jhb: | ||||||||||||
return (strcmp(res->dln_path, cp) == 0); | ||||||||||||
} | ||||||||||||
Not Done Inline ActionsThis is the sole call, and path is always allocated. jhb: This is the sole call, and `path` is always allocated. | ||||||||||||
/* | ||||||||||||
* APIs to manage deprecation and obsolescence. | * APIs to manage deprecation and obsolescence. | |||||||||||
*/ | */ | |||||||||||
static int obsolete_panic = 0; | static int obsolete_panic = 0; | |||||||||||
SYSCTL_INT(_debug, OID_AUTO, obsolete_panic, CTLFLAG_RWTUN, &obsolete_panic, 0, | SYSCTL_INT(_debug, OID_AUTO, obsolete_panic, CTLFLAG_RWTUN, &obsolete_panic, 0, | |||||||||||
"Panic when obsolete features are used (0 = never, 1 = if obsolete, " | "Panic when obsolete features are used (0 = never, 1 = if obsolete, " | |||||||||||
"2 = if deprecated)"); | "2 = if deprecated)"); | |||||||||||
static void | static void | |||||||||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |