From dee7ebd77d33f8dfa5a2887d7c014a42b7d7df3f Mon Sep 17 00:00:00 2001 From: jhb Date: Wed, 8 Jan 2020 19:03:24 +0000 Subject: [PATCH] Use falloc_noinstall + finstall for crypto file descriptors. Reviewed by: cem, kib MFC after: 1 week Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D23078 --- sys/opencrypto/cryptodev.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index ddd76977eca1..52cf49870824 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -1499,20 +1499,21 @@ cryptoioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread switch (cmd) { case CRIOGET: + error = falloc_noinstall(td, &f); + if (error) + break; + fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK | M_ZERO); TAILQ_INIT(&fcr->csessions); mtx_init(&fcr->lock, "fcrypt", NULL, MTX_DEF); - error = falloc(td, &f, &fd, 0); - + finit(f, FREAD | FWRITE, DTYPE_CRYPTO, fcr, &cryptofops); + error = finstall(td, f, &fd, 0, NULL); if (error) { mtx_destroy(&fcr->lock); free(fcr, M_XDATA); - return (error); - } - /* falloc automatically provides an extra reference to 'f'. */ - finit(f, FREAD | FWRITE, DTYPE_CRYPTO, fcr, &cryptofops); - *(u_int32_t *)data = fd; + } else + *(uint32_t *)data = fd; fdrop(f, td); break; case CRIOFINDDEV: