sysfs: release mutex when kmalloc() failed in sysfs_open_file().
--
fs/sysfs/file.c +1 -0
@@ -283,6 +283,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)mutex_lock (&inode->i_mutex);if (!(set = inode->i_private)) {if (!(set = inode->i_private =kmalloc (sizeof (struct sysfs_buffer_collection ),GFP_KERNEL ))) { +mutex_unlock (&inode->i_mutex); error = -ENOMEM ; goto Done; }else {
Signature · 2 lines
YOSHIFUJI Hideaki @ USAGI Project <[email protected]> GPG-FP : 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
fs/sysfs/file.c static int sysfs_open_file(struct inode *inode, struct file *file) · line 289
Quoted 8 lines · On Tue, Jul 10, 2007 at 01:56:46PM +0900, YOSHIFUJI Hideaki / ?$B5HF#1QL@ wrote:
fs/sysfs/file.c +1
-0@@ -283,6 +283,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)mutex_lock (&inode->i_mutex);if (!(set = inode->i_private)) {if (!(set = inode->i_private =kmalloc (sizeof (struct sysfs_buffer_collection ),GFP_KERNEL ))) { +mutex_unlock (&inode->i_mutex); error = -ENOMEM ; goto Done; }else {
Not related to your code, but whoever wrote this code originally deserves a big slap in the face for writing such obsfucated code. This should be something like:
mutex_lock(&inode->i_mutex);
set = inode->i_private;
if (!set) {
set = kmalloc(sizeof(struct sysfs_buffer_collection),
GFP_KERNEL))) {
if (!set)
mutex_unlock(&inode->i_mutex);
error = -ENOMEM;
goto Done;
}
INIT_LIST_HEAD(&set->associates);
inode->i_private = set;
}
mutex_unlock(&inode->i_mutex);fs/sysfs/file.c static int sysfs_open_file(struct inode *inode, struct file *file) · line 289
Quoted 12 lines · On Tue, 10 Jul 2007 13:56:46 +0900 (JST) YOSHIFUJI Hideaki / 吉藤英明…
fs/sysfs/file.c +1
-0@@ -283,6 +283,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)mutex_lock (&inode->i_mutex);if (!(set = inode->i_private)) {if (!(set = inode->i_private =kmalloc (sizeof (struct sysfs_buffer_collection ),GFP_KERNEL ))) { +mutex_unlock (&inode->i_mutex); error = -ENOMEM ; goto Done; }else {
All this code is totally different in Greg's development tree, so this fix really is only applicable to 2.6.22.x.
I suppose we could apply this to -stable, but given GFP_KERNEL's present behaviour for small allocations it's pretty theoretical.
Unless you've enabled fault-injection in the page allocator, or if you get oom-killed in that allocation. In which case your kernel is dead.
So hm, perhaps you'd best send this to [email protected].