lkml.org 
[lkml]   [2022]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCHv2 1/3] software node: Power management operations for software nodes
Hi Heikki,

saw this linked in your WSR and felt compelled to reply... ;)

On Thu, Oct 29, 2020 at 01:59:39PM +0300, Heikki Krogerus wrote:
> +static int software_node_runtime_suspend(struct device *dev)
> +{
> + struct swnode_pm_domain *domain = to_swnode_pm_domain(dev->pm_domain);
> + struct swnode *swnode = dev_to_swnode(dev);
> + int ret;
> +
> + if (domain->primary && domain->primary->ops.runtime_suspend)
> + ret = domain->primary->ops.runtime_suspend(dev);
> + else if (dev->type && dev->type->pm && dev->type->pm->runtime_suspend)
> + ret = dev->type->pm->runtime_suspend(dev);
> + else if (dev->class && dev->class->pm && dev->class->pm->runtime_suspend)
> + ret = dev->class->pm->runtime_suspend(dev);
> + else if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend)
> + ret = dev->bus->pm->runtime_suspend(dev);
> + else
> + ret = pm_generic_runtime_suspend(dev);

This if/else ladder seems to be duplicated for every single PM callback
in this patch.

Code size can be reduced significantly if you use offsetof() to determine
the offset of the given callback in struct pm_ops, then pass that offset
to a helper which contains the above-quoted if/else ladder and retrieves
the callback. Finally invoke the callback you've just retrieved.

That way you only need the if/else ladder once in your patch.

For an example, see pcie_port_device_iter() and its callers
pcie_port_device_suspend() and so on:

https://elixir.bootlin.com/linux/latest/source/drivers/pci/pcie/portdrv_core.c#L372

Thanks,

Lukas

\
 
 \ /
  Last update: 2022-03-25 17:43    [W:0.109 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site