return ret;
}
+static inline int is_aead(dpaa_sec_session *ses)
+{
+ return ((ses->cipher_alg == 0) &&
+ (ses->auth_alg == 0) &&
+ (ses->aead_alg != 0));
+}
+
static inline int is_encode(dpaa_sec_session *ses)
{
return ses->dir == DIR_ENC;
default:
DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
xform->cipher.algo);
- rte_free(session->cipher_key.data);
return -1;
}
session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
default:
DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
xform->auth.algo);
- rte_free(session->auth_key.data);
return -1;
}
RTE_CACHE_LINE_SIZE);
if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
DPAA_SEC_ERR("No Memory for auth key");
- rte_free(session->cipher_key.data);
return -ENOMEM;
}
session->auth_key.length = auth_xform->key.length;
default:
DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
auth_xform->algo);
- goto error_out;
+ return -1;
}
session->cipher_alg = cipher_xform->algo;
default:
DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
cipher_xform->algo);
- goto error_out;
+ return -1;
}
session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
DIR_ENC : DIR_DEC;
return 0;
-
-error_out:
- rte_free(session->cipher_key.data);
- rte_free(session->auth_key.data);
- return -1;
}
static int
break;
default:
DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
- rte_free(session->aead_key.data);
return -ENOMEM;
}
return ret;
}
+static inline void
+free_session_data(dpaa_sec_session *s)
+{
+ if (is_aead(s))
+ rte_free(s->aead_key.data);
+ else {
+ rte_free(s->auth_key.data);
+ rte_free(s->cipher_key.data);
+ }
+ memset(s, 0, sizeof(dpaa_sec_session));
+}
+
static int
dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
struct rte_crypto_sym_xform *xform, void *sess)
return 0;
err1:
- rte_free(session->cipher_key.data);
- rte_free(session->auth_key.data);
- memset(session, 0, sizeof(dpaa_sec_session));
-
+ free_session_data(session);
return -EINVAL;
}
s->inq[i] = NULL;
s->qp[i] = NULL;
}
- rte_free(s->cipher_key.data);
- rte_free(s->auth_key.data);
- memset(s, 0, sizeof(dpaa_sec_session));
+ free_session_data(s);
rte_mempool_put(sess_mp, (void *)s);
}
return 0;
out:
- rte_free(session->auth_key.data);
- rte_free(session->cipher_key.data);
- memset(session, 0, sizeof(dpaa_sec_session));
+ free_session_data(session);
return -1;
}