Skip to contentSkip to conversation

: ir252_ircomm_locking_fixes-4.diff

PATCH New Jean Tourrilhes 1 participant 1 message Aug 29, 2002 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : ir252_ircomm_locking_fixes-4.diff

ir252_ircomm_locking_fixes-4.diff :
---------------------------------
o [FEATURE] Do the hashbin locking fixes for IrCOMM and IrLAN
o [CORRECT] Remove all "save_flags(flags);cli();" in IrCOMM/IrLAN
o [CORRECT] Fix other locking issues in IrCOMM

include/net/irda/ircomm_tty.h renamed from include/net/irda/ircomm_tty.d6.h +8 -0
diff -u -p linux/include/net/irda/ircomm_tty.d6.h linux/include/net/irda/ircomm_tty.h
@@ -104,6 +104,14 @@ struct ircomm_tty_cb {
 	long pgrp;		/* pgrp of opening process */
 	int  open_count;
 	int  blocked_open;	/* # of blocked opens */
+
+	/* Protect concurent access to :
+	 *	o self->open_count
+	 *	o self->ctrl_skb
+	 *	o self->tx_skb
+	 * Maybe other things may gain to be protected as well...
+	 * Jean II */
+	spinlock_t spinlock;
 };
 
 void ircomm_tty_start(struct tty_struct *tty);
net/irda/ircomm/ircomm_core.c renamed from net/irda/ircomm-d5/ircomm_core.c +4 -5
diff -u -p -r linux/net/irda/ircomm-d5/ircomm_core.c linux/net/irda/ircomm/ircomm_core.c
@@ -61,7 +61,7 @@ hashbin_t *ircomm = NULL;
 
 int __init ircomm_init(void)
 {
-	ircomm = hashbin_new(HB_LOCAL); 
+	ircomm = hashbin_new(HB_LOCK); 
 	if (ircomm == NULL) {
 		ERROR(__FUNCTION__ "(), can't allocate hashbin!\n");
 		return -ENOMEM;
@@ -505,11 +505,10 @@ int ircomm_proc_read(char *buf, char **s
 	struct ircomm_cb *self;
 	unsigned long flags;
 	
-	save_flags(flags);
-	cli();
-
 	len = 0;
 
+	spin_lock_irqsave(&ircomm->hb_spinlock, flags);
+
 	self = (struct ircomm_cb *) hashbin_get_first(ircomm);
 	while (self != NULL) {
 		ASSERT(self->magic == IRCOMM_MAGIC, break;);
@@ -535,7 +534,7 @@ int ircomm_proc_read(char *buf, char **s
 
 		self = (struct ircomm_cb *) hashbin_get_next(ircomm);
  	} 
-	restore_flags(flags);
+	spin_unlock_irqrestore(&ircomm->hb_spinlock, flags);
 
 	return len;
 }
net/irda/ircomm/ircomm_lmp.c renamed from net/irda/ircomm-d5/ircomm_lmp.c +1 -1
diff -u -p -r linux/net/irda/ircomm-d5/ircomm_lmp.c linux/net/irda/ircomm/ircomm_lmp.c
@@ -177,7 +177,7 @@ void ircomm_lmp_flow_control(struct sk_b
  
         line = cb->line;
 
-	self = (struct ircomm_cb *) hashbin_find(ircomm, line, NULL);
+	self = (struct ircomm_cb *) hashbin_lock_find(ircomm, line, NULL);
         if (!self) {
 		IRDA_DEBUG(2, __FUNCTION__ "(), didn't find myself\n");
                 return;
net/irda/ircomm/ircomm_param.c renamed from net/irda/ircomm-d5/ircomm_param.c +6 -5
diff -u -p -r linux/net/irda/ircomm-d5/ircomm_param.c linux/net/irda/ircomm/ircomm_param.c
@@ -99,6 +99,8 @@ pi_param_info_t ircomm_param_info = { pi
  */
 int ircomm_param_flush(struct ircomm_tty_cb *self)
 {
+	/* we should lock here, but I guess this function is unused...
+	 * Jean II */
 	if (self->ctrl_skb) {
 		ircomm_control_request(self->ircomm, self->ctrl_skb);
 		self->ctrl_skb = NULL;	
@@ -132,14 +134,13 @@ int ircomm_param_request(struct ircomm_t
 	if (self->service_type == IRCOMM_3_WIRE_RAW)
 		return 0;
 
-	save_flags(flags);
-	cli();
+	spin_lock_irqsave(&self->spinlock, flags);
 
 	skb = self->ctrl_skb;	
 	if (!skb) {
 		skb = dev_alloc_skb(256);
 		if (!skb) {
-			restore_flags(flags);
+			spin_unlock_irqrestore(&self->spinlock, flags);
 			return -ENOMEM;
 		}
 		
@@ -154,12 +155,12 @@ int ircomm_param_request(struct ircomm_t
 				  &ircomm_param_info);
 	if (count < 0) {
 		WARNING(__FUNCTION__ "(), no room for parameter!\n");
-		restore_flags(flags);
+		spin_unlock_irqrestore(&self->spinlock, flags);
 		return -1;
 	}
 	skb_put(skb, count);
 
-	restore_flags(flags);
+	spin_unlock_irqrestore(&self->spinlock, flags);
 
 	IRDA_DEBUG(2, __FUNCTION__ "(), skb->len=%d\n", skb->len);
 
net/irda/ircomm/ircomm_tty.c renamed from net/irda/ircomm-d5/ircomm_tty.c +52 -32

271 lines not on this page · raw message

net/irda/ircomm/ircomm_tty_attach.c renamed from net/irda/ircomm-d5/ircomm_tty_attach.c +2 -0
diff -u -p -r linux/net/irda/ircomm-d5/ircomm_tty_attach.c linux/net/irda/ircomm/ircomm_tty_attach.c
@@ -331,6 +331,8 @@ static void ircomm_tty_discovery_indicat
 	info.daddr = discovery->daddr;
 	info.saddr = discovery->saddr;
 
+	/* FIXME. We probably need to use hashbin_find_next(), but we first
+	 * need to ensure that "line" is unique. - Jean II */
 	self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
 	while (self != NULL) {
 		ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
net/irda/irlan/irlan_common.c renamed from net/irda/irlan-d5/irlan_common.c +4 -5
diff -u -p -r linux/net/irda/irlan-d5/irlan_common.c linux/net/irda/irlan/irlan_common.c
@@ -125,7 +125,7 @@ int __init irlan_init(void)
 
 	IRDA_DEBUG(0, __FUNCTION__ "()\n");
 	/* Allocate master structure */
-	irlan = hashbin_new(HB_LOCAL); 
+	irlan = hashbin_new(HB_LOCK);	/* protect from /proc */
 	if (irlan == NULL) {
 		printk(KERN_WARNING "IrLAN: Can't allocate hashbin!\n");
 		return -ENOMEM;
@@ -1090,11 +1090,10 @@ static int irlan_proc_read(char *buf, ch
 	unsigned long flags;
 	ASSERT(irlan != NULL, return 0;);
      
-	save_flags(flags);
-	cli();
-
 	len = 0;
 	
+	spin_lock_irqsave(&irlan->hb_spinlock, flags);
+
 	len += sprintf(buf+len, "IrLAN instances:\n");
 	
 	self = (struct irlan_cb *) hashbin_get_first(irlan);
@@ -1130,7 +1129,7 @@ static int irlan_proc_read(char *buf, ch
 
 		self = (struct irlan_cb *) hashbin_get_next(irlan);
  	} 
-	restore_flags(flags);
+	spin_unlock_irqrestore(&irlan->hb_spinlock, flags);
 
 	return len;
 }