slram.c modifications

Jochen Schaeuble psionic at psionic.de
Thu Apr 26 05:49:20 EDT 2001


After reading the slram sources I found two things. First of all the

memset(mymtd, 0, sizeof(*mymtd));

In my opinion this is not neccesary because this is done two lines below this
one. The next thing I found is the

memset(mymtd->priv, 0, sizeof(struct mypriv));

If the allocation of the priv field failed above mymtd is set to NULL. If
the priv-field is accessed I guess this would lead to a segmentation fault.

Attached to this mail I send a patch to cover both this issues. I hope this
may be helpfull in some way.

jochen
-------------- next part --------------
Index: slram.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/slram.c,v
retrieving revision 1.14
diff -u -r1.14 slram.c
--- slram.c	2001/01/11 15:17:42	1.14
+++ slram.c	2001/04/26 09:38:41
@@ -156,8 +156,6 @@
 
 	mymtd = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
 	
-	memset(mymtd, 0, sizeof(*mymtd));
-	
 	if (mymtd)
 	{
 		memset((char *)mymtd, 0, sizeof(struct mtd_info));
@@ -166,8 +164,9 @@
 		{
 			kfree(mymtd);
 			mymtd = NULL;
+		} else {
+			memset(mymtd->priv, 0, sizeof(struct mypriv));
 		}
-		memset(mymtd->priv, 0, sizeof(struct mypriv));
 	}
 
 	if (!mymtd)


More information about the linux-mtd mailing list