netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: kaber@trash.net
Cc: shemminger@vyatta.com, netdev@vger.kernel.org
Subject: Re: [PATCH 2/4] dsmark: get rid of trivial function
Date: Mon, 21 Jan 2008 02:22:23 -0800 (PST)	[thread overview]
Message-ID: <20080121.022223.85874858.davem@davemloft.net> (raw)
In-Reply-To: <4793E460.5020804@trash.net>

From: Patrick McHardy <kaber@trash.net>
Date: Mon, 21 Jan 2008 01:16:32 +0100

> Stephen Hemminger wrote:
> > Replace loop in dsmark_valid_indices with equivalent bit math.
> > 
> > Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> > 
> > --- a/net/sched/sch_dsmark.c	2008-01-20 13:07:58.000000000 -0800
> > +++ b/net/sched/sch_dsmark.c	2008-01-20 13:22:54.000000000 -0800
> > @@ -45,13 +45,8 @@ struct dsmark_qdisc_data {
> >  
> >  static inline int dsmark_valid_indices(u16 indices)
> >  {
> > -	while (indices != 1) {
> > -		if (indices & 1)
> > -			return 0;
> > -		indices >>= 1;
> > -	}
> > -
> > -	return 1;
> > +	/* Must have only one bit set */
> > +	return (indices & (indices - 1)) == 0;
> 
> hweight seems easier to understand, it took me a bit
> to realize that the comment matches the code :)

Sounds good.  Here is what I ended up checking in.

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

Based upon a patch by Stephen Hemminger and suggestions
from Patrick McHardy.

Signed-off-by: David S. Miller <davem@davemloft.net>

diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index a9732ae..d96eaf0 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
 #include <linux/skbuff.h>
 #include <linux/rtnetlink.h>
+#include <linux/bitops.h>
 #include <net/pkt_sched.h>
 #include <net/dsfield.h>
 #include <net/inet_ecn.h>
@@ -43,17 +44,6 @@ struct dsmark_qdisc_data {
 	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)
 {
 	return (index <= p->indices && index > 0);
@@ -348,7 +338,8 @@ static int dsmark_init(struct Qdisc *sch, struct rtattr *opt)
 		goto errout;
 
 	indices = RTA_GET_U16(tb[TCA_DSMARK_INDICES-1]);
-	if (!indices || !dsmark_valid_indices(indices))
+
+	if (hweight32(indices) != 1)
 		goto errout;
 
 	if (tb[TCA_DSMARK_DEFAULT_INDEX-1])

  parent reply	other threads:[~2008-01-21 10:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080120130542.16720b45@deepthought>
2008-01-20 21:25 ` [PATCH 2/4] dsmark: get rid of trivial function Stephen Hemminger
2008-01-21  0:16   ` Patrick McHardy
2008-01-21  8:39     ` Ilpo Järvinen
2008-01-21 10:22     ` David Miller [this message]
2008-01-22  3:47       ` Stephen Hemminger
2008-01-22  3:59         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080121.022223.85874858.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).