- drivers/net/hamradio remove local random function, use random32()
Subsystems (2)
PATCH 1/1 - drivers/net/hamradio remove local random function, use random32()
remove local random function, use random32() instead
Signed-off-by Joe Perches <[email protected]>
drivers/net/hamradio/baycom_epp.c +2 -11
@@ -52,6 +52,7 @@#include <linux/hdlcdrv.h> #include <linux/baycom.h> #include <linux/jiffies.h> +#include <linux/random.h> #include <net/ax25.h> #include <asm/uaccess.h>
@@ -433,16 +434,6 @@ static void encode_hdlc(struct baycom_state *bc)/* ---------------------------------------------------------------------- */ -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} - -/* ---------------------------------------------------------------------- */ -static int transmit (struct baycom_state *bc,int cnt,unsigned char stat) {struct parport *pp = bc->pdev->port;
@@ -464,7 +455,7 @@ static int transmit(struct baycom_state *bc, int cnt, unsigned char stat)if ((--bc->hdlctx.slotcnt) >0 )return 0 ; bc->hdlctx.slotcnt = bc->ch_params.slottime; -if ((random_num () %256 ) > bc->ch_params.ppersist) +if ((random32 () %256 ) > bc->ch_params.ppersist)return 0 ; } }
drivers/net/hamradio/hdlcdrv.c +2 -11
@@ -56,6 +56,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/hdlcdrv.h> +#include <linux/random.h> #include <net/ax25.h> #include <asm/uaccess.h>
@@ -371,16 +372,6 @@ static void start_tx(struct net_device *dev, struct hdlcdrv_state *s)/* ---------------------------------------------------------------------- */ -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} - -/* ---------------------------------------------------------------------- */ -void hdlcdrv_arbitrate (struct net_device *dev,struct hdlcdrv_state *s) {if (!s || s->magic !=HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb)
@@ -396,7 +387,7 @@ void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)if ((--s->hdlctx.slotcnt) >0 )return ; s->hdlctx.slotcnt = s->ch_params.slottime; -if ((random_num () %256 ) > s->ch_params.ppersist) +if ((random32 () %256 ) > s->ch_params.ppersist)return ;start_tx (dev, s); }
drivers/net/hamradio/yam.c +2 -9
@@ -50,6 +50,7 @@#include <linux/slab.h> #include <linux/errno.h> #include <linux/bitops.h> +#include <linux/random.h> #include <asm/io.h> #include <asm/system.h> #include <linux/interrupt.h>
@@ -566,14 +567,6 @@ static void yam_start_tx(struct net_device *dev, struct yam_port *yp)ptt_on (dev); } -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} -static void yam_arbitrate (struct net_device *dev) {struct yam_port *yp =netdev_priv (dev);
@@ -600,7 +593,7 @@ static void yam_arbitrate(struct net_device *dev) yp->slotcnt = yp->slot /10 ;/* is random > persist ? */ -if ((random_num () %256 ) > yp->pers) +if ((random32 () %256 ) > yp->pers)return ;yam_start_tx (dev, yp);
Quoted 3 lines · Joe Perches
remove local random function, use
random32()insteadSigned-off-by Joe Perches <[email protected]>
Acked-by Thomas Sailer <[email protected]>
There are a bunch of other drivers with their homegrown random number function, namely 6pack.c dmascc.c hdlcdrv.c yam.c.
Can you do a patch for those too?
Thanks a lot,
Tom
Quoted 9 lines · Thomas Sailer
Quoted 2 lines · Joe Perches
remove local random function, use
random32()insteadQuoted 1 line
Signed-off-by Joe Perches <[email protected]>Acked-by Thomas Sailer <[email protected]>There are a bunch of other drivers with their homegrown random number function, namely
6pack.cdmascc.chdlcdrv.cyam.c.Can you do a patch for those too?
hamradio files with random functions converted to random32()
Signed-off-by Joe Perches <[email protected]>
drivers/net/hamradio/6pack.c +3 -4
@@ -24,6 +24,7 @@#include <linux/errno.h> #include <linux/netdevice.h> #include <linux/timer.h> +#include <linux/random.h> #include <net/ax25.h> #include <linux/etherdevice.h> #include <linux/skbuff.h>
@@ -142,11 +143,9 @@ static void sp_xmit_on_air(unsigned long channel) {struct sixpack *sp = (struct sixpack *) channel;int actual, when = sp->slottime; -static unsigned char random; - random = random *17 +41 ; - -if (((sp->status1 &SIXP_DCD_MASK ) ==0 ) && (random < sp->persistence)) { +if (((sp->status1 &SIXP_DCD_MASK ) ==0 ) + && ((unsigned char )random32 () < sp->persistence)) { sp->led_state =0x70 ; sp->tty->driver->write (sp->tty, &sp->led_state,1 ); sp->tx_enable =1 ;
drivers/net/hamradio/baycom_epp.c +2 -11
@@ -52,6 +52,7 @@#include <linux/hdlcdrv.h> #include <linux/baycom.h> #include <linux/jiffies.h> +#include <linux/random.h> #include <net/ax25.h> #include <asm/uaccess.h>
@@ -433,16 +434,6 @@ static void encode_hdlc(struct baycom_state *bc)/* ---------------------------------------------------------------------- */ -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} - -/* ---------------------------------------------------------------------- */ -static int transmit (struct baycom_state *bc,int cnt,unsigned char stat) {struct parport *pp = bc->pdev->port;
@@ -464,7 +455,7 @@ static int transmit(struct baycom_state *bc, int cnt, unsigned char stat)if ((--bc->hdlctx.slotcnt) >0 )return 0 ; bc->hdlctx.slotcnt = bc->ch_params.slottime; -if ((random_num () %256 ) > bc->ch_params.ppersist) +if ((random32 () %256 ) > bc->ch_params.ppersist)return 0 ; } }
drivers/net/hamradio/dmascc.c +3 -12
@@ -34,6 +34,7 @@#include <linux/rtnetlink.h> #include <linux/sockios.h> #include <linux/workqueue.h> +#include <linux/random.h> #include <asm/atomic.h> #include <asm/bitops.h> #include <asm/dma.h>
@@ -246,7 +247,6 @@ static inline void tx_on(struct scc_priv *priv);static inline void rx_on (struct scc_priv *priv);static inline void rx_off (struct scc_priv *priv);static void start_timer (struct scc_priv *priv,int t,int r15); -static inline unsigned char random (void );static inline void z8530_isr (struct scc_info *info);static irqreturn_t scc_isr (int irq,void *dev_id);
@@ -269,7 +269,6 @@ static struct scc_hardware hw[NUM_TYPES] __initdata_or_module = HARDWARE;/* Global variables */ static struct scc_info *first; -static unsigned long rand;MODULE_AUTHOR ("Klaus Kudielka" );
@@ -314,8 +313,6 @@ static int __init dmascc_init(void)unsigned long time, start[MAX_NUM_DEVS ], delay[MAX_NUM_DEVS ], counting[MAX_NUM_DEVS ]; -/* Initialize random number generator */ - rand = jiffies;/* Cards found = 0 */ n =0 ;/* Warning message */
@@ -1099,13 +1096,6 @@ static void start_timer(struct scc_priv *priv, int t, int r15) } -static inline unsigned char random (void ) -{ -/* See "Numerical Recipes in C", second edition, p. 284 */ - rand = rand *1664525L +1013904223L ; -return (unsigned char ) (rand >>24 ); -} -static inline void z8530_isr (struct scc_info *info) {int is, i =100 ;
@@ -1466,7 +1456,8 @@ static void tm_isr(struct scc_priv *priv) }else { priv->state =WAIT ;start_timer (priv, -random () / priv->param.persist * + (unsigned char )random32 () / + priv->param.persist * priv->param.slottime,DCDIE ); }break ;
drivers/net/hamradio/hdlcdrv.c +2 -11
@@ -56,6 +56,7 @@#include <linux/if_arp.h> #include <linux/skbuff.h> #include <linux/hdlcdrv.h> +#include <linux/random.h> #include <net/ax25.h> #include <asm/uaccess.h>
@@ -371,16 +372,6 @@ static void start_tx(struct net_device *dev, struct hdlcdrv_state *s)/* ---------------------------------------------------------------------- */ -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} - -/* ---------------------------------------------------------------------- */ -void hdlcdrv_arbitrate (struct net_device *dev,struct hdlcdrv_state *s) {if (!s || s->magic !=HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb)
@@ -396,7 +387,7 @@ void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)if ((--s->hdlctx.slotcnt) >0 )return ; s->hdlctx.slotcnt = s->ch_params.slottime; -if ((random_num () %256 ) > s->ch_params.ppersist) +if ((random32 () %256 ) > s->ch_params.ppersist)return ;start_tx (dev, s); }
drivers/net/hamradio/yam.c +2 -9
@@ -50,6 +50,7 @@#include <linux/slab.h> #include <linux/errno.h> #include <linux/bitops.h> +#include <linux/random.h> #include <asm/io.h> #include <asm/system.h> #include <linux/interrupt.h>
@@ -566,14 +567,6 @@ static void yam_start_tx(struct net_device *dev, struct yam_port *yp)ptt_on (dev); } -static unsigned short random_seed; - -static inline unsigned short random_num (void ) -{ - random_seed =28629 * random_seed +157 ; -return random_seed; -} -static void yam_arbitrate (struct net_device *dev) {struct yam_port *yp =netdev_priv (dev);
@@ -600,7 +593,7 @@ static void yam_arbitrate(struct net_device *dev) yp->slotcnt = yp->slot /10 ;/* is random > persist ? */ -if ((random_num () %256 ) > yp->pers) +if ((random32 () %256 ) > yp->pers)return ;yam_start_tx (dev, yp);
Thomas Sailer
Acked-byQuoted 1 line · Joe Perches
Signed-off-by Joe Perches <[email protected]>
Acked-by Thomas Sailer <[email protected]>
Thanks a lot!
Tom