]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ACPI: platform_profile: Fix memory leak in profile_class_is_visible()
authorKurt Borja <kuurtb@gmail.com>
Wed, 12 Feb 2025 19:30:58 +0000 (14:30 -0500)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 18 Feb 2025 19:03:37 +0000 (20:03 +0100)
If class_find_device() finds a device, it's reference count is
incremented.

Call put_device() to drop this reference before returning.

Fixes: 77be5cacb2c2 ("ACPI: platform_profile: Create class for ACPI platform profile")
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Link: https://patch.msgid.link/20250212193058.32110-1-kuurtb@gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/platform_profile.c

index fc92e43d0fe93e04a25e8b96264b1666d89c829b..2ad53cc6aae5364e7f5c5787e49119037b49f172 100644 (file)
@@ -417,8 +417,14 @@ static int profile_class_registered(struct device *dev, const void *data)
 
 static umode_t profile_class_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
 {
-       if (!class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered))
+       struct device *dev;
+
+       dev = class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered);
+       if (!dev)
                return 0;
+
+       put_device(dev);
+
        return attr->mode;
 }