BUG: missing get_mtd_device when running cat /dev/mtdblock*

Jörn Engel joern at wohnheim.fh-wedel.de
Mon Jul 31 11:12:16 EDT 2006


On Mon, 31 July 2006 10:05:52 -0500, Josh Boyer wrote:
> On 7/31/06, Jörn Engel <joern at wohnheim.fh-wedel.de> wrote:
> >While debugging on a 2.6.5 kernel (with fairly recent mtd) I noticed
> >that mtdblock appears to be bypassing get_mtd_device().
> 
> Yes, it bypasses calling that.  But...
> 
> >Can anyone verify this on current mtd by adding a simple printk() to
> >get_mtd_device() and running cat /dev/mtdblock0 > /dev/null or so?
> >
> >I am assuming this is not desired behaviour and should get fixed.
> 
> It seems mtd_blkdevs.c handles the reference counting itself.  See
> blktrans_open.  Most certainly this could be changed to call
> get_mtd_device instead, but I believe all the locking is correct as it
> stands.
> 
> Might want to double check though.

Well, the gluebi patch does not work with that.  Among other things,
gluebi introduced two new methods to struct mtd_info:

+	int (*open) (struct mtd_info *mtd);
+	int (*close) (struct mtd_info *mtd);

And these need to get called before/after devices get accessed.  I
believed the following to be sufficient:

@@ -298,8 +298,12 @@ struct mtd_info *get_mtd_device(struct m
 	if (ret && !try_module_get(ret->owner))
 		ret = NULL;
 
-	if (ret)
+	if (ret) {
+		if (ret->usecount == 0)
+			if (ret->open)
+				ret->open(ret);
 		ret->usecount++;
+	}
 
 	up(&mtd_table_mutex);
 	return ret;
@@ -311,6 +315,9 @@ void put_mtd_device(struct mtd_info *mtd
 
 	down(&mtd_table_mutex);
 	c = --mtd->usecount;
+	if (c == 0)
+		if (mtd->close)
+			mtd->close(mtd);
 	up(&mtd_table_mutex);
 	BUG_ON(c < 0);
 

Looks like it isn't.  And I don't see a good reason why it shouldn't
be enough.

Jörn

-- 
All art is but imitation of nature.
-- Lucius Annaeus Seneca




More information about the linux-mtd mailing list