Skip to contentSkip to conversation

ACPI: platform_profile: Fix memory leak in profile_class_is_visible()

PATCH Applied Kurt Borja 3 participants 5 messages Feb 12, 2025 – Feb 18, 2025 ACPI

lore
Share & tools
lore

Kurt Borja

author
#0 lore raw

PATCH 1/1 ACPI: platform_profile: Fix memory leak in profile_class_is_visible()

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")
---
 drivers/acpi/platform_profile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +7 -1
index fc92e43d0fe9..2ad53cc6aae5 100644
@@ -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;
 }
 

base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d

Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 36 lines · Kurt Borja

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")

---
 drivers/acpi/platform_profile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +7 -1
index fc92e43d0fe9..2ad53cc6aae5 100644
@@ -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;
 }
Quoted 3 lines

base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d

Signature · 1 line
2.48.1

Good find. Looks good to me.

Mark

maintainer Applied
#2 lore raw
Quoted 39 lines · Mark Pearson
Quoted 36 lines · Kurt Borja

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")

---
 drivers/acpi/platform_profile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +7 -1
index fc92e43d0fe9..2ad53cc6aae5 100644
@@ -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;
 }
Quoted 5 lines
Quoted 3 lines

base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d --
2.48.1

Good find. Looks good to me.

Applied as 6.15 material, thanks!

author
#3 lore raw
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Mark Pearson
Quoted 36 lines · Kurt Borja

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")

---
 drivers/acpi/platform_profile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +7 -1
index fc92e43d0fe9..2ad53cc6aae5 100644
@@ -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;
 }
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d --
2.48.1

Good find. Looks good to me.

Applied as 6.15 material, thanks!

Hi Rafael,

Thank you!

I believe this should be merged as a fix for v6.14-rc4 before commit 77be5cacb2c2 hits stable.

Signature · 1 line
 ~ Kurt
#4 lore raw
Quoted 48 lines · Kurt Borja
Quoted 46 lines · Rafael J. Wysocki
Quoted 44 lines · Mark Pearson
Quoted 36 lines · Kurt Borja

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")

---
 drivers/acpi/platform_profile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +7 -1
index fc92e43d0fe9..2ad53cc6aae5 100644
@@ -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;
 }
Quoted 3 lines

base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d --
2.48.1

Good find. Looks good to me.

Quoted 8 lines
Quoted 1 line

Applied as 6.15 material, thanks!

Hi Rafael,

Thank you!

I believe this should be merged as a fix for v6.14-rc4 before commit 77be5cacb2c2 hits stable.

I can queue it up for 6.14-rc, but that may not prevent 77be5cacb2c2 from going into -stable before it.

Thanks!