public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* sysfs: release mutex when kmalloc() failed in sysfs_open_file().
@ 2007-07-10  4:56 YOSHIFUJI Hideaki / 吉藤英明
  2007-07-10 11:55 ` Christoph Hellwig
  2007-07-13  5:24 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2007-07-10  4:56 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>

--
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index b502c71..1f64ce5 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -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 {

-- 
YOSHIFUJI Hideaki @ USAGI Project  <yoshfuji@linux-ipv6.org>
GPG-FP  : 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: sysfs: release mutex when kmalloc() failed in sysfs_open_file().
  2007-07-10  4:56 sysfs: release mutex when kmalloc() failed in sysfs_open_file() YOSHIFUJI Hideaki / 吉藤英明
@ 2007-07-10 11:55 ` Christoph Hellwig
  2007-07-13  5:24 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2007-07-10 11:55 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / ?$B5HF#1QL@; +Cc: gregkh, linux-kernel

On Tue, Jul 10, 2007 at 01:56:46PM +0900, YOSHIFUJI Hideaki / ?$B5HF#1QL@ wrote:
> @@ -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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sysfs: release mutex when kmalloc() failed in sysfs_open_file().
  2007-07-10  4:56 sysfs: release mutex when kmalloc() failed in sysfs_open_file() YOSHIFUJI Hideaki / 吉藤英明
  2007-07-10 11:55 ` Christoph Hellwig
@ 2007-07-13  5:24 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2007-07-13  5:24 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / 吉藤英明
  Cc: gregkh, linux-kernel, stable

On Tue, 10 Jul 2007 13:56:46 +0900 (JST) YOSHIFUJI Hideaki / 吉藤英明  <yoshfuji@linux-ipv6.org> wrote:

> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> index b502c71..1f64ce5 100644
> --- a/fs/sysfs/file.c
> +++ b/fs/sysfs/file.c
> @@ -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 stable@kernel.org.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-13  5:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-10  4:56 sysfs: release mutex when kmalloc() failed in sysfs_open_file() YOSHIFUJI Hideaki / 吉藤英明
2007-07-10 11:55 ` Christoph Hellwig
2007-07-13  5:24 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox