diff mbox

[v2,0/3] ACPI: video/apple-gmux: Fix apple gmux backlight detection

Message ID 20230124105754.62167-1-hdegoede@redhat.com (mailing list archive)
State Handled Elsewhere
Headers show

Commit Message

Hans de Goede Jan. 24, 2023, 10:57 a.m. UTC
Hi All,

Here is v2 of my series to fix apple-gmux detection in
the acpi_video_get_backlight_type() function.

Changes in v2:
- Fix leaking of adev reference returned by acpi_dev_get_first_match_dev()
  (Reported-by: Andy Shevchenko <andy.shevchenko@gmail.com>)
- Add list of known affected Apple models (Lukas Wunner)
- Add Reported-by and Link tags

Most of the changes are in the commit messages. Here is the actual code-diff
between v1 and v2 for fixing the adev leak:


Thank you Andy for pointing out this leak.

Note I plan to push this v2 to pdx86/fixes pretty much straight away after
sending this out, to give the builders some time to play with it. And then
if there is no negative feedback on this I'll include this in a fixes
pull-req to Linus later this week.

Regards,

Hans



Hans de Goede (3):
  platform/x86: apple-gmux: Move port defines to apple-gmux.h
  platform/x86: apple-gmux: Add apple_gmux_detect() helper
  ACPI: video: Fix apple gmux detection

 drivers/acpi/video_detect.c       |  24 +------
 drivers/platform/x86/apple-gmux.c |  93 +++++--------------------
 include/linux/apple-gmux.h        | 109 +++++++++++++++++++++++++++++-
 3 files changed, 128 insertions(+), 98 deletions(-)
diff mbox

Patch

--- a/include/linux/apple-gmux.h
+++ b/include/linux/apple-gmux.h
@@ -68,18 +68,19 @@  static inline bool apple_gmux_is_indexed(unsigned long iostart)
 static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
 {
 	u8 ver_major, ver_minor, ver_release;
+	struct device *dev = NULL;
+	struct acpi_device *adev;
 	struct resource *res;
 	bool indexed = false;
+	bool ret = false;
 
 	if (!pnp_dev) {
-		struct acpi_device *adev;
-		struct device *dev;
-
 		adev = acpi_dev_get_first_match_dev(GMUX_ACPI_HID, NULL, -1);
 		if (!adev)
 			return false;
 
-		dev = acpi_get_first_physical_node(adev);
+		dev = get_device(acpi_get_first_physical_node(adev));
+		acpi_dev_put(adev);
 		if (!dev)
 			return false;
 
@@ -87,11 +88,8 @@  static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
 	}
 
 	res = pnp_get_resource(pnp_dev, IORESOURCE_IO, 0);
-	if (!res)
-		return false;
-
-	if (resource_size(res) < GMUX_MIN_IO_LEN)
-		return false;
+	if (!res || resource_size(res) < GMUX_MIN_IO_LEN)
+		goto out;
 
 	/*
 	 * Invalid version information may indicate either that the gmux
@@ -103,13 +101,16 @@  static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
 	if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
 		indexed = apple_gmux_is_indexed(res->start);
 		if (!indexed)
-			return false;
+			goto out;
 	}
 
 	if (indexed_ret)
 		*indexed_ret = indexed;
 
-	return true;
+	ret = true;
+out:
+	put_device(dev);
+	return ret;
 }
 
 /**