All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 2/2] net: migrate direct users to prandom_u32_max
Date: Wed, 04 Sep 2013 14:58:49 +0200	[thread overview]
Message-ID: <52272E89.2020403@redhat.com> (raw)
In-Reply-To: <1378299135.7360.109.camel@edumazet-glaptop>

On 09/04/2013 02:52 PM, Eric Dumazet wrote:
> On Wed, 2013-09-04 at 14:37 +0200, Daniel Borkmann wrote:
>> Users that directly use or reimplement what we have in prandom_u32_max()
>> can be migrated for now to use it directly, so that we can reduce code size
>> and avoid reimplementations. That's obvious, follow-up patches could inspect
>> modulo use cases for possible migration as well.
>>
>> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
>> ---
>>   drivers/net/team/team_mode_random.c | 8 +-------
>>   include/net/red.h                   | 2 +-
>>   net/802/garp.c                      | 3 ++-
>>   net/802/mrp.c                       | 3 ++-
>>   net/packet/af_packet.c              | 2 +-
>>   net/sched/sch_choke.c               | 8 +-------
>>   6 files changed, 8 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/net/team/team_mode_random.c b/drivers/net/team/team_mode_random.c
>> index 7f032e2..0dbd1eb 100644
>> --- a/drivers/net/team/team_mode_random.c
>> +++ b/drivers/net/team/team_mode_random.c
>> @@ -13,20 +13,14 @@
>>   #include <linux/module.h>
>>   #include <linux/init.h>
>>   #include <linux/skbuff.h>
>> -#include <linux/reciprocal_div.h>
>>   #include <linux/if_team.h>
>>
>> -static u32 random_N(unsigned int N)
>> -{
>> -	return reciprocal_divide(prandom_u32(), N);
>> -}
>> -
>>   static bool rnd_transmit(struct team *team, struct sk_buff *skb)
>>   {
>>   	struct team_port *port;
>>   	int port_index;
>>
>> -	port_index = random_N(team->en_port_count);
>> +	port_index = prandom_u32_max(team->en_port_count - 1);
>
>
> Note the random_N(0) gave 0, while prandom_u32_max(0 - 1) can return any
> number in [0 ... ~0U]

Very true, that was stupid. Thanks for catching!

      reply	other threads:[~2013-09-04 12:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-04 12:37 [PATCH net-next v2 0/2] prandom_u32_range, prandom_u32_max helpers Daniel Borkmann
2013-09-04 12:37 ` [PATCH net-next v2 1/2] random: add prandom_u32_range and " Daniel Borkmann
2013-09-04 15:54   ` Joe Perches
2013-09-04 12:37 ` [PATCH net-next v2 2/2] net: migrate direct users to prandom_u32_max Daniel Borkmann
2013-09-04 12:52   ` Eric Dumazet
2013-09-04 12:58     ` Daniel Borkmann [this message]

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=52272E89.2020403@redhat.com \
    --to=dborkman@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.