aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/apei/erst-dbg.c
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2010-09-29 19:53:54 +0800
committerLen Brown <len.brown@intel.com>2010-09-29 14:02:35 -0400
commit23f124ca3dda98496b7ccf897cfd66264a212b6c (patch)
tree7b60b3de8e5fb0ee000eb97ea0abba1b25b868c6 /drivers/acpi/apei/erst-dbg.c
parentACPI, APEI, HEST Fix the unsuitable usage of platform_data (diff)
downloadlinux-dev-23f124ca3dda98496b7ccf897cfd66264a212b6c.tar.xz
linux-dev-23f124ca3dda98496b7ccf897cfd66264a212b6c.zip
ACPI, APEI, Fix error path for memory allocation
In ERST debug/test support patch, a dynamic allocated buffer is used. The may-failed memory allocation should be tried firstly before free the previous buffer. APEI resource management memory allocation related error path is fixed too. v2: - Fix error messages for APEI resources management Signed-off-by: Huang Ying <ying.huang@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to '')
-rw-r--r--drivers/acpi/apei/erst-dbg.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/drivers/acpi/apei/erst-dbg.c b/drivers/acpi/apei/erst-dbg.c
index 5281ddda2777..8561cfefa3dc 100644
--- a/drivers/acpi/apei/erst-dbg.c
+++ b/drivers/acpi/apei/erst-dbg.c
@@ -111,11 +111,13 @@ retry:
goto out;
}
if (len > erst_dbg_buf_len) {
- kfree(erst_dbg_buf);
+ void *p;
rc = -ENOMEM;
- erst_dbg_buf = kmalloc(len, GFP_KERNEL);
- if (!erst_dbg_buf)
+ p = kmalloc(len, GFP_KERNEL);
+ if (!p)
goto out;
+ kfree(erst_dbg_buf);
+ erst_dbg_buf = p;
erst_dbg_buf_len = len;
goto retry;
}
@@ -150,11 +152,13 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
if (mutex_lock_interruptible(&erst_dbg_mutex))
return -EINTR;
if (usize > erst_dbg_buf_len) {
- kfree(erst_dbg_buf);
+ void *p;
rc = -ENOMEM;
- erst_dbg_buf = kmalloc(usize, GFP_KERNEL);
- if (!erst_dbg_buf)
+ p = kmalloc(usize, GFP_KERNEL);
+ if (!p)
goto out;
+ kfree(erst_dbg_buf);
+ erst_dbg_buf = p;
erst_dbg_buf_len = usize;
}
rc = copy_from_user(erst_dbg_buf, ubuf, usize);