Re: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions

Jiri Pirko
2023-03-14T09:30:14Z

Sun, Mar 12, 2023 at 03:28:03AM CET, vadfed@meta.com wrote:

[...]

>+struct dpll_pin *
>+dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
>+ const struct dpll_pin_properties *prop)
>+{
>+ struct dpll_pin *pin;
>+ int ret;
>+
>+ pin = kzalloc(sizeof(*pin), GFP_KERNEL);
>+ if (!pin)
>+ return ERR_PTR(-ENOMEM);
>+ pin->dev_driver_id = device_drv_id;
>+ pin->clock_id = clock_id;
>+ pin->module = module;
>+ refcount_set(&pin->refcount, 1);
>+ if (WARN_ON(!prop->description)) {
>+ ret = -EINVAL;
>+ goto release;
>+ }
>+ pin->prop.description = kstrdup(prop->description, GFP_KERNEL);
>+ if (!pin->prop.description) {
>+ ret = -ENOMEM;
>+ goto release;
>+ }
>+ if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC ||
>+ prop->type > DPLL_PIN_TYPE_MAX)) {
>+ ret = -EINVAL;
>+ goto release;
>+ }
>+ pin->prop.type = prop->type;
>+ pin->prop.capabilities = prop->capabilities;
>+ pin->prop.freq_supported = prop->freq_supported;
>+ pin->prop.any_freq_min = prop->any_freq_min;
>+ pin->prop.any_freq_max = prop->any_freq_max;
>+ xa_init_flags(&pin->dpll_refs, XA_FLAGS_ALLOC);
>+ xa_init_flags(&pin->parent_refs, XA_FLAGS_ALLOC);
>+ ret = xa_alloc(&dpll_pin_xa, &pin->idx, pin,
>+ xa_limit_16b, GFP_KERNEL);
>+release:
>+ if (ret) {
>+ xa_destroy(&pin->dpll_refs);
>+ xa_destroy(&pin->parent_refs);
>+ kfree(pin->prop.description);
>+ kfree(pin->rclk_dev_name);
>+ kfree(pin);
>+ return ERR_PTR(ret);
>+ }

This is odd flow. Just return 0 before "release" and have the goto-label
dedicated to error path only.

>+
>+ return pin;
>+} …