Skip to contentSkip to conversation

PM / devfreq: event: Call of_node_put() only once in devfreq_event_get_edev_by_phandle()

PATCH Applied Markus Elfring 2 participants 2 messages Oct 3, 2024 – Dec 8, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: event: Call of_node_put() only once in devfreq_event_get_edev_by_phandle()

From: Markus Elfring <[email protected]>
Date: Thu, 3 Oct 2024 11:01:30 +0200

An of_node_put(node) call was immediately used after a null pointer check for the local variable “edev” at the end of this function implementation. Thus call such a function only once instead directly before the check.

This issue was transformed by using the Coccinelle software.

---
 drivers/devfreq/devfreq-event.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/devfreq/devfreq-event.c +2 -6
index 3ebac2496679..70219099c604 100644
@@ -244,13 +244,9 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
 	edev = NULL;
 out:
 	mutex_unlock(&devfreq_event_list_lock);
-
-	if (!edev) {
-		of_node_put(node);
-		return ERR_PTR(-ENODEV);
-	}
-
 	of_node_put(node);
+	if (!edev)
+		return ERR_PTR(-ENODEV);
 
 	return edev;
 }

--
2.46.1

Applied
#1 lore raw

Hi,

Applied it. Thanks.

Quoted 39 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 3 Oct 2024 11:01:30 +0200

An of_node_put(node) call was immediately used after a null pointer check for the local variable “edev” at the end of this function implementation. Thus call such a function only once instead directly before the check.

This issue was transformed by using the Coccinelle software.

---
 drivers/devfreq/devfreq-event.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/devfreq/devfreq-event.c +2 -7
index 3ebac2496679..70219099c604 100644
@@ -244,13 +244,9 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
        edev = NULL;
 out:
        mutex_unlock(&devfreq_event_list_lock);
-
-       if (!edev) {
-               of_node_put(node);
-               return ERR_PTR(-ENODEV);
-       }
-
        of_node_put(node);
+       if (!edev)
+               return ERR_PTR(-ENODEV);
 
        return edev;
 }
--

2.46.1

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics