Simplify session selection/allocation.

This commit is contained in:
Pawel Jakub Dawidek 2008-08-09 20:01:01 +00:00
parent ec7993f8b0
commit b5207ec64a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=181478

View File

@ -215,23 +215,18 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
* allocate one.
*/
ses = TAILQ_FIRST(&sc->sc_sessions);
if (ses == NULL || ses->ses_used)
ses = NULL;
else {
TAILQ_REMOVE(&sc->sc_sessions, ses, ses_next);
ses->ses_used = 1;
TAILQ_INSERT_TAIL(&sc->sc_sessions, ses, ses_next);
}
if (ses == NULL) {
if (ses == NULL || ses->ses_used) {
ses = malloc(sizeof(*ses), M_PADLOCK, M_NOWAIT | M_ZERO);
if (ses == NULL) {
rw_wunlock(&sc->sc_sessions_lock);
return (ENOMEM);
}
ses->ses_used = 1;
ses->ses_id = sc->sc_sid++;
TAILQ_INSERT_TAIL(&sc->sc_sessions, ses, ses_next);
} else {
TAILQ_REMOVE(&sc->sc_sessions, ses, ses_next);
}
ses->ses_used = 1;
TAILQ_INSERT_TAIL(&sc->sc_sessions, ses, ses_next);
rw_wunlock(&sc->sc_sessions_lock);
error = padlock_cipher_setup(ses, encini);