Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2060574pxb; Fri, 25 Mar 2022 10:23:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1szDSgafQNtUonGr0R5/BakcIaLlmnjL2RTNEmW+l9CXsefTulqP9IFdIh+LIUbcLKsnT X-Received: by 2002:a17:903:2288:b0:153:bfbe:7354 with SMTP id b8-20020a170903228800b00153bfbe7354mr12797552plh.112.1648228990126; Fri, 25 Mar 2022 10:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648228990; cv=none; d=google.com; s=arc-20160816; b=zGNbP1Vtox8ldUXtxZb9Q4teVOYqpW8hbEeTG6U+8/2aY+V76JO292o4yH3UT9BbQV 6xwtbQAIKTur9MPX4aiQ+c9HMB9mxAB4Nyuq/GZvR9+0P0zkWENIrjIprrPQsHMtxPz4 JUgb586WYk3GutLA2XERZsLFl5Snm4ZlWlP9ZLmT06FnBFPS6ec0zUOVI3F8YFaRj3II t1vx5R5/kBziTRaaaDIQR9bu48aWyg1XZEoS+S2gKc0mCGBNRXH6DATa45Dw2HBuBxMM oe4khDXV65ILOHTpi/mYmQ5Jd1VQ5mAHZl8ROlriN2V+Ut5yeko6ICnIWzBhzj+ylhg1 Dd1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Z37i/7gGmkg0BlxLIRmwH8jzG+XXy4Oo4qf3OihL4Nk=; b=J9dutQBPZh0gDLMR4KCJR74McV8XINBfrrg9oSoOeQ4XkPDdDL8GIvG4SnssbGN2ow 8E/jL/OZT90IdlMm7KKIXC56Ws3O536OTTP9hvbVQZMbh0JZKT2Ifev1MYJlS3Lt9l/4 NFWWJ+0+w8IWExZ0McLX7Z5myO+TydSvxEjoUPnkKOxoVELGzq7x4ShDiHxMVSWw7zNH nmuylFd7rlRHfBFRrklQa+9Yh2K30zry730i/6FWyo5+SQtsjqqa8s9TB6o/LZQWjmsE /CGkCAmY5SiTrjUsldgrs9DGdl5HqO9hIkadIH7w0s2lxVdh0ffBoROotpRtyy6ivAUf S0Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bg17-20020a056a02011100b0038765abce77si3133882pgb.652.2022.03.25.10.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 911F4ECC74; Fri, 25 Mar 2022 10:18:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355147AbiCYQof (ORCPT + 99 others); Fri, 25 Mar 2022 12:44:35 -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) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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