Skip to contentSkip to conversation

Module refcounting in fs/proc/inode.c

PATCH Doug Ledford 1 participant 1 message Nov 18, 2002 Proc filesystem

lore
Share & tools
lore
#0 lore raw

This patch should make module ref counting safe in the proc filesystem. Without it, accessing /proc/scsi/aic7xxx/0 renders the aic7xxx module unloadable. However, I assume that we can call put_de() on the de we have at the time that the module ref inc attempt might fail. If that's not right, then someone who knows de ops will have to correct this patch.

Signature · 4 lines
  Doug Ledford <[email protected]>     919-754-3700 x44233
         Red Hat, Inc. 
         1801 Varsity Dr.
         Raleigh, NC 27606

===== fs/proc/inode.c 1.17 vs edited =====

fs/proc/inode.c +3 -2
@@ -73,7 +73,7 @@
 	de = PROC_I(inode)->pde;
 	if (de) {
 		if (de->owner)
-			__MOD_DEC_USE_COUNT(de->owner);
+			module_put(de->owner);
 		de_put(de);
 	}
 }
@@ -201,7 +201,8 @@
 		if (de->nlink)
 			inode->i_nlink = de->nlink;
 		if (de->owner)
-			__MOD_INC_USE_COUNT(de->owner);
+			if(!try_module_get(de->owner))
+				goto out_fail;
 		if (de->proc_iops)
 			inode->i_op = de->proc_iops;
 		if (de->proc_fops)