Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
Subsystems (2)
PATCH 1/1 Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
set errno to -ENOMEM and goto out
--- fs/btrfs/file.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/btrfs/file.c +4 -0
@@ -926,6 +926,10 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,PAGE_CACHE_SIZE ,PAGE_CACHE_SIZE / (sizeof(struct page *))); pages =kmalloc (nrptrs *sizeof (struct page *),GFP_KERNEL ); +if (!pages) { + ret = -ENOMEM ; + goto out; + }/* generic_write_checks can change our pos */ start_pos = pos;
Signature · 1 line
1.7.0.4
2010/6/20 JieJing.Zhang <[email protected]>
fs/btrfs/file.c static ssize_t btrfs_file_aio_write(struct kiocb=
Quoted 13 lines
set errno to
-ENOMEMand goto outSigned-off-by JieJing.Zhang <[email protected]>---
=A0fs/btrfs/file.c | =A0 =A04 ++++
=A01 files changed, 4 insertions(+), 0 deletions(-)fs/btrfs/file.c +0
-0@@ -926,6 +926,10 @@ static ssize_t btrfs_file_aio_write(struct kiocb=
*iocb,
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
PAGE_CACHE_SIZE, PAGE_CACHE_S=
IZE /
Quoted 2 lines
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (
sizeof(struct page *))); =A0 =A0 =A0 =A0pages =3D kmalloc(nrptrs *sizeof(struct page *), GFP_=
KERNEL);
I think this gfp should changed to GFP_NOFS to avoid deadlock, right ? like this commit: 33818bbb84cd371b63ed8849cc5264d24c8b3aa2
Quoted 10 lines
+ =A0 =A0 =A0 if (!pages) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D-ENOMEM;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
+ =A0 =A0 =A0 }=A0 =A0 =A0 =A0/*
generic_write_checkscan change our pos */ =A0 =A0 =A0 =A0start_pos =3D pos;
--
1.7.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
This is the improved of the former patch.
Quoted 1 line
From
d9c4cf7dd0e4489a31610e2fb2565ee29f0e4179Mon Sep 17 00:00:00 2001
From: JieJing.Zhang <[email protected]>
Date: Sun, 4 Jul 2010 01:17:54 +0800
Subject: [PATCH] Btrfs: handle memory alloc failure in btrfs_file_aio_write()
1. kmalloc() should add a check of return valule.
2. In later code it memset zero to the allocated memory, so use kzalloc() instead of kmalloc() when allocation is better.
--- fs/btrfs/file.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/file.c +5 -2
@@ -925,7 +925,11 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, nrptrs =min ((iov_iter_count (&i) +PAGE_CACHE_SIZE -1 ) /PAGE_CACHE_SIZE ,PAGE_CACHE_SIZE / (sizeof (struct page *))); - pages =kmalloc (nrptrs *sizeof (struct page *),GFP_KERNEL ); + pages =kzalloc (nrptrs *sizeof (struct page *),GFP_KERNEL ); +if (!pages) { + ret = -ENOMEM ; + goto out; + }/* generic_write_checks can change our pos */ start_pos = pos;
@@ -968,7 +972,6 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,PAGE_CACHE_SHIFT ;WARN_ON (num_pages > nrptrs); -memset (pages,0 ,sizeof (struct page *) * nrptrs); ret =btrfs_delalloc_reserve_space (inode, write_bytes);if (ret)
Signature · 1 line
1.7.0.4