Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762444Ab3IDM6z (ORCPT ); Wed, 4 Sep 2013 08:58:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15077 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754881Ab3IDM6y (ORCPT ); Wed, 4 Sep 2013 08:58:54 -0400 Message-ID: <52272E89.2020403@redhat.com> Date: Wed, 04 Sep 2013 14:58:49 +0200 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Eric Dumazet 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 References: <1378298247-29364-1-git-send-email-dborkman@redhat.com> <1378298247-29364-3-git-send-email-dborkman@redhat.com> <1378299135.7360.109.camel@edumazet-glaptop> In-Reply-To: <1378299135.7360.109.camel@edumazet-glaptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1962 Lines: 51 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 >> --- >> 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 >> #include >> #include >> -#include >> #include >> >> -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! -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/