summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2006-05-31 23:01:45 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2006-05-31 23:01:45 +0000
commit14122972524e1f349a5da3b63d98f5edf53df290 (patch)
tree056d6b328edcc23eee6af6d66d220df5bc434f63
parentb6fd4a36bf93e9be4d0ac2d98b614c935ce50921 (diff)
remove some silly casts. put spl calls after all declarations.
put one splx in a better spot. make a variable size MALLOC use malloc. remove null test after malloc(M_WAITOK). add PR_NOWAIT flag to pool_get instead of 0. change callbacks to correct type. ok brad deraadt markus mickey
-rw-r--r--sys/crypto/crypto.c33
-rw-r--r--sys/crypto/cryptodev.c39
-rw-r--r--sys/crypto/cryptodev.h4
3 files changed, 41 insertions, 35 deletions
diff --git a/sys/crypto/crypto.c b/sys/crypto/crypto.c
index c410023523a..8f6327f8980 100644
--- a/sys/crypto/crypto.c
+++ b/sys/crypto/crypto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crypto.c,v 1.47 2006/03/04 21:33:39 brad Exp $ */
+/* $OpenBSD: crypto.c,v 1.48 2006/05/31 23:01:44 tedu Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
*
@@ -216,15 +216,17 @@ int32_t
crypto_get_driverid(u_int8_t flags)
{
struct cryptocap *newdrv;
- int i, s = splvm();
+ int i, s;
+
+ s = splvm();
if (crypto_drivers_num == 0) {
crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
crypto_drivers = malloc(crypto_drivers_num *
sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT);
if (crypto_drivers == NULL) {
- splx(s);
crypto_drivers_num = 0;
+ splx(s);
return -1;
}
@@ -355,9 +357,11 @@ crypto_register(u_int32_t driverid, int *alg,
int
crypto_unregister(u_int32_t driverid, int alg)
{
- int i = CRYPTO_ALGORITHM_MAX + 1, s = splvm();
+ int i = CRYPTO_ALGORITHM_MAX + 1, s;
u_int32_t ses;
+ s = splvm();
+
/* Sanity checks. */
if (driverid >= crypto_drivers_num || crypto_drivers == NULL ||
((alg <= 0 || alg > CRYPTO_ALGORITHM_MAX) &&
@@ -401,9 +405,10 @@ crypto_unregister(u_int32_t driverid, int alg)
int
crypto_dispatch(struct cryptop *crp)
{
- int s = splvm();
+ int s;
u_int32_t hid;
+ s = splvm();
/*
* Keep track of ops per driver, for coallescing purposes. If
* we have been given an invalid hid, we'll deal with in the
@@ -418,7 +423,7 @@ crypto_dispatch(struct cryptop *crp)
crp_req_queue = crp;
crp_req_queue_tail = &(crp->crp_next);
splx(s);
- wakeup((caddr_t) &crp_req_queue); /* Shared wait channel. */
+ wakeup(&crp_req_queue); /* Shared wait channel. */
} else {
*crp_req_queue_tail = crp;
crp_req_queue_tail = &(crp->crp_next);
@@ -430,14 +435,16 @@ crypto_dispatch(struct cryptop *crp)
int
crypto_kdispatch(struct cryptkop *krp)
{
- int s = splvm();
+ int s;
+
+ s = splvm();
krp->krp_next = NULL;
if (krp_req_queue == NULL) {
krp_req_queue = krp;
krp_req_queue_tail = &(krp->krp_next);
splx(s);
- wakeup((caddr_t) &crp_req_queue); /* Shared wait channel. */
+ wakeup(&crp_req_queue); /* Shared wait channel. */
} else {
*krp_req_queue_tail = krp;
krp_req_queue_tail = &(krp->krp_next);
@@ -586,7 +593,9 @@ crypto_getreq(int num)
{
struct cryptodesc *crd;
struct cryptop *crp;
- int s = splvm();
+ int s;
+
+ s = splvm();
if (crypto_pool_initialized == 0) {
pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0,
@@ -596,7 +605,7 @@ crypto_getreq(int num)
crypto_pool_initialized = 1;
}
- crp = pool_get(&cryptop_pool, 0);
+ crp = pool_get(&cryptop_pool, PR_NOWAIT);
if (crp == NULL) {
splx(s);
return NULL;
@@ -604,7 +613,7 @@ crypto_getreq(int num)
bzero(crp, sizeof(struct cryptop));
while (num--) {
- crd = pool_get(&cryptodesc_pool, 0);
+ crd = pool_get(&cryptodesc_pool, PR_NOWAIT);
if (crd == NULL) {
splx(s);
crypto_freereq(crp);
@@ -636,7 +645,7 @@ crypto_thread(void)
crp = crp_req_queue;
krp = krp_req_queue;
if (crp == NULL && krp == NULL) {
- (void) tsleep(&crp_req_queue, PLOCK, "crypto_wait", 0);
+ (void)tsleep(&crp_req_queue, PLOCK, "crypto_wait", 0);
continue;
}
diff --git a/sys/crypto/cryptodev.c b/sys/crypto/cryptodev.c
index 95c5703a825..b6dc06bfd9d 100644
--- a/sys/crypto/cryptodev.c
+++ b/sys/crypto/cryptodev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptodev.c,v 1.64 2005/08/18 13:10:02 deraadt Exp $ */
+/* $OpenBSD: cryptodev.c,v 1.65 2006/05/31 23:01:44 tedu Exp $ */
/*
* Copyright (c) 2001 Theo de Raadt
@@ -113,8 +113,8 @@ int cryptodev_op(struct csession *, struct crypt_op *, struct proc *);
int cryptodev_key(struct crypt_kop *);
int cryptodev_dokey(struct crypt_kop *kop, struct crparam kvp[]);
-int cryptodev_cb(void *);
-int cryptodevkey_cb(void *);
+int cryptodev_cb(struct cryptop *);
+int cryptodevkey_cb(struct cryptkop *);
int usercrypto = 1; /* userland may do crypto requests */
int userasymcrypto = 1; /* userland may do asymmetric crypto reqs */
@@ -139,7 +139,7 @@ int
cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
{
struct cryptoini cria, crie;
- struct fcrypt *fcr = (struct fcrypt *)fp->f_data;
+ struct fcrypt *fcr = fp->f_data;
struct csession *cse;
struct session_op *sop;
struct crypt_op *cop;
@@ -303,7 +303,7 @@ bail:
int
cryptodev_op(struct csession *cse, struct crypt_op *cop, struct proc *p)
{
- struct cryptop *crp= NULL;
+ struct cryptop *crp = NULL;
struct cryptodesc *crde = NULL, *crda = NULL;
int i, s, error;
u_int32_t hid;
@@ -329,6 +329,7 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct proc *p)
for (i = 0; i < cse->uio.uio_iovcnt; i++)
cse->uio.uio_resid += cse->uio.uio_iov[0].iov_len;
+ /* number of requests, not logical and */
crp = crypto_getreq((cse->txform != NULL) + (cse->thash != NULL));
if (crp == NULL) {
error = ENOMEM;
@@ -376,9 +377,9 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct proc *p)
crp->crp_ilen = cop->len;
crp->crp_buf = (caddr_t)&cse->uio;
- crp->crp_callback = (int (*) (struct cryptop *)) cryptodev_cb;
+ crp->crp_callback = cryptodev_cb;
crp->crp_sid = cse->sid;
- crp->crp_opaque = (void *)cse;
+ crp->crp_opaque = cse;
if (cop->iv) {
if (crde == NULL) {
@@ -407,7 +408,7 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct proc *p)
error = EINVAL;
goto bail;
}
- crp->crp_mac=cse->tmp_mac;
+ crp->crp_mac = cse->tmp_mac;
}
/* try the fast path first */
@@ -468,10 +469,9 @@ bail:
}
int
-cryptodev_cb(void *op)
+cryptodev_cb(struct cryptop *crp)
{
- struct cryptop *crp = (struct cryptop *) op;
- struct csession *cse = (struct csession *)crp->crp_opaque;
+ struct csession *cse = crp->crp_opaque;
cse->error = crp->crp_etype;
if (crp->crp_etype == EAGAIN) {
@@ -483,9 +483,8 @@ cryptodev_cb(void *op)
}
int
-cryptodevkey_cb(void *op)
+cryptodevkey_cb(struct cryptkop *krp)
{
- struct cryptkop *krp = (struct cryptkop *) op;
wakeup(krp);
return (0);
@@ -529,16 +528,14 @@ cryptodev_key(struct crypt_kop *kop)
return (EINVAL);
}
- krp = (struct cryptkop *)malloc(sizeof *krp, M_XDATA, M_WAITOK);
- if (!krp)
- return (ENOMEM);
+ krp = malloc(sizeof *krp, M_XDATA, M_WAITOK);
bzero(krp, sizeof *krp);
krp->krp_op = kop->crk_op;
krp->krp_status = kop->crk_status;
krp->krp_iparams = kop->crk_iparams;
krp->krp_oparams = kop->crk_oparams;
krp->krp_status = 0;
- krp->krp_callback = (int (*) (struct cryptkop *)) cryptodevkey_cb;
+ krp->krp_callback = cryptodevkey_cb;
for (i = 0; i < CRK_MAXPARAM; i++)
krp->krp_param[i].crp_nbits = kop->crk_param[i].crp_nbits;
@@ -546,7 +543,7 @@ cryptodev_key(struct crypt_kop *kop)
size = (krp->krp_param[i].crp_nbits + 7) / 8;
if (size == 0)
continue;
- MALLOC(krp->krp_param[i].crp_p, caddr_t, size, M_XDATA, M_WAITOK);
+ krp->krp_param[i].crp_p = malloc(size, M_XDATA, M_WAITOK);
if (i >= krp->krp_iparams)
continue;
error = copyin(kop->crk_param[i].crp_p, krp->krp_param[i].crp_p, size);
@@ -582,7 +579,7 @@ fail:
kop->crk_status = krp->krp_status;
for (i = 0; i < CRK_MAXPARAM; i++) {
if (krp->krp_param[i].crp_p)
- FREE(krp->krp_param[i].crp_p, M_XDATA);
+ free(krp->krp_param[i].crp_p, M_XDATA);
}
free(krp, M_XDATA);
}
@@ -614,7 +611,7 @@ cryptof_stat(struct file *fp, struct stat *sb, struct proc *p)
int
cryptof_close(struct file *fp, struct proc *p)
{
- struct fcrypt *fcr = (struct fcrypt *)fp->f_data;
+ struct fcrypt *fcr = fp->f_data;
struct csession *cse;
while ((cse = TAILQ_FIRST(&fcr->csessions))) {
@@ -683,7 +680,7 @@ cryptoioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
f->f_flag = FREAD | FWRITE;
f->f_type = DTYPE_CRYPTO;
f->f_ops = &cryptofops;
- f->f_data = (caddr_t)fcr;
+ f->f_data = fcr;
*(u_int32_t *)data = fd;
FILE_SET_MATURE(f);
break;
diff --git a/sys/crypto/cryptodev.h b/sys/crypto/cryptodev.h
index e14b18b56e0..37e1587c40d 100644
--- a/sys/crypto/cryptodev.h
+++ b/sys/crypto/cryptodev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptodev.h,v 1.43 2005/05/25 05:47:53 markus Exp $ */
+/* $OpenBSD: cryptodev.h,v 1.44 2006/05/31 23:01:44 tedu Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
@@ -166,7 +166,7 @@ struct cryptop {
#define CRYPTO_F_DONE 0x0010 /* request completed */
caddr_t crp_buf; /* Data to be processed */
- caddr_t crp_opaque; /* Opaque pointer, passed along */
+ void *crp_opaque; /* Opaque pointer, passed along */
struct cryptodesc *crp_desc; /* Linked list of processing descriptors */
int (*crp_callback)(struct cryptop *); /* Callback function */