Re: [PATCH 5/9] drm/panthor: Implement support for multiple power domains

Marek Vasut
2025-02-28T18:27:11Z

On 2/28/25 11:10 AM, Alexander Stein wrote:

Hi,

>> diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
>> index 51ee9cae94504..4348b7e917b64 100644
>> --- a/drivers/gpu/drm/panthor/panthor_device.c
>> +++ b/drivers/gpu/drm/panthor/panthor_device.c
>> @@ -75,6 +75,58 @@ static int panthor_reset_init(struct panthor_device *ptdev)
>> return 0;
>> }
>>
>> +/* Generic power domain handling code, see drivers/gpu/drm/tiny/simpledrm.c */
>> +static void panthor_detach_genpd(void *res)
>> +{
>> + struct panthor_device *ptdev = res;
>> + int i;
>> +
>> + if (ptdev->pwr_dom_count <= 1)
>> + return;
>> +
>> + for (i = ptdev->pwr_dom_count - 1; i >= 0; i--)
>> + dev_pm_domain_detach(ptdev->pwr_dom_devs[i], true);
>> +}
>> +
>> +static int panthor_genpd_init(struct panthor_device *ptdev)
>> +{
>> + struct device *dev = ptdev->base.dev;
>> + int i, ret;
>> +
>> + ptdev->pwr_dom_count = of_count_phandle_with_args(dev->of_node, "power-domains",
>> + "#power-domain-cells");
>> + /*
>> + * Single power-domain devices are handled by driver core nothing to do
>> + * here. The same for device nodes without "power-domains" property.
>> + */
>> + if (ptdev->pwr_dom_count <= 1)
>> + return 0;
>> +
>> + if (ptdev->pwr_dom_count > ARRAY_SIZE(ptdev->pwr_dom_devs)) {
>> + drm_warn(&ptdev->base, "Too many power domains (%d) for this device\n",
>> + ptdev->pwr_dom_count);
>> + return -EINVAL;
>> + }
>> +
>> + for (i = 0; i < ptdev->pwr_dom_count; i++) {
>> + ptdev->pwr_dom_devs[i] = dev_pm_domain_attach_by_id(dev, i);
>> + if (!IS_ERR(ptdev->pwr_dom_devs[i]))
>> + continue;
>> +
>> + ret = PTR_ERR(ptdev->pwr_dom_devs[i]);
>> + if (ret != -EPROBE_DEFER) {
>> + drm_warn(&ptdev->base, "pm_domain_attach_by_id(%u) failed: %d\n", i, ret);
>> + continue;
>
> Is it a good idea to continue if a power-domain is missing? Any access might
> stuck completely. IMHO returning an error is more sensible.
> Also some dev_err_probe() should be added here.
Fixed both, thanks .