From: jsing Date: Mon, 12 Jun 2017 15:09:07 +0000 (+0000) Subject: Factor out and reuse the code that frees the crypto sessions, instead of X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2dc30802a6531cb8aa946388aad2dfcf8876d30d;p=openbsd Factor out and reuse the code that frees the crypto sessions, instead of duplicating it. --- diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 4e06ab05f1b..f170914a2dd 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.134 2017/06/12 14:46:00 jsing Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.135 2017/06/12 15:09:07 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom * Copyright (c) 2008 Hans-Joerg Hoexer @@ -888,6 +888,17 @@ done: return key_disk; } +static void +sr_crypto_free_sessions(struct sr_discipline *sd) +{ + u_int i; + + for (i = 0; sd->mds.mdd_crypto.scr_sid[i] != (u_int64_t)-1; i++) { + crypto_freesession(sd->mds.mdd_crypto.scr_sid[i]); + sd->mds.mdd_crypto.scr_sid[i] = (u_int64_t)-1; + } +} + int sr_crypto_alloc_resources(struct sr_discipline *sd) { @@ -956,13 +967,7 @@ sr_crypto_alloc_resources(struct sr_discipline *sd) cri.cri_key = sd->mds.mdd_crypto.scr_key[i]; if (crypto_newsession(&sd->mds.mdd_crypto.scr_sid[i], &cri, 0) != 0) { - for (i = 0; - sd->mds.mdd_crypto.scr_sid[i] != (u_int64_t)-1; - i++) { - crypto_freesession( - sd->mds.mdd_crypto.scr_sid[i]); - sd->mds.mdd_crypto.scr_sid[i] = (u_int64_t)-1; - } + sr_crypto_free_sessions(sd); return (EINVAL); } } @@ -977,7 +982,6 @@ sr_crypto_free_resources(struct sr_discipline *sd) { struct sr_workunit *wu; struct sr_crypto_wu *crwu; - u_int i; DNPRINTF(SR_D_DIS, "%s: sr_crypto_free_resources\n", DEVNAME(sd->sd_sc)); @@ -991,10 +995,7 @@ sr_crypto_free_resources(struct sr_discipline *sd) sr_hotplug_unregister(sd, sr_crypto_hotplug); - for (i = 0; sd->mds.mdd_crypto.scr_sid[i] != (u_int64_t)-1; i++) { - crypto_freesession(sd->mds.mdd_crypto.scr_sid[i]); - sd->mds.mdd_crypto.scr_sid[i] = (u_int64_t)-1; - } + sr_crypto_free_sessions(sd); TAILQ_FOREACH(wu, &sd->sd_wu, swu_next) { crwu = (struct sr_crypto_wu *)wu;