lkml.org 
[lkml]   [2013]   [Apr]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] exofs: don't increase urilen if k realloc() fails
Without the patch, edp->urilen is increased before krealloc(). If krealloc() fails,
edp->urilen is too high. Fix that by only updating edp->urilen if krealloc() is successful.

Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
---
fs/exofs/sys.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/exofs/sys.c b/fs/exofs/sys.c
index 1b4f2f9..79b0a85 100644
--- a/fs/exofs/sys.c
+++ b/fs/exofs/sys.c
@@ -82,11 +82,11 @@ static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len)
{
uint8_t *new_uri;

- edp->urilen = strlen(buf) + 1;
- new_uri = krealloc(edp->uri, edp->urilen, GFP_KERNEL);
+ new_uri = krealloc(edp->uri, strlen(buf) + 1, GFP_KERNEL);
if (new_uri == NULL)
return -ENOMEM;
edp->uri = new_uri;
+ edp->urilen = strlen(buf) + 1;
strncpy(edp->uri, buf, edp->urilen);
return edp->urilen;
}
-- 1.7.1


\
 
 \ /
  Last update: 2013-04-28 14:21    [W:0.030 / U:0.564 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site