Re: [RFC PATCH v8 03/10] dpll: core: Add DPLL framework base functions

From: Jakub Kicinski
Date: Mon Jun 12 2023 - 19:45:24 EST


On Fri, 9 Jun 2023 14:18:46 +0200 Arkadiusz Kubalewski wrote:
> + xa_for_each(xa_pins, i, ref) {
> + if (ref->pin != pin)
> + continue;
> + reg = dpll_pin_registration_find(ref, ops, priv);
> + if (reg) {
> + refcount_inc(&ref->refcount);
> + return 0;
> + }
> + ref_exists = true;
> + break;
> + }
> +
> + if (!ref_exists) {
> + ref = kzalloc(sizeof(*ref), GFP_KERNEL);
> + if (!ref)
> + return -ENOMEM;
> + ref->pin = pin;
> + INIT_LIST_HEAD(&ref->registration_list);
> + ret = xa_insert(xa_pins, pin->pin_idx, ref, GFP_KERNEL);
> + if (ret) {
> + kfree(ref);
> + return ret;
> + }
> + refcount_set(&ref->refcount, 1);
> + }
> +
> + reg = kzalloc(sizeof(*reg), GFP_KERNEL);

Why do we have two structures - ref and reg?

> + if (!reg) {
> + if (!ref_exists)
> + kfree(ref);

ref has already been inserted into xa_pins

> + return -ENOMEM;