From: Rafael J. Wysocki Date: Thu, 21 May 2026 14:09:35 +0000 (+0200) Subject: ACPI: video: Use devm action for video bus object cleanup X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=aad090a11389e17cacfbda62b963ddf709e5cc34;p=thirdparty%2Fkernel%2Flinux.git ACPI: video: Use devm action for video bus object cleanup Introduce acpi_video_bus_free() for freeing video bus object memory and reversing changes related to it made during ACPI video bus device probe, modify acpi_video_bus_probe() to add acpi_video_bus_free() as a devm action, and remove the code superseded by it from acpi_video_bus_remove(). No intentional functional impact. Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/3892168.MHq7AAxBmi@rafael.j.wysocki --- diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index ca2bee9679467..11dd00614f6b1 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -1953,6 +1953,14 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video) return 0; } +static void acpi_video_bus_free(void *data) +{ + struct acpi_video_bus *video = data; + + video->device->driver_data = NULL; + kfree(video); +} + static int duplicate_dev_check(struct device *sibling, void *data) { struct acpi_video_bus *video; @@ -2005,6 +2013,10 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev, video->device = device; device->driver_data = video; + error = devm_add_action_or_reset(dev, acpi_video_bus_free, video); + if (error) + return error; + /* * A hack to fix the duplicate name "VID" problem on T61 and the * duplicate name "VGA" problem on Pa 3553. @@ -2022,7 +2034,7 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev, acpi_video_bus_find_cap(video); error = acpi_video_bus_check(video); if (error) - goto err_free_video; + return error; mutex_init(&video->device_list_lock); INIT_LIST_HEAD(&video->video_device_list); @@ -2081,9 +2093,6 @@ err_del: err_put_video: acpi_video_bus_put_devices(video); kfree(video->attached_array); -err_free_video: - kfree(video); - device->driver_data = NULL; return error; } @@ -2104,9 +2113,6 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev) acpi_video_bus_unregister_backlight(video); acpi_video_bus_put_devices(video); kfree(video->attached_array); - - kfree(video); - device->driver_data = NULL; } static int __init is_i740(struct pci_dev *dev)