Re: [BUG] mm: bdi: export BDI attributes in sysfs

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Miklos Szeredi <miklos@...>
Cc: <ajones@...>, <a.p.zijlstra@...>, <mszeredi@...>, <akpm@...>, <kay.sievers@...>, <greg@...>, <trond.myklebust@...>, <linux-kernel@...>
Date: Thursday, May 15, 2008 - 3:18 pm

On Thu, 15 May 2008, Miklos Szeredi wrote:

Yeah, don't do this:


This kind of serialization can often hide bugs, and in some cases even 
make them go away (if the caller of the function means that the device is 
pinned and the tear-down cannot happen, for example), but it's really 
really bad form.

In order to use locking in a repeatable manner that is easy to think 
about, you really need to *keep* the lock until you've stopped using the 
data (or have dereferenced it into a stable form - eg maybe accessing the 
pointer itself needs locking, but some individual data read _off_ the 
pointer does not).

So the above kind of "get and release the lock" does obviously serialize 
wrt others that hold the lock, but it's still wrong.


You should just get the lock in the routines that acually use this thing.

Or, if the "struct backing_dev_info *" pointer itself is stable, and it 
really is just the access from "struct device" that needs protection, then 
at the very least it should have been

	static struct backing_dev_info *dev_get_bdi(struct device *dev)
	{
		struct backing_dev_info *bdi;

		mutex_lock(&bdi_dev_mutex);
		bdi = dev_get_drvdata(dev);
		mutex_unlock(&bdi_dev_mutex);
		return bdi;
	}

which makes it clear that it's the "dev_get_drvdata()" that needs the 
locking, not the bdi pointer itself.

		Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Arthur Jones, (Wed May 14, 10:40 am)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Miklos Szeredi, (Thu May 15, 2:53 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Arthur Jones, (Thu May 15, 4:44 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Linus Torvalds, (Thu May 15, 3:18 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Miklos Szeredi, (Thu May 15, 3:27 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Linus Torvalds, (Thu May 15, 3:54 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Arthur Jones, (Thu May 15, 6:05 pm)
Re: [BUG] mm: bdi: export BDI attributes in sysfs, Greg KH, (Fri May 16, 12:59 am)