Skip to contentSkip to conversation

usb: dwc3: add device put function to decrement the ref-counted reference

PATCH In review Stanley Chang 3 participants 6 messages Nov 7, 2023 – Nov 14, 2023

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

PATCH 1/1 usb: dwc3: add device put function to decrement the ref-counted reference

When the function exits, the count should be decremented via platform_device_put and of_node_put.

Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue layer driver")
---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +3 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644
@@ -187,6 +187,7 @@ static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np)
 
 	ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
 
+	of_node_put(dwc3_np);
 	return (ret < 0) ? USB_SPEED_UNKNOWN : ret;
 }
 
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
 
 	switch_usb2_role(rtk, rtk->cur_role);
 
+	platform_device_put(dwc3_pdev);
+	of_node_put(dwc3_node);
 	return 0;
 
 err_pdev_put:
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 22 lines · Stanley Chang

When the function exits, the count should be decremented via platform_device_put and of_node_put.

Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue layer driver")
---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +1 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644
@@ -187,6 +187,7 @@ static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np)
 
 	ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
 
+	of_node_put(dwc3_np);
 	return (ret < 0) ? USB_SPEED_UNKNOWN : ret;
 }
 

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) · line 343

Quoted 4 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
 
 	switch_usb2_role(rtk, rtk->cur_role);
 
+	platform_device_put(dwc3_pdev);

Don't you use this after probe? Why put here and not on remove?

BR,
Thinh

Quoted 7 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
+	of_node_put(dwc3_node);
 	return 0;
 
 err_pdev_put:
Signature · 1 line
2.34.1
#2 lore raw
Quoted 42 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Friday, November 10, 2023 10:34 AM
To: Stanley Chang[昌育德] <[email protected]>
Cc: Thinh Nguyen <[email protected]>; Christophe JAILLET <[email protected]>; Greg Kroah-Hartman <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v1] usb: dwc3: add device put function to decrement the ref-counted reference

External mail.

Quoted 23 lines · Stanley Chang

When the function exits, the count should be decremented via platform_device_put and of_node_put.

Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue

layer driver")

---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +1 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644
@@ -187,6 +187,7 @@ static enum usb_device_speed
 __get_dwc3_maximum_speed(struct device_node *np)
 
      ret = match_string(speed_names, ARRAY_SIZE(speed_names),
 maximum_speed);
 
+     of_node_put(dwc3_np);
      return (ret < 0) ? USB_SPEED_UNKNOWN : ret;  }
Quoted 8 lines

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct · line 344

Quoted 6 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct
 dwc3_rtk *rtk)
 
      switch_usb2_role(rtk, rtk->cur_role);
 
+     platform_device_put(dwc3_pdev);

Don't you use this after probe? Why put here and not on remove?

I don't use dwc3_pdev in driver.
I use rtk->dwc and dwc is removed by of_platform_depopulate on remove. So I think I don't need to keep the count of dwc3_pdev.

Thanks,
Stanley

Quoted 11 lines

BR,
Thinh

Quoted 7 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
+     of_node_put(dwc3_node);
      return 0;
 

err_pdev_put:
--
2.34.1

maintainer Acked-by
#3 lore raw
Quoted 47 lines · Stanley Chang[昌育德]
Quoted 47 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Friday, November 10, 2023 10:34 AM
To: Stanley Chang[昌育德] <[email protected]>
Cc: Thinh Nguyen <[email protected]>; Christophe JAILLET <[email protected]>; Greg Kroah-Hartman <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v1] usb: dwc3: add device put function to decrement the ref-counted reference

External mail.

Quoted 28 lines · Stanley Chang

When the function exits, the count should be decremented via platform_device_put and of_node_put.

Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue

layer driver")

---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +1 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644
@@ -187,6 +187,7 @@ static enum usb_device_speed
 __get_dwc3_maximum_speed(struct device_node *np)
 
      ret = match_string(speed_names, ARRAY_SIZE(speed_names),
 maximum_speed);
 
+     of_node_put(dwc3_np);
      return (ret < 0) ? USB_SPEED_UNKNOWN : ret;  }
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct
 dwc3_rtk *rtk)
 
      switch_usb2_role(rtk, rtk->cur_role);
 
Quoted 8 lines
Quoted 3 lines

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) · line 343

Quoted 1 line
drivers/usb/dwc3/dwc3-rtk.c +1 -0
+     platform_device_put(dwc3_pdev);

Don't you use this after probe? Why put here and not on remove?

I don't use dwc3_pdev in driver.
I use rtk->dwc and dwc is removed by of_platform_depopulate on remove. So I think I don't need to keep the count of dwc3_pdev.

Thanks for the clarification.

BR,
Thinh

#4 lore raw
In reply to Stanley Chang
Quoted 2 lines · Stanley Chang

When the function exits, the count should be decremented via platform_device_put and of_node_put.

This isn't really a self-contained commit message (and your use of 'count' is too vague). You're also changing two functions in two different ways here.

Quoted 11 lines
Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue layer driver")
---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +0 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644

drivers/usb/dwc3/dwc3-rtk.c static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) · line 190

Quoted 4 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
@@ -187,6 +187,7 @@ static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np)
 
 	ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
 
+	of_node_put(dwc3_np);

You're still leaking a reference in the of_property_read_string() error path just above.

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) · line 344

Quoted 9 lines
drivers/usb/dwc3/dwc3-rtk.c +2 -0
 	return (ret < 0) ? USB_SPEED_UNKNOWN : ret;
 }
 
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
 
 	switch_usb2_role(rtk, rtk->cur_role);
 
+	platform_device_put(dwc3_pdev);
+	of_node_put(dwc3_node);

Please keep the new line before return for readability.

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) · line 347

Quoted 3 lines
drivers/usb/dwc3/dwc3-rtk.c +0 -0
 	return 0;
 
 err_pdev_put:

Johan

#5 lore raw

Hi Johan,

Quoted 7 lines · Stanley Chang
Quoted 2 lines

When the function exits, the count should be decremented via platform_device_put and of_node_put.

This isn't really a self-contained commit message (and your use of 'count' is too vague). You're also changing two functions in two different ways here.

I will modify the commit message.

Quoted 14 lines
Quoted 14 lines
Fixes 34c200483569 ("usb: dwc3: add Realtek DHC RTD SoC dwc3 glue

layer driver")

---
 drivers/usb/dwc3/dwc3-rtk.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-rtk.c +0 -0
index 590028e8fdcb..9d6f2a8bd6ce 100644
@@ -187,6 +187,7 @@ static enum usb_device_speed
 __get_dwc3_maximum_speed(struct device_node *np)
 
Quoted 4 lines

drivers/usb/dwc3/dwc3-rtk.c static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) · line 190

Quoted 4 lines
drivers/usb/dwc3/dwc3-rtk.c +1 -0
      ret = match_string(speed_names, ARRAY_SIZE(speed_names),
 maximum_speed);
 
+     of_node_put(dwc3_np);

I will fixed this.

Thanks,
Stanley

Quoted 20 lines

You're still leaking a reference in the of_property_read_string() error path just above.

drivers/usb/dwc3/dwc3-rtk.c static int dwc3_rtk_probe_dwc3_core(struct · line 345

Quoted 9 lines
drivers/usb/dwc3/dwc3-rtk.c +2 -0
      return (ret < 0) ? USB_SPEED_UNKNOWN : ret;  }
@@ -339,6 +340,8 @@ static int dwc3_rtk_probe_dwc3_core(struct
 dwc3_rtk *rtk)
 
      switch_usb2_role(rtk, rtk->cur_role);
 
+     platform_device_put(dwc3_pdev);
+     of_node_put(dwc3_node);

Please keep the new line before return for readability.

Quoted 3 lines
drivers/usb/dwc3/dwc3-rtk.c +0 -0
      return 0;
 

err_pdev_put:

Johan