diff options
author | Krishna Kumar <krkumar2@in.ibm.com> | 2009-10-14 15:55:07 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-18 02:57:26 -0400 |
commit | 988ade6b8e27e79311812f83a87b5cea11fabcd7 (patch) | |
tree | 864fccbc78ffa108cde15648440b543f8f7e6688 /net/netlink/genetlink.c | |
parent | 93860b08e31a3202b6e67e386811545e719a0165 (diff) |
genetlink: Optimize and one bug fix in genl_generate_id()
1. GENL_MIN_ID is a valid id -> no need to start at
GENL_MIN_ID + 1.
2. Avoid going through the ids two times: If we start at
GENL_MIN_ID+1 (*or bigger*) and all ids are over!, the
code iterates through the list twice (*or lesser*).
3. Simplify code - no need to start at idx=0 which gets
reset to GENL_MIN_ID.
Patch on net-next-2.6. Reboot test shows that first id
passed to genl_register_family was 16, next two were
GENL_ID_GENERATE and genl_generate_id returned 17 & 18
(user level testing of same code shows expected values
across entire range of MIN/MAX).
Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/netlink/genetlink.c')
-rw-r--r-- | net/netlink/genetlink.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index ddfdb7d2e02b..d07ecda0a92d 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -97,25 +97,17 @@ static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family) | |||
97 | */ | 97 | */ |
98 | static inline u16 genl_generate_id(void) | 98 | static inline u16 genl_generate_id(void) |
99 | { | 99 | { |
100 | static u16 id_gen_idx; | 100 | static u16 id_gen_idx = GENL_MIN_ID; |
101 | int overflowed = 0; | 101 | int i; |
102 | 102 | ||
103 | do { | 103 | for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) { |
104 | if (id_gen_idx == 0) | 104 | if (!genl_family_find_byid(id_gen_idx)) |
105 | return id_gen_idx; | ||
106 | if (++id_gen_idx > GENL_MAX_ID) | ||
105 | id_gen_idx = GENL_MIN_ID; | 107 | id_gen_idx = GENL_MIN_ID; |
108 | } | ||
106 | 109 | ||
107 | if (++id_gen_idx > GENL_MAX_ID) { | 110 | return 0; |
108 | if (!overflowed) { | ||
109 | overflowed = 1; | ||
110 | id_gen_idx = 0; | ||
111 | continue; | ||
112 | } else | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | } while (genl_family_find_byid(id_gen_idx)); | ||
117 | |||
118 | return id_gen_idx; | ||
119 | } | 111 | } |
120 | 112 | ||
121 | static struct genl_multicast_group notify_grp; | 113 | static struct genl_multicast_group notify_grp; |