[PATCH net v5 1/4] dpll: fix broken error path in dpll_pin_alloc(..)

Arkadiusz Kubalewski posted 4 patches 1 year, 11 months ago
There is a newer version of this series
[PATCH net v5 1/4] dpll: fix broken error path in dpll_pin_alloc(..)
Posted by Arkadiusz Kubalewski 1 year, 11 months ago
If pin type is not expected, or dpll_pin_prop_dup(..) failed to
allocate memory, the unwind error path shall not destroy pin's xarrays,
which were not yet initialized.
Add new goto label and use it to fix broken error path.

Fixes: 9431063ad323 ("dpll: core: Add DPLL framework base functions")
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
v5:
- make this patch first in the series, previously was fourth

 drivers/dpll/dpll_core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c
index 1eca8cc271f8..c08772ee9fd6 100644
--- a/drivers/dpll/dpll_core.c
+++ b/drivers/dpll/dpll_core.c
@@ -441,7 +441,7 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module,
 	if (WARN_ON(prop->type < DPLL_PIN_TYPE_MUX ||
 		    prop->type > DPLL_PIN_TYPE_MAX)) {
 		ret = -EINVAL;
-		goto err;
+		goto err_pin_prop;
 	}
 	pin->prop = prop;
 	refcount_set(&pin->refcount, 1);
@@ -450,11 +450,12 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module,
 	ret = xa_alloc_cyclic(&dpll_pin_xa, &pin->id, pin, xa_limit_32b,
 			      &dpll_pin_xa_id, GFP_KERNEL);
 	if (ret)
-		goto err;
+		goto err_xa_alloc;
 	return pin;
-err:
+err_xa_alloc:
 	xa_destroy(&pin->dpll_refs);
 	xa_destroy(&pin->parent_refs);
+err_pin_prop:
 	kfree(pin);
 	return ERR_PTR(ret);
 }
-- 
2.38.1
Re: [PATCH net v5 1/4] dpll: fix broken error path in dpll_pin_alloc(..)
Posted by Jiri Pirko 1 year, 11 months ago
Thu, Jan 18, 2024 at 12:07:16PM CET, arkadiusz.kubalewski@intel.com wrote:
>If pin type is not expected, or dpll_pin_prop_dup(..) failed to
>allocate memory, the unwind error path shall not destroy pin's xarrays,
>which were not yet initialized.
>Add new goto label and use it to fix broken error path.
>
>Fixes: 9431063ad323 ("dpll: core: Add DPLL framework base functions")
>Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
RE: [PATCH net v5 1/4] dpll: fix broken error path in dpll_pin_alloc(..)
Posted by Kubalewski, Arkadiusz 1 year, 11 months ago
>From: Jiri Pirko <jiri@resnulli.us>
>Sent: Thursday, January 18, 2024 12:33 PM
>
>Thu, Jan 18, 2024 at 12:07:16PM CET, arkadiusz.kubalewski@intel.com wrote:
>>If pin type is not expected, or dpll_pin_prop_dup(..) failed to
>>allocate memory, the unwind error path shall not destroy pin's xarrays,
>>which were not yet initialized.
>>Add new goto label and use it to fix broken error path.
>>
>>Fixes: 9431063ad323 ("dpll: core: Add DPLL framework base functions")
>>Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
>
>Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Thank you!
Arkadiusz