: ir252_drivers_locking_fixes-3.diff
Subsystems (2)
PATCH 1/1 : ir252_drivers_locking_fixes-3.diff
ir252_drivers_locking_fixes-3.diff :
----------------------------------
o [CORRECT] Remove all "save_flags(flags);cli();" in IrDA driver
o [FEATURE] Rework broken locking in irport
o [FEATURE] Finish locking cleanup in nsc-ircc
o [FEATURE] Improve locking in smc-ircc & w83977af_ir
include/net/irda/irtty.h renamed from include/net/irda-d6/irtty.h +3 -0
@@ -62,6 +62,9 @@ struct irtty_cb {struct qos_info qos;/* QoS capabilities for this device */ dongle_t *dongle;/* Dongle driver */ + +spinlock_t lock;/* For serializing operations */ +__u32 new_speed;__u32 flags;/* Interface flags */
include/net/irda/smc-ircc.h renamed from include/net/irda-d6/smc-ircc.h +3 -1
@@ -165,7 +165,9 @@ struct ircc_cb {struct irport_cb *irport; -spinlock_t lock;/* For serializing operations */ +/* Locking : half of our operations are done with irport, so we +* use the irport spinlock to make sure *everything* is properly +* synchronised - Jean II */ __u32 new_speed;__u32 flags;/* Interface flags */
include/net/irda/w83977af_ir.h renamed from include/net/irda-d6/w83977af_ir.h +5 -0
@@ -179,6 +179,11 @@ struct w83977af_ir {chipio_t io;/* IrDA controller information */ iobuff_t tx_buff;/* Transmit buffer */ iobuff_t rx_buff;/* Receive buffer */ + +/* Note : currently locking is *very* incomplete, but this +* will get you started. Check in nsc-ircc.c for a proper +* locking strategy. - Jean II */ +spinlock_t lock;/* For serializing operations */ __u32 flags;/* Interface flags */ __u32 new_speed;
drivers/net/irda/irda-usb.c renamed from drivers/net/irda-d6/irda-usb.c +1 -1
@@ -1171,7 +1171,7 @@ static inline int irda_usb_open(struct iirda_usb_init_qos (self);/* Initialise list of skb beeing curently transmitted */ - self->tx_list =hashbin_new (HB_GLOBAL ); + self->tx_list =hashbin_new (HB_NOLOCK );/* unused */ /* Allocate the buffer for speed changes */ /* Don't change this buffer size and allocation without doing
drivers/net/irda/irport.c renamed from drivers/net/irda-d6/irport.c +63 -31
300 lines not on this page · raw message
drivers/net/irda/irtty.c renamed from drivers/net/irda-d6/irtty.c +64 -19
295 lines not on this page · raw message
drivers/net/irda/nsc-ircc.c renamed from drivers/net/irda-d6/nsc-ircc.c +7 -12
@@ -870,7 +870,6 @@ static void nsc_ircc_init_dongle_interfa*/ static void nsc_ircc_change_dongle_speed (int iobase,int speed,int dongle_id) { -unsigned long flags;__u8 bank;/* Save current bank */
@@ -916,11 +915,10 @@ static void nsc_ircc_change_dongle_speedoutb (0x01 , iobase+4 );if (speed ==4000000 ) { -save_flags (flags); -cli (); +/* There was a cli() there, but we now are already +* under spin_lock_irqsave() - JeanII */ outb (0x81 , iobase+4 );outb (0x80 , iobase+4 ); -restore_flags (flags); }else outb (0x00 , iobase+4 );break ;
@@ -2013,33 +2011,30 @@ static int nsc_ircc_net_ioctl(struct netIRDA_DEBUG (2 , __FUNCTION__"(), %s, (cmd=0x%X)\n" , dev->name, cmd); -/* Disable interrupts & save flags */ -save_flags (flags); -cli (); -switch (cmd) {case SIOCSBANDWIDTH :/* Set bandwidth */ if (!capable (CAP_NET_ADMIN )) { ret = -EPERM ; - goto out; +break ; } +spin_lock_irqsave (&self->lock, flags);nsc_ircc_change_speed (self, irq->ifr_baudrate); +spin_unlock_irqrestore (&self->lock, flags);break ;case SIOCSMEDIABUSY :/* Set media busy */ if (!capable (CAP_NET_ADMIN )) { ret = -EPERM ; - goto out; +break ; }irda_device_set_media_busy (self->netdev, TRUE);break ;case SIOCGRECEIVING :/* Check if we are receiving right now */ +/* This is already protected */ irq->ifr_receiving =nsc_ircc_is_receiving (self);break ;default : ret = -EOPNOTSUPP ; } -out: -restore_flags (flags);return ret; }
drivers/net/irda/smc-ircc.c renamed from drivers/net/irda-d6/smc-ircc.c +25 -11
@@ -431,6 +431,7 @@ static int __init ircc_open(unsigned intstruct ircc_cb *self;struct irport_cb *irport;unsigned char low, high, chip, config, dma, irq, version; +unsigned long flags;IRDA_DEBUG (0 , __FUNCTION__"\n" );
@@ -484,7 +485,6 @@ static int __init ircc_open(unsigned intreturn -ENOMEM ; }memset (self,0 ,sizeof (struct ircc_cb )); -spin_lock_init (&self->lock);/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */ self->rx_buff.truesize =4000 ;
@@ -555,6 +555,9 @@ static int __init ircc_open(unsigned intrequest_region (self->io->fir_base,CHIP_IO_EXTENT , driver_name); +/* Don't allow irport to change under us - Jean II */ +spin_lock_irqsave (&self->irport->lock, flags); +/* Initialize QoS for this device */ irda_init_max_qos_capabilies (&irport->qos);
@@ -581,6 +584,7 @@ static int __init ircc_open(unsigned int self->netdev->stop = &ircc_net_close;irport_start (self->irport); +spin_unlock_irqrestore (&self->irport->lock, flags); self->pmdev =pm_register (PM_SYS_DEV ,PM_SYS_IRDA , ircc_pmproc);if (self->pmdev)
@@ -598,6 +602,7 @@ static int __init ircc_open(unsigned int* * Change the speed of the device * +* This function should be called with irq off and spin-lock. */ static void ircc_change_speed (void *priv,u32 speed) {
@@ -658,6 +663,7 @@ static void ircc_change_speed(void *priv/* Make special FIR init if necessary */ if (speed >115200 ) { +/* No need to lock, already locked - Jean II */ irport_stop (self->irport);/* Install FIR transmit handler */
@@ -674,6 +680,7 @@ static void ircc_change_speed(void *priv }else {/* Install SIR transmit handler */ dev->hard_start_xmit = &irport_hard_xmit; +/* No need to lock, already locked - Jean II */ irport_start (self->irport); IRDA_DEBUG(0, __FUNCTION__
@@ -727,20 +734,26 @@ static int ircc_hard_xmit(struct sk_buffnetif_stop_queue (dev); +/* Make sure tests *& speed change are atomic */ +spin_lock_irqsave (&self->irport->lock, flags); + +/* Note : you should make sure that speed changes are not going +* to corrupt any outgoing frame. Look at nsc-ircc for the gory +* details - Jean II */ +/* Check if we need to change the speed after this frame */ speed =irda_get_next_speed (skb);if ((speed != self->io->speed) && (speed !=-1 )) {/* Check for empty frame */ if (!skb->len) {ircc_change_speed (self, speed); +spin_unlock_irqrestore (&self->irport->lock, flags);dev_kfree_skb (skb);return 0 ; }else self->new_speed = speed; } -spin_lock_irqsave (&self->lock, flags); -memcpy (self->tx_buff.head, skb->data, skb->len); self->tx_buff.len = skb->len;
@@ -763,7 +776,7 @@ static int ircc_hard_xmit(struct sk_buff/* Transmit frame */ ircc_dma_xmit (self, iobase,0 ); } -spin_unlock_irqrestore (&self->lock, flags); +spin_unlock_irqrestore (&self->irport->lock, flags);dev_kfree_skb (skb);return 0 ;
@@ -985,12 +998,13 @@ static void ircc_interrupt(int irq, void/* Check if we should use the SIR interrupt handler */ if (self->io->speed <576000 ) { +/* Will spinlock itself - Jean II */ irport_interrupt (irq, dev_id, regs);return ; } iobase = self->io->fir_base; -spin_lock (&self->lock); +spin_lock (&self->irport->lock);register_bank (iobase,0 ); iir =inb (iobase+IRCC_IIR );
@@ -1013,7 +1027,7 @@ static void ircc_interrupt(int irq, voidregister_bank (iobase,0 );outb (IRCC_IER_ACTIVE_FRAME |IRCC_IER_EOM , iobase+IRCC_IER ); -spin_unlock (&self->lock); +spin_unlock (&self->irport->lock); }#if 0 /* unused */
@@ -1128,17 +1142,15 @@ static void ircc_suspend(struct ircc_cbstatic void ircc_wakeup (struct ircc_cb *self) { -unsigned long flags; -if (!self->io->suspended)return ; -save_flags (flags); -cli (); +/* The code was doing a "cli()" here, but this can't be right. +* If you need protection, do it in net_open with a spinlock +* or give a good reason. - Jean II */ ircc_net_open (self->netdev); -restore_flags (flags);MESSAGE ("%s, Waking up\n" , driver_name); }
@@ -1174,6 +1186,7 @@ static int __exit ircc_close(struct ircc iobase = self->irport->io.fir_base; +/* This will destroy irport */ irport_close (self->irport);/* Stop interrupts */
@@ -1187,6 +1200,7 @@ static int __exit ircc_close(struct irccoutb (IRCC_CFGA_IRDA_SIR_A |IRCC_CFGA_TX_POLARITY , iobase+IRCC_SCE_CFGA );outb (IRCC_CFGB_IR , iobase+IRCC_SCE_CFGB );#endif +/* Release the PORT that this driver is using */ IRDA_DEBUG (0 , __FUNCTION__"(), releasing 0x%03x\n" , iobase);
drivers/net/irda/w83977af_ir.c renamed from drivers/net/irda-d6/w83977af_ir.c +8 -11
@@ -175,6 +175,7 @@ int w83977af_open(int i, unsigned int ioreturn -ENOMEM ; }memset (self,0 ,sizeof (struct w83977af_ir )); +spin_lock_init (&self->lock);/* Need to store self somewhere */ dev_self[i] = self;
@@ -603,8 +604,7 @@ static void w83977af_dma_write(struct w8switch_bank (iobase,SET2 );outb (ADCR1_D_CHSW |/*ADCR1_DMA_F|*/ ADCR1_ADV_SL , iobase+ADCR1 );#ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS -save_flags (flags); -cli (); +spin_lock_irqsave (&self->lock, flags);disable_dma (self->io.dma);clear_dma_ff (self->io.dma);
@@ -623,7 +623,7 @@ static void w83977af_dma_write(struct w8 hcr =inb (iobase+HCR );outb (hcr |HCR_EN_DMA , iobase+HCR );enable_dma (self->io.dma); -restore_flags (flags); +spin_unlock_irqrestore (&self->lock, flags);#else outb (inb (iobase+HCR ) |HCR_EN_DMA |HCR_TX_WT , iobase+HCR );#endif
@@ -761,8 +761,7 @@ int w83977af_dma_receive(struct w83977af self->rx_buff.data = self->rx_buff.head;#ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS -save_flags (flags); -cli (); +spin_lock_irqsave (&self->lock, flags);disable_dma (self->io.dma);clear_dma_ff (self->io.dma);
@@ -788,7 +787,7 @@ int w83977af_dma_receive(struct w83977af hcr =inb (iobase+HCR );outb (hcr |HCR_EN_DMA , iobase+HCR );enable_dma (self->io.dma); -restore_flags (flags); +spin_unlock_irqrestore (&self->lock, flags);#else outb (inb (iobase+HCR ) |HCR_EN_DMA , iobase+HCR );#endif
@@ -1334,10 +1333,8 @@ static int w83977af_net_ioctl(struct netIRDA_DEBUG (2 , __FUNCTION__"(), %s, (cmd=0x%X)\n" , dev->name, cmd); -/* Disable interrupts & save flags */ -save_flags (flags); -cli (); - +spin_lock_irqsave (&self->lock, flags); +switch (cmd) {case SIOCSBANDWIDTH :/* Set bandwidth */ if (!capable (CAP_NET_ADMIN )) {
@@ -1360,7 +1357,7 @@ static int w83977af_net_ioctl(struct net ret = -EOPNOTSUPP ; } out: -restore_flags (flags); +spin_unlock_irqrestore (&self->lock, flags);return ret; }