Commit 5b0ac72b authored by David S. Miller's avatar David S. Miller

[PKT_SCHED] dsmark: Use hweight32() instead of convoluted loop.

Based upon a patch by Stephen Hemminger and suggestions
from Patrick McHardy.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 81da99ed
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/bitops.h>
#include <net/pkt_sched.h> #include <net/pkt_sched.h>
#include <net/dsfield.h> #include <net/dsfield.h>
#include <net/inet_ecn.h> #include <net/inet_ecn.h>
...@@ -43,17 +44,6 @@ struct dsmark_qdisc_data { ...@@ -43,17 +44,6 @@ struct dsmark_qdisc_data {
int set_tc_index; int set_tc_index;
}; };
static inline int dsmark_valid_indices(u16 indices)
{
while (indices != 1) {
if (indices & 1)
return 0;
indices >>= 1;
}
return 1;
}
static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index) static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index)
{ {
return (index <= p->indices && index > 0); return (index <= p->indices && index > 0);
...@@ -348,7 +338,8 @@ static int dsmark_init(struct Qdisc *sch, struct rtattr *opt) ...@@ -348,7 +338,8 @@ static int dsmark_init(struct Qdisc *sch, struct rtattr *opt)
goto errout; goto errout;
indices = RTA_GET_U16(tb[TCA_DSMARK_INDICES-1]); indices = RTA_GET_U16(tb[TCA_DSMARK_INDICES-1]);
if (!indices || !dsmark_valid_indices(indices))
if (hweight32(indices) != 1)
goto errout; goto errout;
if (tb[TCA_DSMARK_DEFAULT_INDEX-1]) if (tb[TCA_DSMARK_DEFAULT_INDEX-1])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment