- Fix freeing session on newsession failure.

- Update copyright years.
This commit is contained in:
Pawel Jakub Dawidek 2008-08-09 19:48:59 +00:00
parent f422e90330
commit ec7993f8b0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=181477

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> * Copyright (c) 2005-2008 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -65,6 +65,8 @@ struct padlock_softc {
static int padlock_newsession(device_t, uint32_t *sidp, struct cryptoini *cri); static int padlock_newsession(device_t, uint32_t *sidp, struct cryptoini *cri);
static int padlock_freesession(device_t, uint64_t tid); static int padlock_freesession(device_t, uint64_t tid);
static void padlock_freesession_one(struct padlock_softc *sc,
struct padlock_session *ses, int locked);
static int padlock_process(device_t, struct cryptop *crp, int hint __unused); static int padlock_process(device_t, struct cryptop *crp, int hint __unused);
MALLOC_DEFINE(M_PADLOCK, "padlock_data", "PadLock Data"); MALLOC_DEFINE(M_PADLOCK, "padlock_data", "PadLock Data");
@ -234,14 +236,14 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
error = padlock_cipher_setup(ses, encini); error = padlock_cipher_setup(ses, encini);
if (error != 0) { if (error != 0) {
padlock_freesession(NULL, ses->ses_id); padlock_freesession_one(sc, ses, 0);
return (error); return (error);
} }
if (macini != NULL) { if (macini != NULL) {
error = padlock_hash_setup(ses, macini); error = padlock_hash_setup(ses, macini);
if (error != 0) { if (error != 0) {
padlock_freesession(NULL, ses->ses_id); padlock_freesession_one(sc, ses, 0);
return (error); return (error);
} }
} }
@ -250,6 +252,24 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
return (0); return (0);
} }
static void
padlock_freesession_one(struct padlock_softc *sc, struct padlock_session *ses,
int locked)
{
uint32_t sid = ses->ses_id;
if (!locked)
rw_wlock(&sc->sc_sessions_lock);
TAILQ_REMOVE(&sc->sc_sessions, ses, ses_next);
padlock_hash_free(ses);
bzero(ses, sizeof(*ses));
ses->ses_used = 0;
ses->ses_id = sid;
TAILQ_INSERT_HEAD(&sc->sc_sessions, ses, ses_next);
if (!locked)
rw_wunlock(&sc->sc_sessions_lock);
}
static int static int
padlock_freesession(device_t dev, uint64_t tid) padlock_freesession(device_t dev, uint64_t tid)
{ {
@ -267,12 +287,7 @@ padlock_freesession(device_t dev, uint64_t tid)
rw_wunlock(&sc->sc_sessions_lock); rw_wunlock(&sc->sc_sessions_lock);
return (EINVAL); return (EINVAL);
} }
TAILQ_REMOVE(&sc->sc_sessions, ses, ses_next); padlock_freesession_one(sc, ses, 1);
padlock_hash_free(ses);
bzero(ses, sizeof(*ses));
ses->ses_used = 0;
ses->ses_id = sid;
TAILQ_INSERT_HEAD(&sc->sc_sessions, ses, ses_next);
rw_wunlock(&sc->sc_sessions_lock); rw_wunlock(&sc->sc_sessions_lock);
return (0); return (0);
} }