* [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
@ 2010-06-19 18:13 JieJing.Zhang
2010-06-20 4:56 ` Zhang JieJing
0 siblings, 1 reply; 3+ messages in thread
From: JieJing.Zhang @ 2010-06-19 18:13 UTC (permalink / raw)
To: linux-btrfs; +Cc: JieJing.Zhang
set errno to -ENOMEM and goto out
Signed-off-by: JieJing.Zhang <kzjeef@gmail.com>
---
fs/btrfs/file.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e354c33..e0fcb6c 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
2010-06-19 18:13 [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write() JieJing.Zhang
@ 2010-06-20 4:56 ` Zhang JieJing
2010-07-03 17:35 ` Zhang JieJing
0 siblings, 1 reply; 3+ messages in thread
From: Zhang JieJing @ 2010-06-20 4:56 UTC (permalink / raw)
To: linux-btrfs
2010/6/20 JieJing.Zhang <kzjeef@gmail.com>
>
> set errno to -ENOMEM and goto out
>
> Signed-off-by: JieJing.Zhang <kzjeef@gmail.com>
> ---
> =A0fs/btrfs/file.c | =A0 =A04 ++++
> =A01 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e354c33..e0fcb6c 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -926,6 +926,10 @@ static ssize_t btrfs_file_aio_write(struct kiocb=
*iocb,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 PAGE_CACHE_SIZE, PAGE_CACHE_S=
IZE /
> =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
> + =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_checks can 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write()
2010-06-20 4:56 ` Zhang JieJing
@ 2010-07-03 17:35 ` Zhang JieJing
0 siblings, 0 replies; 3+ messages in thread
From: Zhang JieJing @ 2010-07-03 17:35 UTC (permalink / raw)
To: linux-btrfs; +Cc: linux-fsdevel, Chris Mason
This is the improved of the former patch.
>From d9c4cf7dd0e4489a31610e2fb2565ee29f0e4179 Mon Sep 17 00:00:00 2001
From: JieJing.Zhang <kzjeef@gmail.com>
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.
Signed-off-by: JieJing.Zhang <kzjeef@gmail.com>
---
fs/btrfs/file.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e354c33..961612c 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-03 17:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-19 18:13 [PATCH] Btrfs: handle kmalloc() failure in btrfs_file_aio_write() JieJing.Zhang
2010-06-20 4:56 ` Zhang JieJing
2010-07-03 17:35 ` Zhang JieJing
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).