Commit 23f124ca authored by Huang Ying's avatar Huang Ying Committed by Len Brown

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: default avatarHuang Ying <ying.huang@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 1dd6b20e
...@@ -445,11 +445,15 @@ EXPORT_SYMBOL_GPL(apei_resources_sub); ...@@ -445,11 +445,15 @@ EXPORT_SYMBOL_GPL(apei_resources_sub);
int apei_resources_request(struct apei_resources *resources, int apei_resources_request(struct apei_resources *resources,
const char *desc) const char *desc)
{ {
struct apei_res *res, *res_bak; struct apei_res *res, *res_bak = NULL;
struct resource *r; struct resource *r;
int rc;
apei_resources_sub(resources, &apei_resources_all); rc = apei_resources_sub(resources, &apei_resources_all);
if (rc)
return rc;
rc = -EINVAL;
list_for_each_entry(res, &resources->iomem, list) { list_for_each_entry(res, &resources->iomem, list) {
r = request_mem_region(res->start, res->end - res->start, r = request_mem_region(res->start, res->end - res->start,
desc); desc);
...@@ -475,7 +479,11 @@ int apei_resources_request(struct apei_resources *resources, ...@@ -475,7 +479,11 @@ int apei_resources_request(struct apei_resources *resources,
} }
} }
apei_resources_merge(&apei_resources_all, resources); rc = apei_resources_merge(&apei_resources_all, resources);
if (rc) {
pr_err(APEI_PFX "Fail to merge resources!\n");
goto err_unmap_ioport;
}
return 0; return 0;
err_unmap_ioport: err_unmap_ioport:
...@@ -491,12 +499,13 @@ int apei_resources_request(struct apei_resources *resources, ...@@ -491,12 +499,13 @@ int apei_resources_request(struct apei_resources *resources,
break; break;
release_mem_region(res->start, res->end - res->start); release_mem_region(res->start, res->end - res->start);
} }
return -EINVAL; return rc;
} }
EXPORT_SYMBOL_GPL(apei_resources_request); EXPORT_SYMBOL_GPL(apei_resources_request);
void apei_resources_release(struct apei_resources *resources) void apei_resources_release(struct apei_resources *resources)
{ {
int rc;
struct apei_res *res; struct apei_res *res;
list_for_each_entry(res, &resources->iomem, list) list_for_each_entry(res, &resources->iomem, list)
...@@ -504,7 +513,9 @@ void apei_resources_release(struct apei_resources *resources) ...@@ -504,7 +513,9 @@ void apei_resources_release(struct apei_resources *resources)
list_for_each_entry(res, &resources->ioport, list) list_for_each_entry(res, &resources->ioport, list)
release_region(res->start, res->end - res->start); release_region(res->start, res->end - res->start);
apei_resources_sub(&apei_resources_all, resources); rc = apei_resources_sub(&apei_resources_all, resources);
if (rc)
pr_err(APEI_PFX "Fail to sub resources!\n");
} }
EXPORT_SYMBOL_GPL(apei_resources_release); EXPORT_SYMBOL_GPL(apei_resources_release);
......
...@@ -111,11 +111,13 @@ static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf, ...@@ -111,11 +111,13 @@ static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf,
goto out; goto out;
} }
if (len > erst_dbg_buf_len) { if (len > erst_dbg_buf_len) {
kfree(erst_dbg_buf); void *p;
rc = -ENOMEM; rc = -ENOMEM;
erst_dbg_buf = kmalloc(len, GFP_KERNEL); p = kmalloc(len, GFP_KERNEL);
if (!erst_dbg_buf) if (!p)
goto out; goto out;
kfree(erst_dbg_buf);
erst_dbg_buf = p;
erst_dbg_buf_len = len; erst_dbg_buf_len = len;
goto retry; goto retry;
} }
...@@ -150,11 +152,13 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf, ...@@ -150,11 +152,13 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
if (mutex_lock_interruptible(&erst_dbg_mutex)) if (mutex_lock_interruptible(&erst_dbg_mutex))
return -EINTR; return -EINTR;
if (usize > erst_dbg_buf_len) { if (usize > erst_dbg_buf_len) {
kfree(erst_dbg_buf); void *p;
rc = -ENOMEM; rc = -ENOMEM;
erst_dbg_buf = kmalloc(usize, GFP_KERNEL); p = kmalloc(usize, GFP_KERNEL);
if (!erst_dbg_buf) if (!p)
goto out; goto out;
kfree(erst_dbg_buf);
erst_dbg_buf = p;
erst_dbg_buf_len = usize; erst_dbg_buf_len = usize;
} }
rc = copy_from_user(erst_dbg_buf, ubuf, usize); rc = copy_from_user(erst_dbg_buf, ubuf, usize);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment