Simplify session selection/allocation.
This commit is contained in:
parent
ec7993f8b0
commit
b5207ec64a
@ -215,23 +215,18 @@ padlock_newsession(device_t dev, uint32_t *sidp, struct cryptoini *cri)
|
|||||||
* allocate one.
|
* allocate one.
|
||||||
*/
|
*/
|
||||||
ses = TAILQ_FIRST(&sc->sc_sessions);
|
ses = TAILQ_FIRST(&sc->sc_sessions);
|
||||||
if (ses == NULL || ses->ses_used)
|
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) {
|
|
||||||
ses = malloc(sizeof(*ses), M_PADLOCK, M_NOWAIT | M_ZERO);
|
ses = malloc(sizeof(*ses), M_PADLOCK, M_NOWAIT | M_ZERO);
|
||||||
if (ses == NULL) {
|
if (ses == NULL) {
|
||||||
rw_wunlock(&sc->sc_sessions_lock);
|
rw_wunlock(&sc->sc_sessions_lock);
|
||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
}
|
}
|
||||||
ses->ses_used = 1;
|
|
||||||
ses->ses_id = sc->sc_sid++;
|
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);
|
rw_wunlock(&sc->sc_sessions_lock);
|
||||||
|
|
||||||
error = padlock_cipher_setup(ses, encini);
|
error = padlock_cipher_setup(ses, encini);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user