xen/acpi: xen memory hotplug minor updates
Dan Carpenter found current xen memory hotplug logic has potential issue: at func acpi_memory_get_device() *mem_device = 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@intel.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
parent
77be36de8b
commit
484400ffbf
|
@ -158,50 +158,46 @@ acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int acpi_memory_get_device(acpi_handle handle,
|
||||||
acpi_memory_get_device(acpi_handle handle,
|
|
||||||
struct acpi_memory_device **mem_device)
|
struct acpi_memory_device **mem_device)
|
||||||
{
|
{
|
||||||
acpi_status status;
|
|
||||||
acpi_handle phandle;
|
|
||||||
struct acpi_device *device = NULL;
|
struct acpi_device *device = NULL;
|
||||||
struct acpi_device *pdevice = NULL;
|
int result = 0;
|
||||||
int result;
|
|
||||||
|
|
||||||
if (!acpi_bus_get_device(handle, &device) && device)
|
acpi_scan_lock_acquire();
|
||||||
|
|
||||||
|
acpi_bus_get_device(handle, &device);
|
||||||
|
if (device)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
status = acpi_get_parent(handle, &phandle);
|
|
||||||
if (ACPI_FAILURE(status)) {
|
|
||||||
pr_warn(PREFIX "Cannot find acpi parent\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the parent device */
|
|
||||||
result = acpi_bus_get_device(phandle, &pdevice);
|
|
||||||
if (result) {
|
|
||||||
pr_warn(PREFIX "Cannot get acpi bus device\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now add the notified device. This creates the acpi_device
|
* Now add the notified device. This creates the acpi_device
|
||||||
* and invokes .add function
|
* and invokes .add function
|
||||||
*/
|
*/
|
||||||
result = acpi_bus_scan(handle);
|
result = acpi_bus_scan(handle);
|
||||||
if (result) {
|
if (result) {
|
||||||
pr_warn(PREFIX "Cannot add acpi bus\n");
|
pr_warn(PREFIX "ACPI namespace scan failed\n");
|
||||||
return -EINVAL;
|
result = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
result = acpi_bus_get_device(handle, &device);
|
||||||
|
if (result) {
|
||||||
|
pr_warn(PREFIX "Missing device object\n");
|
||||||
|
result = -EINVAL;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
*mem_device = acpi_driver_data(device);
|
*mem_device = acpi_driver_data(device);
|
||||||
if (!(*mem_device)) {
|
if (!(*mem_device)) {
|
||||||
pr_err(PREFIX "Driver data not found\n");
|
pr_err(PREFIX "driver data not found\n");
|
||||||
return -ENODEV;
|
result = -ENODEV;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
out:
|
||||||
|
acpi_scan_lock_release();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
|
static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
|
||||||
|
@ -259,12 +255,15 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
||||||
"\nReceived EJECT REQUEST notification for device\n"));
|
"\nReceived EJECT REQUEST notification for device\n"));
|
||||||
|
|
||||||
|
acpi_scan_lock_acquire();
|
||||||
if (acpi_bus_get_device(handle, &device)) {
|
if (acpi_bus_get_device(handle, &device)) {
|
||||||
|
acpi_scan_lock_release();
|
||||||
pr_err(PREFIX "Device doesn't exist\n");
|
pr_err(PREFIX "Device doesn't exist\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mem_device = acpi_driver_data(device);
|
mem_device = acpi_driver_data(device);
|
||||||
if (!mem_device) {
|
if (!mem_device) {
|
||||||
|
acpi_scan_lock_release();
|
||||||
pr_err(PREFIX "Driver Data is NULL\n");
|
pr_err(PREFIX "Driver Data is NULL\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +273,7 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
|
||||||
* acpi_bus_remove if Xen support hotremove in the future
|
* acpi_bus_remove if Xen support hotremove in the future
|
||||||
*/
|
*/
|
||||||
acpi_memory_disable_device(mem_device);
|
acpi_memory_disable_device(mem_device);
|
||||||
|
acpi_scan_lock_release();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue