Skip to contentSkip to conversation

netlabel: cleanup struct netlbl_lsm_catmap

PATCH Applied George Guo 3 participants 3 messages Feb 4, 2024 – Feb 7, 2024

Subsystems (4)
lore
Share & tools
lore

George Guo

author
#0 lore raw

PATCH v2 1/1 netlabel: cleanup struct netlbl_lsm_catmap

From: George Guo <[email protected]>

Simplify the code from macro NETLBL_CATMAP_MAPTYPE to u64, and fix warning "Macros with complex values should be enclosed in parentheses" on "#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01", which is modified to "#define NETLBL_CATMAP_BIT ((u64)0x01)".

---
V2:
Yes, I understand what you are saying.
Actually, there is a compile warnings on "#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01" which is missing parentheses.

---
 include/net/netlabel.h       | 7 +++----
 net/netlabel/netlabel_kapi.c | 8 ++++----
 2 files changed, 7 insertions(+), 8 deletions(-)
include/net/netlabel.h +3 -4
index d74f21f528de..0d04a8ae3811 100644
@@ -145,15 +145,14 @@ struct netlbl_lsm_cache {
  * processing.
  *
  */
-#define NETLBL_CATMAP_MAPTYPE           u64
 #define NETLBL_CATMAP_MAPCNT            4
-#define NETLBL_CATMAP_MAPSIZE           (sizeof(NETLBL_CATMAP_MAPTYPE) * 8)
+#define NETLBL_CATMAP_MAPSIZE           (sizeof(u64) * 8)
 #define NETLBL_CATMAP_SIZE              (NETLBL_CATMAP_MAPSIZE * \
 					 NETLBL_CATMAP_MAPCNT)
-#define NETLBL_CATMAP_BIT               (NETLBL_CATMAP_MAPTYPE)0x01
+#define NETLBL_CATMAP_BIT               ((u64)0x01)
 struct netlbl_lsm_catmap {
 	u32 startbit;
-	NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT];
+	u64 bitmap[NETLBL_CATMAP_MAPCNT];
 	struct netlbl_lsm_catmap *next;
 };
 
net/netlabel/netlabel_kapi.c +4 -4
index 27511c90a26f..7b844581ebee 100644
@@ -610,7 +610,7 @@ int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, u32 offset)
 	struct netlbl_lsm_catmap *iter;
 	u32 idx;
 	u32 bit;
-	NETLBL_CATMAP_MAPTYPE bitmap;
+	u64 bitmap;
 
 	iter = _netlbl_catmap_getnode(&catmap, offset, _CM_F_WALK, 0);
 	if (iter == NULL)
@@ -666,8 +666,8 @@ int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, u32 offset)
 	struct netlbl_lsm_catmap *prev = NULL;
 	u32 idx;
 	u32 bit;
-	NETLBL_CATMAP_MAPTYPE bitmask;
-	NETLBL_CATMAP_MAPTYPE bitmap;
+	u64 bitmask;
+	u64 bitmap;
 
 	iter = _netlbl_catmap_getnode(&catmap, offset, _CM_F_WALK, 0);
 	if (iter == NULL)
@@ -857,7 +857,7 @@ int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap,
 
 	offset -= iter->startbit;
 	idx = offset / NETLBL_CATMAP_MAPSIZE;
-	iter->bitmap[idx] |= (NETLBL_CATMAP_MAPTYPE)bitmap
+	iter->bitmap[idx] |= (u64)bitmap
 			     << (offset % NETLBL_CATMAP_MAPSIZE);
 
 	return 0;
Signature · 1 line
2.34.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 14 lines · George Guo

From: George Guo <[email protected]>

Simplify the code from macro NETLBL_CATMAP_MAPTYPE to u64, and fix warning "Macros with complex values should be enclosed in parentheses" on "#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01", which is modified to "#define NETLBL_CATMAP_BIT ((u64)0x01)".

---
V2:
Yes, I understand what you are saying.
Actually, there is a compile warnings on "#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01" which is missing parentheses.

Quoted 4 lines
---
 include/net/netlabel.h       | 7 +++----
 net/netlabel/netlabel_kapi.c | 8 ++++----
 2 files changed, 7 insertions(+), 8 deletions(-)

This is a much better approach, thank you.

Signature · 1 line
paul-moore.com
#2 lore raw
In reply to George Guo
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 8 lines · On Sun, 4 Feb 2024 10:35:31 +0800 you wrote:

From: George Guo <[email protected]>

Simplify the code from macro NETLBL_CATMAP_MAPTYPE to u64, and fix warning "Macros with complex values should be enclosed in parentheses" on "#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01", which is modified to "#define NETLBL_CATMAP_BIT ((u64)0x01)".

[...]

Here is the summary with links:
- [v2,1/1] netlabel: cleanup struct netlbl_lsm_catmap

    https://git.kernel.org/netdev/net-next/c/23c5ae6d4675

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html