[PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux