[PATCH] fs/proc/generic.c: check proc_register result

From: Arnaldo Carvalho de Melo (acme@conectiva.com.br)
Date: Tue Aug 29 2000 - 19:33:53 EST


Linus,

        proc_register can fail and its result is not being checked, I've also
noticed that at one place (the first hunk in the patch below) it returns a
kfreed pointer on failure.

                        - Arnaldo

--- linux-2.4.0-test8-pre1/fs/proc/generic.c Thu Aug 24 07:40:11 2000
+++ linux-2.4.0-test8-pre1.acme/fs/proc/generic.c Tue Aug 29 21:27:10 2000
@@ -427,16 +427,17 @@
         ent->nlink = 1;
         ent->mode = S_IFLNK|S_IRUGO|S_IWUGO|S_IXUGO;
         ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
- if (!ent->data) {
- kfree(ent);
- goto out;
- }
+ if (!ent->data)
+ goto cleanup_ent;
         strcpy((char*)ent->data,dest);
 
- proc_register(parent, ent);
-
+ if (proc_register(parent, ent))
+ goto cleanup_data;
 out:
         return ent;
+cleanup_data: kfree(ent->data);
+cleanup_ent: kfree(ent);
+ return NULL;
 }
 
 struct proc_dir_entry *proc_mknod(const char *name, mode_t mode,
@@ -461,8 +462,10 @@
         ent->mode = mode;
         ent->rdev = rdev;
 
- proc_register(parent, ent);
-
+ if (proc_register(parent, ent)) {
+ kfree(ent);
+ return NULL;
+ }
 out:
         return ent;
 }
@@ -489,8 +492,10 @@
         ent->nlink = 2;
         ent->mode = S_IFDIR | S_IRUGO | S_IXUGO;
 
- proc_register(parent, ent);
-
+ if (proc_register(parent, ent)) {
+ kfree(ent);
+ return NULL;
+ }
 out:
         return ent;
 }
@@ -529,8 +534,10 @@
         }
         ent->mode = mode;
 
- proc_register(parent, ent);
-
+ if (proc_register(parent, ent)) {
+ kfree(ent);
+ return NULL;
+ }
 out:
         return ent;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Aug 31 2000 - 21:00:24 EST