Skip to content

Commit ea9f885

Browse files
Igor Murzovlenb
authored andcommitted
ACPI video: Harden video bus adding.
It is always better to check return values, so add some new checks and correct existing ones. v2: Be consistent and don't mix errors from -E* and AE_* namespaces. Signed-off-by: Igor Murzov <e-mail@date.by> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent c16fa4f commit ea9f885

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

drivers/acpi/video.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -548,27 +548,27 @@ acpi_video_device_EDID(struct acpi_video_device *device,
548548
* 1. The system BIOS should NOT automatically control the brightness
549549
* level of the LCD when the power changes from AC to DC.
550550
* Return Value:
551-
* -1 wrong arg.
551+
* -EINVAL wrong arg.
552552
*/
553553

554554
static int
555555
acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
556556
{
557-
u64 status = 0;
557+
acpi_status status;
558558
union acpi_object arg0 = { ACPI_TYPE_INTEGER };
559559
struct acpi_object_list args = { 1, &arg0 };
560560

561561

562-
if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
563-
status = -1;
564-
goto Failed;
565-
}
562+
if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1)
563+
return -EINVAL;
566564
arg0.integer.value = (lcd_flag << 2) | bios_flag;
567565
video->dos_setting = arg0.integer.value;
568-
acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
566+
status = acpi_evaluate_object(video->device->handle, "_DOS",
567+
&args, NULL);
568+
if (ACPI_FAILURE(status))
569+
return -EIO;
569570

570-
Failed:
571-
return status;
571+
return 0;
572572
}
573573

574574
/*
@@ -1343,15 +1343,17 @@ static int
13431343
acpi_video_bus_get_devices(struct acpi_video_bus *video,
13441344
struct acpi_device *device)
13451345
{
1346-
int status = 0;
1346+
int status;
13471347
struct acpi_device *dev;
13481348

1349-
acpi_video_device_enumerate(video);
1349+
status = acpi_video_device_enumerate(video);
1350+
if (status)
1351+
return status;
13501352

13511353
list_for_each_entry(dev, &device->children, node) {
13521354

13531355
status = acpi_video_bus_get_one_device(dev, video);
1354-
if (ACPI_FAILURE(status)) {
1356+
if (status) {
13551357
printk(KERN_WARNING PREFIX
13561358
"Can't attach device\n");
13571359
continue;
@@ -1653,8 +1655,12 @@ static int acpi_video_bus_add(struct acpi_device *device)
16531655
mutex_init(&video->device_list_lock);
16541656
INIT_LIST_HEAD(&video->video_device_list);
16551657

1656-
acpi_video_bus_get_devices(video, device);
1657-
acpi_video_bus_start_devices(video);
1658+
error = acpi_video_bus_get_devices(video, device);
1659+
if (error)
1660+
goto err_free_video;
1661+
error = acpi_video_bus_start_devices(video);
1662+
if (error)
1663+
goto err_put_video;
16581664

16591665
video->input = input = input_allocate_device();
16601666
if (!input) {
@@ -1692,14 +1698,19 @@ static int acpi_video_bus_add(struct acpi_device *device)
16921698

16931699
video->pm_nb.notifier_call = acpi_video_resume;
16941700
video->pm_nb.priority = 0;
1695-
register_pm_notifier(&video->pm_nb);
1701+
error = register_pm_notifier(&video->pm_nb);
1702+
if (error)
1703+
goto err_unregister_input_dev;
16961704

16971705
return 0;
16981706

1707+
err_unregister_input_dev:
1708+
input_unregister_device(input);
16991709
err_free_input_dev:
17001710
input_free_device(input);
17011711
err_stop_video:
17021712
acpi_video_bus_stop_devices(video);
1713+
err_put_video:
17031714
acpi_video_bus_put_devices(video);
17041715
kfree(video->attached_array);
17051716
err_free_video:

0 commit comments

Comments
 (0)