diff options
author | obrien <obrien@FreeBSD.org> | 2013-07-09 23:47:28 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2013-07-09 23:47:28 +0000 |
commit | af0e2ca5b5c3c18e7a5aaed93302fd4b2d353560 (patch) | |
tree | f7e9a6286f2183cdcaeac0de67c33117c01aea11 /sys | |
parent | 53ef2508e06a61a140193eda87788d64daa5f02e (diff) | |
download | FreeBSD-src-af0e2ca5b5c3c18e7a5aaed93302fd4b2d353560.zip FreeBSD-src-af0e2ca5b5c3c18e7a5aaed93302fd4b2d353560.tar.gz |
Refactor random_systat to be a *random_systat. This avoids unnecessary
structure copying in random_ident_hardware(). This change will also help
further modularization of random(4) subsystem.
Submitted by: arthurmesh@gmail.com
Reviewed by: obrien
Obtained from: Juniper Networks
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/random/probe.c | 8 | ||||
-rw-r--r-- | sys/dev/random/randomdev.c | 24 | ||||
-rw-r--r-- | sys/dev/random/randomdev.h | 4 | ||||
-rw-r--r-- | sys/dev/random/randomdev_soft.c | 18 |
4 files changed, 27 insertions, 27 deletions
diff --git a/sys/dev/random/probe.c b/sys/dev/random/probe.c index 4558db7..d9e70de 100644 --- a/sys/dev/random/probe.c +++ b/sys/dev/random/probe.c @@ -61,11 +61,11 @@ extern struct random_systat random_ivy; #endif void -random_ident_hardware(struct random_systat *systat) +random_ident_hardware(struct random_systat **systat) { /* Set default to software */ - *systat = random_yarrow; + *systat = &random_yarrow; /* Then go looking for hardware */ #if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) @@ -76,7 +76,7 @@ random_ident_hardware(struct random_systat *systat) enable = 1; TUNABLE_INT_FETCH("hw.nehemiah_rng_enable", &enable); if (enable) - *systat = random_nehemiah; + *systat = &random_nehemiah; } #endif #ifdef RDRAND_RNG @@ -86,7 +86,7 @@ random_ident_hardware(struct random_systat *systat) enable = 1; TUNABLE_INT_FETCH("hw.ivy_rng_enable", &enable); if (enable) - *systat = random_ivy; + *systat = &random_ivy; } #endif #endif diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index 96e1d88..18b17d8 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -70,7 +70,7 @@ static struct cdevsw random_cdevsw = { .d_name = "random", }; -struct random_systat random_systat; +struct random_systat *random_systat; /* For use with make_dev(9)/destroy_dev(9). */ static struct cdev *random_dev; @@ -88,8 +88,8 @@ random_close(struct cdev *dev __unused, int flags, int fmt __unused, { if ((flags & FWRITE) && (priv_check(td, PRIV_RANDOM_RESEED) == 0) && (securelevel_gt(td->td_ucred, 0) == 0)) { - (*random_systat.reseed)(); - random_systat.seeded = 1; + (*random_systat->reseed)(); + random_systat->seeded = 1; arc4rand(NULL, 0, 1); /* Reseed arc4random as well. */ } @@ -104,8 +104,8 @@ random_read(struct cdev *dev __unused, struct uio *uio, int flag) void *random_buf; /* Blocking logic */ - if (!random_systat.seeded) - error = (*random_systat.block)(flag); + if (!random_systat->seeded) + error = (*random_systat->block)(flag); /* The actual read */ if (!error) { @@ -114,7 +114,7 @@ random_read(struct cdev *dev __unused, struct uio *uio, int flag) while (uio->uio_resid > 0 && !error) { c = MIN(uio->uio_resid, PAGE_SIZE); - c = (*random_systat.read)(random_buf, c); + c = (*random_systat->read)(random_buf, c); error = uiomove(random_buf, c, uio); } @@ -139,7 +139,7 @@ random_write(struct cdev *dev __unused, struct uio *uio, int flag __unused) error = uiomove(random_buf, c, uio); if (error) break; - (*random_systat.write)(random_buf, c); + (*random_systat->write)(random_buf, c); } free(random_buf, M_TEMP); @@ -172,10 +172,10 @@ random_poll(struct cdev *dev __unused, int events, struct thread *td) int revents = 0; if (events & (POLLIN | POLLRDNORM)) { - if (random_systat.seeded) + if (random_systat->seeded) revents = events & (POLLIN | POLLRDNORM); else - revents = (*random_systat.poll) (events,td); + revents = (*random_systat->poll) (events,td); } return (revents); } @@ -189,11 +189,11 @@ random_modevent(module_t mod __unused, int type, void *data __unused) switch (type) { case MOD_LOAD: random_ident_hardware(&random_systat); - (*random_systat.init)(); + (*random_systat->init)(); if (bootverbose) printf("random: <entropy source, %s>\n", - random_systat.ident); + random_systat->ident); random_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &random_cdevsw, RANDOM_MINOR, NULL, UID_ROOT, GID_WHEEL, 0666, "random"); @@ -202,7 +202,7 @@ random_modevent(module_t mod __unused, int type, void *data __unused) break; case MOD_UNLOAD: - (*random_systat.deinit)(); + (*random_systat->deinit)(); destroy_dev(random_dev); diff --git a/sys/dev/random/randomdev.h b/sys/dev/random/randomdev.h index 2529a82..deb6831 100644 --- a/sys/dev/random/randomdev.h +++ b/sys/dev/random/randomdev.h @@ -51,7 +51,7 @@ struct random_systat { random_reseed_func_t *reseed; }; -extern struct random_systat random_systat; +extern struct random_systat *random_systat; -extern void random_ident_hardware(struct random_systat *); +extern void random_ident_hardware(struct random_systat **); extern void random_null_func(void); diff --git a/sys/dev/random/randomdev_soft.c b/sys/dev/random/randomdev_soft.c index 1742549..ac48214 100644 --- a/sys/dev/random/randomdev_soft.c +++ b/sys/dev/random/randomdev_soft.c @@ -138,7 +138,7 @@ random_yarrow_init(void) SYSCTL_ADD_PROC(&random_clist, SYSCTL_CHILDREN(random_sys_o), OID_AUTO, "seeded", CTLTYPE_INT | CTLFLAG_RW, - &random_systat.seeded, 1, random_check_boolean, "I", + &random_systat->seeded, 1, random_check_boolean, "I", "Seeded State"); random_sys_harvest_o = SYSCTL_ADD_NODE(&random_clist, @@ -362,10 +362,10 @@ random_yarrow_write(void *buf, int count) void random_yarrow_unblock(void) { - if (!random_systat.seeded) { - random_systat.seeded = 1; - selwakeuppri(&random_systat.rsel, PUSER); - wakeup(&random_systat); + if (!random_systat->seeded) { + random_systat->seeded = 1; + selwakeuppri(&random_systat->rsel, PUSER); + wakeup(random_systat); } (void)atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_NONE, ARC4_ENTR_HAVE); @@ -377,10 +377,10 @@ random_yarrow_poll(int events, struct thread *td) int revents = 0; mtx_lock(&random_reseed_mtx); - if (random_systat.seeded) + if (random_systat->seeded) revents = events & (POLLIN | POLLRDNORM); else - selrecord(td, &random_systat.rsel); + selrecord(td, &random_systat->rsel); mtx_unlock(&random_reseed_mtx); return revents; @@ -394,12 +394,12 @@ random_yarrow_block(int flag) mtx_lock(&random_reseed_mtx); /* Blocking logic */ - while (!random_systat.seeded && !error) { + while (!random_systat->seeded && !error) { if (flag & O_NONBLOCK) error = EWOULDBLOCK; else { printf("Entropy device is blocking.\n"); - error = msleep(&random_systat, + error = msleep(random_systat, &random_reseed_mtx, PUSER | PCATCH, "block", 0); } |