linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation
@ 2019-12-10 11:07 Yunfeng Ye
  2019-12-10 13:39 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Yunfeng Ye @ 2019-12-10 11:07 UTC (permalink / raw)
  To: Herbert Xu, davem, linux-crypto, linux-kernel, hushiyuan, linfeilong

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation
  2019-12-10 11:07 [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation Yunfeng Ye
@ 2019-12-10 13:39 ` Herbert Xu
  2019-12-10 14:27   ` Yunfeng Ye
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2019-12-10 13:39 UTC (permalink / raw)
  To: Yunfeng Ye; +Cc: davem, linux-crypto, linux-kernel, hushiyuan, linfeilong

On Tue, Dec 10, 2019 at 07:07:36PM +0800, Yunfeng Ye wrote:
> 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>

I don't think your patch makes it any more readable.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation
  2019-12-10 13:39 ` Herbert Xu
@ 2019-12-10 14:27   ` Yunfeng Ye
  0 siblings, 0 replies; 3+ messages in thread
From: Yunfeng Ye @ 2019-12-10 14:27 UTC (permalink / raw)
  To: Herbert Xu; +Cc: davem, linux-crypto, linux-kernel, hushiyuan, linfeilong



On 2019/12/10 21:39, Herbert Xu wrote:
> On Tue, Dec 10, 2019 at 07:07:36PM +0800, Yunfeng Ye wrote:
>> 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>
> 
> I don't think your patch makes it any more readable.
> 
ok, thanks, I think use macro instead of the same index calculation
logic is more clear.

> Cheers,
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-10 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 11:07 [PATCH] crypto: user - use macro CRYPTO_MSG_INDEX() to instead of index calculation Yunfeng Ye
2019-12-10 13:39 ` Herbert Xu
2019-12-10 14:27   ` Yunfeng Ye

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).