From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECBB1C433F5 for ; Fri, 25 Mar 2022 16:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351535AbiCYQoe (ORCPT ); Fri, 25 Mar 2022 12:44:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344427AbiCYQod (ORCPT ); Fri, 25 Mar 2022 12:44:33 -0400 Received: from bmailout3.hostsharing.net (bmailout3.hostsharing.net [IPv6:2a01:4f8:150:2161:1:b009:f23e:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13854E09BA; Fri, 25 Mar 2022 09:42:58 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1" (verified OK)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id A4AF810306A7A; Fri, 25 Mar 2022 17:42:55 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 7E20F2BC2EC; Fri, 25 Mar 2022 17:42:55 +0100 (CET) Date: Fri, 25 Mar 2022 17:42:55 +0100 From: Lukas Wunner To: Heikki Krogerus Cc: "Rafael J. Wysocki" , Felipe Balbi , Andy Shevchenko , Sakari Ailus , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-acpi@vger.kernel.org Subject: Re: [PATCHv2 1/3] software node: Power management operations for software nodes Message-ID: <20220325164255.GA12710@wunner.de> References: <20201029105941.63410-1-heikki.krogerus@linux.intel.com> <20201029105941.63410-2-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201029105941.63410-2-heikki.krogerus@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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