Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/devfs/devfs_devs.c
Show First 20 Lines • Show All 476 Lines • ▼ Show 20 Lines | |||||
* Each cdev_priv has an array of pointers to devfs_dirent which is indexed | * Each cdev_priv has an array of pointers to devfs_dirent which is indexed | ||||
* by the mount points dm_idx. | * by the mount points dm_idx. | ||||
* This function extends the array when necessary, taking into account that | * This function extends the array when necessary, taking into account that | ||||
* the default array is 1 element and not malloc'ed. | * the default array is 1 element and not malloc'ed. | ||||
*/ | */ | ||||
static void | static void | ||||
devfs_metoo(struct cdev_priv *cdp, struct devfs_mount *dm) | devfs_metoo(struct cdev_priv *cdp, struct devfs_mount *dm) | ||||
{ | { | ||||
struct devfs_dirent **dep; | struct devfs_dirent **dep, **olddep; | ||||
int siz; | int siz; | ||||
siz = (dm->dm_idx + 1) * sizeof *dep; | siz = (dm->dm_idx + 1) * sizeof *dep; | ||||
dep = malloc(siz, M_DEVFS2, M_WAITOK | M_ZERO); | dep = malloc(siz, M_DEVFS2, M_WAITOK | M_ZERO); | ||||
dev_lock(); | dev_lock(); | ||||
if (dm->dm_idx <= cdp->cdp_maxdirent) { | if (dm->dm_idx <= cdp->cdp_maxdirent) { | ||||
/* We got raced */ | /* We got raced */ | ||||
dev_unlock(); | dev_unlock(); | ||||
free(dep, M_DEVFS2); | free(dep, M_DEVFS2); | ||||
return; | return; | ||||
} | } | ||||
memcpy(dep, cdp->cdp_dirents, (cdp->cdp_maxdirent + 1) * sizeof *dep); | memcpy(dep, cdp->cdp_dirents, (cdp->cdp_maxdirent + 1) * sizeof *dep); | ||||
if (cdp->cdp_maxdirent > 0) | olddep = cdp->cdp_maxdirent > 0 ? cdp->cdp_dirents : NULL; | ||||
free(cdp->cdp_dirents, M_DEVFS2); | |||||
cdp->cdp_dirents = dep; | cdp->cdp_dirents = dep; | ||||
/* | /* | ||||
kib: `olddep = cdp->cdp_maxdirent > 0 ? cdp->cdp_dirents : NULL;` | |||||
* XXX: if malloc told us how much we actually got this could | * XXX: if malloc told us how much we actually got this could | ||||
* XXX: be optimized. | * XXX: be optimized. | ||||
Not Done Inline ActionsBTW, we now have malloc_size() for this, though I'm not sure we want to encourage its use for situations like this. markj: BTW, we now have malloc_size() for this, though I'm not sure we want to encourage its use for… | |||||
*/ | */ | ||||
cdp->cdp_maxdirent = dm->dm_idx; | cdp->cdp_maxdirent = dm->dm_idx; | ||||
dev_unlock(); | dev_unlock(); | ||||
free(olddep, M_DEVFS2); | |||||
} | } | ||||
/* | /* | ||||
* The caller needs to hold the dm for the duration of the call. | * The caller needs to hold the dm for the duration of the call. | ||||
*/ | */ | ||||
static int | static int | ||||
devfs_populate_loop(struct devfs_mount *dm, int cleanup) | devfs_populate_loop(struct devfs_mount *dm, int cleanup) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 234 Lines • Show Last 20 Lines |
olddep = cdp->cdp_maxdirent > 0 ? cdp->cdp_dirents : NULL;