linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yunfeng Ye <yeyunfeng@huawei.com>
To: Herbert Xu <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.or>,
	"hushiyuan@huawei.com" <hushiyuan@huawei.com>,
	"linfeilong@huawei.com" <linfeilong@huawei.com>
Subject: [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation
Date: Tue, 10 Dec 2019 19:07:36 +0800	[thread overview]
Message-ID: <6306e685-51fa-1a04-e9d9-07d4c80b5400@huawei.com> (raw)

There are multiple places using CRYPTO_MSG_BASE to calculate the index,
so use macro CRYPTO_MSG_INDEX() instead for better readability.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 crypto/crypto_user_base.c       | 28 ++++++++++++++--------------
 include/uapi/linux/cryptouser.h |  1 +
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/crypto/crypto_user_base.c b/crypto/crypto_user_base.c
index 910e0b4..4c8cac4 100644
--- a/crypto/crypto_user_base.c
+++ b/crypto/crypto_user_base.c
@@ -387,12 +387,12 @@ static int crypto_del_rng(struct sk_buff *skb, struct nlmsghdr *nlh,
 #define MSGSIZE(type) sizeof(struct type)

 static const int crypto_msg_min[CRYPTO_NR_MSGTYPES] = {
-	[CRYPTO_MSG_NEWALG	- CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
-	[CRYPTO_MSG_DELALG	- CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
-	[CRYPTO_MSG_UPDATEALG	- CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
-	[CRYPTO_MSG_GETALG	- CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
-	[CRYPTO_MSG_DELRNG	- CRYPTO_MSG_BASE] = 0,
-	[CRYPTO_MSG_GETSTAT	- CRYPTO_MSG_BASE] = MSGSIZE(crypto_user_alg),
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_NEWALG)] = MSGSIZE(crypto_user_alg),
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_DELALG)] = MSGSIZE(crypto_user_alg),
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_UPDATEALG)] = MSGSIZE(crypto_user_alg),
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_GETALG)] = MSGSIZE(crypto_user_alg),
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_DELRNG)] = 0,
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_GETSTAT)] = MSGSIZE(crypto_user_alg),
 };

 static const struct nla_policy crypto_policy[CRYPTOCFGA_MAX+1] = {
@@ -406,14 +406,14 @@ static int crypto_del_rng(struct sk_buff *skb, struct nlmsghdr *nlh,
 	int (*dump)(struct sk_buff *, struct netlink_callback *);
 	int (*done)(struct netlink_callback *);
 } crypto_dispatch[CRYPTO_NR_MSGTYPES] = {
-	[CRYPTO_MSG_NEWALG	- CRYPTO_MSG_BASE] = { .doit = crypto_add_alg},
-	[CRYPTO_MSG_DELALG	- CRYPTO_MSG_BASE] = { .doit = crypto_del_alg},
-	[CRYPTO_MSG_UPDATEALG	- CRYPTO_MSG_BASE] = { .doit = crypto_update_alg},
-	[CRYPTO_MSG_GETALG	- CRYPTO_MSG_BASE] = { .doit = crypto_report,
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_NEWALG)] = { .doit = crypto_add_alg},
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_DELALG)] = { .doit = crypto_del_alg},
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_UPDATEALG)] = { .doit = crypto_update_alg},
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_GETALG)] = { .doit = crypto_report,
 						       .dump = crypto_dump_report,
 						       .done = crypto_dump_report_done},
-	[CRYPTO_MSG_DELRNG	- CRYPTO_MSG_BASE] = { .doit = crypto_del_rng },
-	[CRYPTO_MSG_GETSTAT	- CRYPTO_MSG_BASE] = { .doit = crypto_reportstat},
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_DELRNG)] = { .doit = crypto_del_rng },
+	[CRYPTO_MSG_INDEX(CRYPTO_MSG_GETSTAT)] = { .doit = crypto_reportstat},
 };

 static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -428,10 +428,10 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (type > CRYPTO_MSG_MAX)
 		return -EINVAL;

-	type -= CRYPTO_MSG_BASE;
+	type = CRYPTO_MSG_INDEX(type);
 	link = &crypto_dispatch[type];

-	if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&
+	if ((type == CRYPTO_MSG_INDEX(CRYPTO_MSG_GETALG) &&
 	    (nlh->nlmsg_flags & NLM_F_DUMP))) {
 		struct crypto_alg *alg;
 		unsigned long dump_alloc = 0;
diff --git a/include/uapi/linux/cryptouser.h b/include/uapi/linux/cryptouser.h
index 5730c67..8a5fe9c 100644
--- a/include/uapi/linux/cryptouser.h
+++ b/include/uapi/linux/cryptouser.h
@@ -37,6 +37,7 @@ enum {
 };
 #define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1)
 #define CRYPTO_NR_MSGTYPES (CRYPTO_MSG_MAX + 1 - CRYPTO_MSG_BASE)
+#define CRYPTO_MSG_INDEX(x) ((x) - CRYPTO_MSG_BASE)

 #define CRYPTO_MAX_NAME 64

-- 
1.8.3.1


             reply	other threads:[~2019-12-10 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 11:07 Yunfeng Ye [this message]
2019-12-10 13:39 ` [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation Herbert Xu
2019-12-10 14:27   ` Yunfeng Ye

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=6306e685-51fa-1a04-e9d9-07d4c80b5400@huawei.com \
    --to=yeyunfeng@huawei.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hushiyuan@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.or \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).