[PATCH 1/2] xen/acpi: xen memory hotplug minor updates
From: Liu Jinsong
Date: Sat Feb 16 2013 - 03:59:03 EST
Dan Carpenter found current xen memory hotplug logic
has potential issue: at func acpi_memory_get_device()
*mem_device =3D acpi_driver_data(device);
while the device may be NULL and then dereference.
At native side, Rafael recently updated acpi_memory_get_device(),
dropping acpi_bus_add, adding lock, and avoiding above issue.
This patch updates xen memory hotplug logic accordingly, removing
redundant logic, adding lock, and avoiding dereference.
Signed-off-by: Liu Jinsong <jinsong.liu@xxxxxxxxx>
---
drivers/xen/xen-acpi-memhotplug.c | 52 ++++++++++++++++++---------------=
---
1 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/drivers/xen/xen-acpi-memhotplug.c b/drivers/xen/xen-acpi-memho=
tplug.c
index 853b12d..faef5b3 100644
--- a/drivers/xen/xen-acpi-memhotplug.c
+++ b/drivers/xen/xen-acpi-memhotplug.c
@@ -158,31 +158,17 @@ acpi_memory_get_device_resources(struct acpi_memory_d=
evice *mem_device)
return 0;
}
=20
-static int
-acpi_memory_get_device(acpi_handle handle,
- struct acpi_memory_device **mem_device)
+static int acpi_memory_get_device(acpi_handle handle,
+ struct acpi_memory_device **mem_device)
{
- acpi_status status;
- acpi_handle phandle;
struct acpi_device *device =3D NULL;
- struct acpi_device *pdevice =3D NULL;
- int result;
+ int result =3D 0;
=20
- if (!acpi_bus_get_device(handle, &device) && device)
- goto end;
+ acpi_scan_lock_acquire();
=20
- status =3D acpi_get_parent(handle, &phandle);
- if (ACPI_FAILURE(status)) {
- pr_warn(PREFIX "Cannot find acpi parent\n");
- return -EINVAL;
- }
-
- /* Get the parent device */
- result =3D acpi_bus_get_device(phandle, &pdevice);
- if (result) {
- pr_warn(PREFIX "Cannot get acpi bus device\n");
- return -EINVAL;
- }
+ acpi_bus_get_device(handle, &device);
+ if (device)
+ goto end;
=20
/*
* Now add the notified device. This creates the acpi_device
@@ -190,18 +176,28 @@ acpi_memory_get_device(acpi_handle handle,
*/
result =3D acpi_bus_scan(handle);
if (result) {
- pr_warn(PREFIX "Cannot add acpi bus\n");
- return -EINVAL;
+ pr_warn(PREFIX "ACPI namespace scan failed\n");
+ result =3D -EINVAL;
+ goto out;
+ }
+ result =3D acpi_bus_get_device(handle, &device);
+ if (result) {
+ pr_warn(PREFIX "Missing device object\n");
+ result =3D -EINVAL;
+ goto out;
}
=20
end:
*mem_device =3D acpi_driver_data(device);
if (!(*mem_device)) {
- pr_err(PREFIX "Driver data not found\n");
- return -ENODEV;
+ pr_err(PREFIX "driver data not found\n");
+ result =3D -ENODEV;
+ goto out;
}
=20
- return 0;
+out:
+ acpi_scan_lock_release();
+ return result;
}
=20
static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
@@ -259,12 +255,15 @@ static void acpi_memory_device_notify(acpi_handle han=
dle, u32 event, void *data)
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"\nReceived EJECT REQUEST notification for device\n"));
=20
+ acpi_scan_lock_acquire();
if (acpi_bus_get_device(handle, &device)) {
+ acpi_scan_lock_release();
pr_err(PREFIX "Device doesn't exist\n");
break;
}
mem_device =3D acpi_driver_data(device);
if (!mem_device) {
+ acpi_scan_lock_release();
pr_err(PREFIX "Driver Data is NULL\n");
break;
}
@@ -274,6 +273,7 @@ static void acpi_memory_device_notify(acpi_handle handl=
e, u32 event, void *data)
* acpi_bus_remove if Xen support hotremove in the future
*/
acpi_memory_disable_device(mem_device);
+ acpi_scan_lock_release();
break;
=20
default:
--=20
1.7.1
--_002_DE8DF0795D48FD4CA783C40EC82923353FCCC8SHSMSX101ccrcorpi_
Content-Type: application/octet-stream;
name="0001-xen-acpi-xen-memory-hotplug-minor-updates.patch"
Content-Description: 0001-xen-acpi-xen-memory-hotplug-minor-updates.patch
Content-Disposition: attachment;
filename="0001-xen-acpi-xen-memory-hotplug-minor-updates.patch"; size=3664;
creation-date="Sun, 17 Feb 2013 07:24:14 GMT";
modification-date="Sun, 17 Feb 2013 15:14:12 GMT"
Content-Transfer-Encoding: base64
Rn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lbGVhc2UoKTsKIAkJCXByX2VycihQUkVGSVgg
IkRldmljZSBkb2Vzbid0IGV4aXN0XG4iKTsKIAkJCWJyZWFrOwogCQl9CiAJCW1lbV9kZXZpY2Ug
PSBhY3BpX2RyaXZlcl9kYXRhKGRldmljZSk7CiAJCWlmICghbWVtX2RldmljZSkgeworCQkJYWNw
aV9zY2FuX2xvY2tfcmVsZWFzZSgpOwogCQkJcHJfZXJyKFBSRUZJWCAiRHJpdmVyIERhdGEgaXMg
TlVMTFxuIik7CiAJCQlicmVhazsKIAkJfQpAQCAtMjc0LDYgKzI3Myw3IEBAIHN0YXRpYyB2b2lk
IGFjcGlfbWVtb3J5X2RldmljZV9ub3RpZnkoYWNwaV9oYW5kbGUgaGFuZGxlLCB1MzIgZXZlbnQs
IHZvaWQgKmRhdGEpCiAJCSAqIGFjcGlfYnVzX3JlbW92ZSBpZiBYZW4gc3VwcG9ydCBob3RyZW1v
dmUgaW4gdGhlIGZ1dHVyZQogCQkgKi8KIAkJYWNwaV9tZW1vcnlfZGlzYWJsZV9kZXZpY2UobWVt
X2RldmljZSk7CisJCWFjcGlfc2Nhbl9sb2NrX3JlbGVhc2UoKTsKIAkJYnJlYWs7CiAKIAlkZWZh
dWx0OgotLSAKMS43LjEKCg==
--_002_DE8DF0795D48FD4CA783C40EC82923353FCCC8SHSMSX101ccrcorpi_--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/