clocksource/drivers/sun5i: Handle error returns from devm_reset_control_get_optional_exclusive()

Message ID 20260205084037.3661261-1-nichen@iscas.ac.cn (mailing list archive)
State New
Headers
Series clocksource/drivers/sun5i: Handle error returns from devm_reset_control_get_optional_exclusive() |

Commit Message

Chen Ni Feb. 5, 2026, 8:40 a.m. UTC
The devm_reset_control_get_optional_exclusive() function may return an
ERR_PTR in case of genuine reset control acquisition errors, not just
NULL which indicates the legitimate absence of an optional reset.

Add an IS_ERR() check after the call in sun5i_timer_probe(). On error,
return the error code to ensure proper failure handling rather than
proceeding with invalid pointers.

Fixes: 7e5bac610d2f ("clocksource/drivers/sun5i: Convert to platform device driver")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 drivers/clocksource/timer-sun5i.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Chen-Yu Tsai Feb. 24, 2026, 2:51 p.m. UTC | #1
On Thu, Feb 5, 2026 at 4:42 PM Chen Ni <nichen@iscas.ac.cn> wrote:
>
> The devm_reset_control_get_optional_exclusive() function may return an
> ERR_PTR in case of genuine reset control acquisition errors, not just
> NULL which indicates the legitimate absence of an optional reset.
>
> Add an IS_ERR() check after the call in sun5i_timer_probe(). On error,
> return the error code to ensure proper failure handling rather than
> proceeding with invalid pointers.
>
> Fixes: 7e5bac610d2f ("clocksource/drivers/sun5i: Convert to platform device driver")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>

Acked-by: Chen-Yu Tsai <wens@kernel.org>
  
Daniel Lezcano March 4, 2026, 7:35 p.m. UTC | #2
On Thu, Feb 05, 2026 at 04:40:37PM +0800, Chen Ni wrote:
> The devm_reset_control_get_optional_exclusive() function may return an
> ERR_PTR in case of genuine reset control acquisition errors, not just
> NULL which indicates the legitimate absence of an optional reset.
> 
> Add an IS_ERR() check after the call in sun5i_timer_probe(). On error,
> return the error code to ensure proper failure handling rather than
> proceeding with invalid pointers.
> 
> Fixes: 7e5bac610d2f ("clocksource/drivers/sun5i: Convert to platform device driver")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---

Applied, thanks
  

Patch

diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index f827d3f98f60..d7e012992170 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -286,6 +286,9 @@  static int sun5i_timer_probe(struct platform_device *pdev)
 	}
 
 	rstc = devm_reset_control_get_optional_exclusive(dev, NULL);
+	if (IS_ERR(rstc))
+		return dev_err_probe(dev, PTR_ERR(rstc),
+				     "failed to get reset\n");
 	if (rstc)
 		reset_control_deassert(rstc);