From: Gerrit Huizenga <gh@us.ibm.com>

Fix rule re-insertion to be more careful with empty lists.  Fix rule deletion
to not delete rules that are still in a list.

Signed-Off-By: Matt Helsley <matthltc@us.ibm.com>
Signed-Off-By: Gerrit Huizenga <gh@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 kernel/ckrm/rbce/rbce_main.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff -puN kernel/ckrm/rbce/rbce_main.c~ckrm-fix-edge-cases-with-empty-lists-and-rule-deletion kernel/ckrm/rbce/rbce_main.c
--- 25/kernel/ckrm/rbce/rbce_main.c~ckrm-fix-edge-cases-with-empty-lists-and-rule-deletion	Wed Jul 13 14:44:29 2005
+++ 25-akpm/kernel/ckrm/rbce/rbce_main.c	Wed Jul 13 14:44:29 2005
@@ -162,8 +162,8 @@ static int insert_rule(struct rbce_rule 
 			}
 		}
 	}
-	if (type == REINSERT)
-		list_del(&rule->obj.link);
+	if ((type == REINSERT) && !list_empty(&rule->obj.link))
+		list_del_init(&rule->obj.link);
 	else {
 		/*  protect the module from removed if a rule exists */
 		try_module_get(THIS_MODULE);
@@ -340,12 +340,14 @@ static void __release_rule(struct rbce_r
 static inline int __delete_rule(struct rbce_rule *rule)
 {
 	/* make sure we are not referenced by other rules */
+	if (list_empty(&rule->obj.link))
+		return 0;
 	if (GET_REF(rule))
 		return -EBUSY;
 	__release_rule(rule);
 	put_class(rule->target_class);
 	release_term_index(rule->index);
-	list_del(&rule->obj.link);
+	list_del_init(&rule->obj.link);
 	gl_num_rules--;
 	gl_rules_version++;
 	module_put(THIS_MODULE);
_