ACPI: video - add missing input_free_device()

If input_register_device() fails input_free_device() must
be called to release memory allocated for the device.
Also consolidate error handling in acpi_bus_video_add()
and handle input_allocate_device() failures.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Acked-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Dmitry Torokhov 2007-11-05 11:43:30 -05:00 committed by Len Brown
parent 91c05c667b
commit f51e83916a
1 changed files with 34 additions and 35 deletions

View File

@ -1897,14 +1897,10 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
static int instance; static int instance;
static int acpi_video_bus_add(struct acpi_device *device) static int acpi_video_bus_add(struct acpi_device *device)
{ {
int result = 0; acpi_status status;
acpi_status status = 0; struct acpi_video_bus *video;
struct acpi_video_bus *video = NULL;
struct input_dev *input; struct input_dev *input;
int error;
if (!device)
return -EINVAL;
video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
if (!video) if (!video)
@ -1923,13 +1919,13 @@ static int acpi_video_bus_add(struct acpi_device *device)
acpi_driver_data(device) = video; acpi_driver_data(device) = video;
acpi_video_bus_find_cap(video); acpi_video_bus_find_cap(video);
result = acpi_video_bus_check(video); error = acpi_video_bus_check(video);
if (result) if (error)
goto end; goto err_free_video;
result = acpi_video_bus_add_fs(device); error = acpi_video_bus_add_fs(device);
if (result) if (error)
goto end; goto err_free_video;
init_MUTEX(&video->sem); init_MUTEX(&video->sem);
INIT_LIST_HEAD(&video->video_device_list); INIT_LIST_HEAD(&video->video_device_list);
@ -1943,16 +1939,15 @@ static int acpi_video_bus_add(struct acpi_device *device)
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR, ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
"Error installing notify handler\n")); "Error installing notify handler\n"));
acpi_video_bus_stop_devices(video); error = -ENODEV;
acpi_video_bus_put_devices(video); goto err_stop_video;
kfree(video->attached_array);
acpi_video_bus_remove_fs(device);
result = -ENODEV;
goto end;
} }
video->input = input = input_allocate_device(); video->input = input = input_allocate_device();
if (!input) {
error = -ENOMEM;
goto err_uninstall_notify;
}
snprintf(video->phys, sizeof(video->phys), snprintf(video->phys, sizeof(video->phys),
"%s/video/input0", acpi_device_hid(video->device)); "%s/video/input0", acpi_device_hid(video->device));
@ -1972,18 +1967,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
set_bit(KEY_DISPLAY_OFF, input->keybit); set_bit(KEY_DISPLAY_OFF, input->keybit);
set_bit(KEY_UNKNOWN, input->keybit); set_bit(KEY_UNKNOWN, input->keybit);
result = input_register_device(input);
if (result) {
acpi_remove_notify_handler(video->device->handle,
ACPI_DEVICE_NOTIFY,
acpi_video_bus_notify);
acpi_video_bus_stop_devices(video);
acpi_video_bus_put_devices(video);
kfree(video->attached_array);
acpi_video_bus_remove_fs(device);
goto end;
}
error = input_register_device(input);
if (error)
goto err_free_input_dev;
printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
@ -1991,11 +1978,23 @@ static int acpi_video_bus_add(struct acpi_device *device)
video->flags.rom ? "yes" : "no", video->flags.rom ? "yes" : "no",
video->flags.post ? "yes" : "no"); video->flags.post ? "yes" : "no");
end: return 0;
if (result)
kfree(video);
return result; err_free_input_dev:
input_free_device(input);
err_uninstall_notify:
acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
acpi_video_bus_notify);
err_stop_video:
acpi_video_bus_stop_devices(video);
acpi_video_bus_put_devices(video);
kfree(video->attached_array);
acpi_video_bus_remove_fs(device);
err_free_video:
kfree(video);
acpi_driver_data(device) = NULL;
return error;
} }
static int acpi_video_bus_remove(struct acpi_device *device, int type) static int acpi_video_bus_remove(struct acpi_device *device, int type)