Subject: Re: [patch 2/7] CAN: Add PF_CAN core module

From: Oliver Hartkopp <[email-masked]>
Date: Fri, 18 May 2007 23:06:18 +0200

Hello Paul,

as you may see in the attached SVN-log i changed some code according 
your suggestions.
I additionally made some clarifications of function names.

If you would like to see the af_can.c completely please visit:
http://svn.berlios.de/svnroot/repos/socketcan/trunk/kernel/2.6/net/can/af_can.c

But this code in the projekt SVN is working for several kernel versions 
(which is removed by some scripts when creating a LKML netdev patch) - 
just for your information.

Best regards,
Oliver

-------- Original-Nachricht --------
Betreff: 	r311 - trunk/kernel/2.6/net/can
Datum: 	Fri, 18 May 2007 21:47:15 +0200
Von: 	[email-masked]
An: 	[email-masked]

Author: hartkopp
Date: 2007-05-18 21:47:14 +0200 (Fri, 18 May 2007)
New Revision: 311

Modified:
   trunk/kernel/2.6/net/can/af_can.c
Log:
Updated RCU removal of dev_rcv_lists structures in the case of CAN-interfaces
going down (in can_notifier). Thanks to Paul E. McKenny (IBM) who gave this
hint on netdev kernel mailinglist.

Modified: trunk/kernel/2.6/net/can/af_can.c
===================================================================
--- trunk/kernel/2.6/net/can/af_can.c	2007-05-16 09:03:21 UTC (rev 310)
+++ trunk/kernel/2.6/net/can/af_can.c	2007-05-18 19:47:14 UTC (rev 311)
@@ -454,31 +454,48 @@
 }
 EXPORT_SYMBOL(can_rx_register);
 
-static void can_rcv_lists_delete(struct rcu_head *rp)
+static void can_rx_delete_list(struct hlist_head *rl)
 {
+	struct receiver *r;
+	struct hlist_node *n;
+
+	hlist_for_each_entry_rcu(r, n, rl, list) {
+		hlist_del_rcu(&r->list);
+		kmem_cache_free(rcv_cache, r);
+	}
+}
+
+/*
+ * can_rx_delete_device - rcu callback for dev_rcv_lists structure removal
+ */
+static void can_rx_delete_device(struct rcu_head *rp)
+{
 	struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
+	int i;
 
+	/* remove all receivers hooked at this netdevice */
+	can_rx_delete_list(&d->rx_err);
+	can_rx_delete_list(&d->rx_all);
+	can_rx_delete_list(&d->rx_fil);
+	can_rx_delete_list(&d->rx_inv);
+	can_rx_delete_list(&d->rx_eff);
+
+	for (i = 0; i < 2048; i++)
+		can_rx_delete_list(&d->rx_sff[i]);
+
 	kfree(d);
 }
 
-static void can_rx_delete(struct rcu_head *rp)
+/*
+ * can_rx_delete_receiver - rcu callback for single receiver entry removal
+ */
+static void can_rx_delete_receiver(struct rcu_head *rp)
 {
 	struct receiver *r = container_of(rp, struct receiver, rcu);
 
 	kmem_cache_free(rcv_cache, r);
 }
 
-static void can_rx_delete_all(struct hlist_head *rl)
-{
-	struct receiver *r;
-	struct hlist_node *n;
-
-	hlist_for_each_entry_rcu(r, n, rl, list) {
-		hlist_del_rcu(&r->list);
-		call_rcu(&r->rcu, can_rx_delete);
-	}
-}
-
 /**
  * can_rx_unregister - unsubscribe CAN frames from a specific interface
  * @dev: pointer to netdevice (NULL => unsubcribe from 'all' CAN devices list)
@@ -556,7 +573,7 @@
 
 	/* schedule the receiver item for deletion */
 	if (r)
-		call_rcu(&r->rcu, can_rx_delete);
+		call_rcu(&r->rcu, can_rx_delete_receiver);
 
 	return ret;
 }
@@ -945,7 +962,6 @@
 	struct net_device *dev = (struct net_device *)data;
 	struct notifier *n;
 	struct dev_rcv_lists *d;
-	int i;
 
 	DBG("called for %s, msg = %lu\n", dev->name, msg);
 
@@ -986,25 +1002,16 @@
 		spin_lock_bh(&rcv_lists_lock);
 
 		d = find_dev_rcv_lists(dev);
-		if (d) {
+		if (d)
 			hlist_del_rcu(&d->list);
-
-			/* remove all receivers hooked at this netdevice */
-			can_rx_delete_all(&d->rx_err);
-			can_rx_delete_all(&d->rx_all);
-			can_rx_delete_all(&d->rx_fil);
-			can_rx_delete_all(&d->rx_inv);
-			can_rx_delete_all(&d->rx_eff);
-			for (i = 0; i < 2048; i++)
-				can_rx_delete_all(&d->rx_sff[i]);
-		} else
+		else
 			printk(KERN_ERR "can: notifier: receive list not "
 			       "found for dev %s\n", dev->name);
 
 		spin_unlock_bh(&rcv_lists_lock);
 
 		if (d)
-			call_rcu(&d->rcu, can_rcv_lists_delete);
+			call_rcu(&d->rcu, can_rx_delete_device);
 
 		break;
 	}

_______________________________________________
Socketcan-commit mailing list
[email-masked]
https://lists.berlios.de/mailman/listinfo/socketcan-commit