All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Longpeng(Mike)" <longpeng2@huawei.com>
Cc: arei.gonglei@huawei.com, longpeng.mike@gmail.com,
	qemu-devel@nongnu.org, weidong.huang@huawei.com
Subject: Re: [Qemu-devel] [PATCH v3 12/18] crypto: introduce some common functions for af_alg backend
Date: Wed, 26 Apr 2017 13:10:13 +0100	[thread overview]
Message-ID: <20170426121013.GR18933@redhat.com> (raw)
In-Reply-To: <1492845627-4384-13-git-send-email-longpeng2@huawei.com>

On Sat, Apr 22, 2017 at 03:20:21PM +0800, Longpeng(Mike) wrote:
> The AF_ALG socket family is the userspace interface for linux
> crypto API, this patch adds af_alg family support and some common
> functions for af_alg backend. It'll be used by afalg-backend crypto
> latter.
> 
> Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
> ---
>  configure            |  21 +++++++++
>  crypto/Makefile.objs |   1 +
>  crypto/afalg.c       | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  crypto/afalgpriv.h   |  59 ++++++++++++++++++++++++++
>  4 files changed, 199 insertions(+)
>  create mode 100644 crypto/afalg.c
>  create mode 100644 crypto/afalgpriv.h

> +static bool
> +qcrypto_afalg_build_saddr(const char *type, const char *name,
> +                          struct sockaddr_alg *salg, Error **errp)
> +{
> +    salg->salg_family = AF_ALG;
> +
> +    if (qemu_strnlen(type, SALG_TYPE_LEN_MAX) == SALG_TYPE_LEN_MAX) {
> +        error_setg(errp, "Afalg type(%s) is larger than %d bytes",
> +                   type, SALG_TYPE_LEN_MAX);
> +        return false;
> +    }
> +
> +    if (qemu_strnlen(name, SALG_NAME_LEN_MAX) == SALG_NAME_LEN_MAX) {
> +        error_setg(errp, "Afalg name(%s) is larger than %d bytes",
> +                   name, SALG_NAME_LEN_MAX);
> +        return false;
> +    }

This is uneccessarily complicated - we can just use

   if (strlen(name) >= SALG_NAME_LEN_MAX) {
       ....
   }

> +    pstrcpy((char *)salg->salg_type, SALG_TYPE_LEN_MAX, type);
> +    pstrcpy((char *)salg->salg_name, SALG_NAME_LEN_MAX, name);
> +
> +    return true;
> +}


> +void qcrypto_afalg_comm_free(QCryptoAFAlg *afalg)
> +{
> +    if (afalg) {

Rather than indenting the entire method it is preferrable to
invert the condition and return immediately, eg

  if (!afalg) {
     return;
  }

> +        if (afalg->msg) {
> +            g_free(afalg->msg->msg_control);
> +            g_free(afalg->msg);
> +        }
> +
> +        if (afalg->name) {
> +            g_free(afalg->name);
> +        }
> +
> +        if (afalg->tfmfd != -1) {
> +            closesocket(afalg->tfmfd);
> +        }
> +
> +        if (afalg->opfd != -1) {
> +            closesocket(afalg->opfd);
> +        }
> +
> +        g_free(afalg);
> +    }
> +}


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2017-04-26 12:10 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-22  7:20 [Qemu-devel] [PATCH v3 00/18] crypto: add afalg-backend support Longpeng(Mike)
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 01/18] crypto: cipher: introduce context free function Longpeng(Mike)
2017-04-26 12:02   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 02/18] crypto: cipher: introduce qcrypto_cipher_ctx_new for gcrypt-backend Longpeng(Mike)
2017-04-26 12:02   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 03/18] crypto: cipher: introduce qcrypto_cipher_ctx_new for nettle-backend Longpeng(Mike)
2017-04-26 12:03   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 04/18] crypto: cipher: introduce qcrypto_cipher_ctx_new for builtin-backend Longpeng(Mike)
2017-04-26 12:03   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 05/18] crypto: cipher: add cipher driver framework Longpeng(Mike)
2017-04-26 12:04   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 06/18] crypto: hash: add hash " Longpeng(Mike)
2017-04-26 12:04   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 07/18] crypto: hmac: move crypto/hmac.h into include/crypto/ Longpeng(Mike)
2017-04-26 12:05   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 08/18] crypto: hmac: introduce qcrypto_hmac_ctx_new for gcrypt-backend Longpeng(Mike)
2017-04-26 12:05   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 09/18] crypto: hmac: introduce qcrypto_hmac_ctx_new for nettle-backend Longpeng(Mike)
2017-04-26 12:06   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 10/18] crypto: hmac: introduce qcrypto_hmac_ctx_new for glib-backend Longpeng(Mike)
2017-04-26 12:06   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 11/18] crypto: hmac: add hmac driver framework Longpeng(Mike)
2017-04-26 12:07   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 12/18] crypto: introduce some common functions for af_alg backend Longpeng(Mike)
2017-04-26 12:10   ` Daniel P. Berrange [this message]
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 13/18] crypto: cipher: add afalg-backend cipher support Longpeng(Mike)
2017-04-26 12:17   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 14/18] crypto: hash: add afalg-backend hash support Longpeng(Mike)
2017-04-26 12:20   ` Daniel P. Berrange
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 15/18] crypto: hmac: add af_alg hmac support Longpeng(Mike)
2017-04-26 12:23   ` Daniel P. Berrange
2017-07-04  8:52     ` Longpeng (Mike)
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 16/18] tests: crypto: add cipher speed benchmark support Longpeng(Mike)
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 17/18] tests: crypto: add hash " Longpeng(Mike)
2017-04-22  7:20 ` [Qemu-devel] [PATCH v3 18/18] tests: crypto: add hmac " Longpeng(Mike)
2017-04-22  7:41 ` [Qemu-devel] [PATCH v3 00/18] crypto: add afalg-backend support no-reply
2017-04-22  7:42 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170426121013.GR18933@redhat.com \
    --to=berrange@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=longpeng.mike@gmail.com \
    --cc=longpeng2@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=weidong.huang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.