Re: [PATCH V3 15/20] cxl: Add a routine to find cxl root decoder on cxl bus using cxl port

Dave Jiang
2025-10-06T16:02:50Z

On 9/29/25 6:40 AM, Neeraj Kumar wrote:
> On 24/09/25 11:11AM, Dave Jiang wrote:
>>
>>> +struct cxl_root_decoder *cxl_find_root_decoder_by_port(struct cxl_port *port)
>>> +{
>>> +    struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
>>> +    struct device *dev;
>>> +
>>> +    if (!cxl_root)
>>> +        return NULL;
>>> +
>>> +    dev = device_find_child(&cxl_root->port.dev, NULL, match_root_decoder);
>>> +    if (!dev)
>>> +        return NULL;
>>> +
>>> +    /* Release device ref taken via device_find_child() */
>>> +    put_device(dev);
>>
>> Should the caller release the device reference instead?
>>
>> DJ
>
> Actually caller of this function wants to find root decoder information from cxl_port.
> So in order to find root decoder we have used device_find_child() which internally
> takes device ref. Therefore, just after finding the appropriate dev, I am releasing
> device ref.
> Its like taking device ref temporarly and releasing it then and there after finding
> proper root decoder.
> I believe, Releasing device ref from caller would make it look little out of context.

With the caller acquiring the root decoder, it should hold a reference until it is done with it. See usages of cxl_find_root_decoder(). i.e. core/region.c:cxl_add_to_region(). cxl_find_root_decoder_by_port() should do something similar.

DJ

>
>
> Regards,
> Neeraj
>