On Thu, Aug 24, 2017 at 10:46 AM, Markus Armbruster <arm...@redhat.com> wrote: > Cc: "Daniel P. Berrange" <berra...@redhat.com> > Signed-off-by: Markus Armbruster <arm...@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > crypto/block-luks.c | 19 +++++++------------ > 1 file changed, 7 insertions(+), 12 deletions(-) > > diff --git a/crypto/block-luks.c b/crypto/block-luks.c > index afb8543..c3cacdb 100644 > --- a/crypto/block-luks.c > +++ b/crypto/block-luks.c > @@ -20,6 +20,7 @@ > > #include "qemu/osdep.h" > #include "qapi/error.h" > +#include "qapi/util.h" > #include "qemu/bswap.h" > > #include "crypto/block-luks.h" > @@ -265,39 +266,33 @@ > qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg, > * make that function emit a more friendly error message */ > static int qcrypto_block_luks_name_lookup(const char *name, > const char *const *map, > - size_t maplen, > const char *type, > Error **errp) > { > - size_t i; > - for (i = 0; i < maplen; i++) { > - if (g_str_equal(map[i], name)) { > - return i; > - } > - } > + int ret = qapi_enum_parse(map, name, -1, NULL); > > - error_setg(errp, "%s %s not supported", type, name); > - return 0; > + if (ret < 0) { > + error_setg(errp, "%s %s not supported", type, name); > + return 0; > + } > + return ret; > } > > #define qcrypto_block_luks_cipher_mode_lookup(name, errp) \ > qcrypto_block_luks_name_lookup(name, \ > QCryptoCipherMode_lookup, \ > - QCRYPTO_CIPHER_MODE__MAX, \ > "Cipher mode", \ > errp) > > #define qcrypto_block_luks_hash_name_lookup(name, errp) \ > qcrypto_block_luks_name_lookup(name, \ > QCryptoHashAlgorithm_lookup, \ > - QCRYPTO_HASH_ALG__MAX, \ > "Hash algorithm", \ > errp) > > #define qcrypto_block_luks_ivgen_name_lookup(name, errp) \ > qcrypto_block_luks_name_lookup(name, \ > QCryptoIVGenAlgorithm_lookup, \ > - QCRYPTO_IVGEN_ALG__MAX, \ > "IV generator", \ > errp) > > -- > 2.7.5 > > -- Marc-André Lureau