The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Hans de Goede <hansg@kernel.org>, Armin Wolf <w_armin@gmx.de>
Subject: [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices
Date: Thu, 21 May 2026 16:10:13 +0200	[thread overview]
Message-ID: <1932803.atdPhlSkOF@rafael.j.wysocki> (raw)
In-Reply-To: <4739447.LvFx2qVVIh@rafael.j.wysocki>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

Rename acpi_video_bus_put_devices() to devm_acpi_video_bus_get_devices()
and turn acpi_video_bus_put_devices() into a devm action added by it for
freeing the video devices allocated by it and the attached_array memory.

Accordingly, remove the acpi_video_bus_put_devices() calls and
attached_array freeing from acpi_video_bus_remove() and the rollback
path in acpi_video_bus_probe().

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/acpi_video.c | 53 +++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 11dd00614f6b..a02eaf13f5d8 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1494,10 +1494,31 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
 }
 EXPORT_SYMBOL(acpi_video_get_edid);
 
-static int
-acpi_video_bus_get_devices(struct acpi_video_bus *video,
-			   struct acpi_device *device)
+static void acpi_video_bus_put_devices(void *data)
+{
+	struct acpi_video_bus *video = data;
+	struct acpi_video_device *dev, *next;
+
+	mutex_lock(&video->device_list_lock);
+	list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
+		list_del(&dev->entry);
+		kfree(dev);
+	}
+	mutex_unlock(&video->device_list_lock);
+
+	kfree(video->attached_array);
+	video->attached_array = NULL;
+}
+
+static int devm_acpi_video_bus_get_devices(struct device *dev,
+					   struct acpi_video_bus *video)
 {
+	int ret;
+
+	ret = devm_add_action(dev, acpi_video_bus_put_devices, video);
+	if (ret)
+		return ret;
+
 	/*
 	 * There are systems where video module known to work fine regardless
 	 * of broken _DOD and ignoring returned value here doesn't cause
@@ -1505,7 +1526,8 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
 	 */
 	acpi_video_device_enumerate(video);
 
-	return acpi_dev_for_each_child(device, acpi_video_bus_get_one_device, video);
+	return acpi_dev_for_each_child(video->device,
+				       acpi_video_bus_get_one_device, video);
 }
 
 /* acpi_video interface */
@@ -1939,20 +1961,6 @@ static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
 	video->input = NULL;
 }
 
-static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
-{
-	struct acpi_video_device *dev, *next;
-
-	mutex_lock(&video->device_list_lock);
-	list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
-		list_del(&dev->entry);
-		kfree(dev);
-	}
-	mutex_unlock(&video->device_list_lock);
-
-	return 0;
-}
-
 static void acpi_video_bus_free(void *data)
 {
 	struct acpi_video_bus *video = data;
@@ -2039,9 +2047,9 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
 	mutex_init(&video->device_list_lock);
 	INIT_LIST_HEAD(&video->video_device_list);
 
-	error = acpi_video_bus_get_devices(video, device);
+	error = devm_acpi_video_bus_get_devices(dev, video);
 	if (error)
-		goto err_put_video;
+		return error;
 
 	/*
 	 * HP ZBook Fury 16 G10 requires ACPI video's child devices have _PS0
@@ -2090,9 +2098,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
 	list_del(&video->entry);
 	mutex_unlock(&video_list_lock);
 	acpi_video_bus_unregister_backlight(video);
-err_put_video:
-	acpi_video_bus_put_devices(video);
-	kfree(video->attached_array);
 
 	return error;
 }
@@ -2111,8 +2116,6 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
 	list_del(&video->entry);
 	mutex_unlock(&video_list_lock);
 	acpi_video_bus_unregister_backlight(video);
-	acpi_video_bus_put_devices(video);
-	kfree(video->attached_array);
 }
 
 static int __init is_i740(struct pci_dev *dev)
-- 
2.51.0





  parent reply	other threads:[~2026-05-21 14:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-06-02 18:50   ` Andy Shevchenko
2026-06-02 20:57     ` Rafael J. Wysocki
2026-06-02 21:58       ` Andy Shevchenko
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-05-25 15:40   ` Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 04/17] ACPI: battery: " Rafael J. Wysocki
2026-05-21 14:03 ` [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance Rafael J. Wysocki
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
2026-06-02 22:10   ` Andy Shevchenko
2026-06-03 10:51     ` Rafael J. Wysocki
2026-06-03 11:12       ` Andy Shevchenko
2026-05-21 14:04 ` [PATCH v1 07/17] ACPI: thermal: " Rafael J. Wysocki
2026-05-21 14:05 ` [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove() Rafael J. Wysocki
2026-05-21 14:07 ` [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code Rafael J. Wysocki
2026-05-21 14:09 ` [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup Rafael J. Wysocki
2026-05-21 14:10 ` Rafael J. Wysocki [this message]
2026-05-21 14:10 ` [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup Rafael J. Wysocki
2026-05-21 14:11 ` [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1932803.atdPhlSkOF@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=w_armin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox