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 D39D3C433FE for ; Thu, 9 Dec 2021 16:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238252AbhLIRAF (ORCPT ); Thu, 9 Dec 2021 12:00:05 -0500 Received: from mga04.intel.com ([192.55.52.120]:27927 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241588AbhLIQ7v (ORCPT ); Thu, 9 Dec 2021 11:59:51 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10193"; a="236887011" X-IronPort-AV: E=Sophos;i="5.88,193,1635231600"; d="scan'208";a="236887011" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 08:55:19 -0800 X-IronPort-AV: E=Sophos;i="5.88,193,1635231600"; d="scan'208";a="564887994" Received: from smile.fi.intel.com ([10.237.72.184]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 08:55:15 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.95) (envelope-from ) id 1mvMgS-004Arq-7Q; Thu, 09 Dec 2021 18:54:16 +0200 Date: Thu, 9 Dec 2021 18:54:15 +0200 From: Andy Shevchenko To: Bjorn Helgaas Cc: Greg KH , Lee Jones , Leon Romanovsky , "David E. Box" , hdegoede@redhat.com, bhelgaas@google.com, srinivas.pandruvada@intel.com, shuah@kernel.org, mgross@linux.intel.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, "Rafael J. Wysocki" Subject: Re: [V2 2/6] driver core: auxiliary bus: Add driver data helpers Message-ID: References: <20211209163245.GA245119@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211209163245.GA245119@bhelgaas> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 09, 2021 at 10:32:45AM -0600, Bjorn Helgaas wrote: > [+cc Rafael, since I used generic PM as an example] > On Wed, Dec 08, 2021 at 09:47:56AM +0100, Greg KH wrote: ... Okay, more bikeshedding :-) > In the very common situation of PCI drivers that use generic power > management, authors *do* have to use both (example from [1]): > > ioh_gpio_probe(struct pci_dev *pdev) # pci_driver.probe() > pci_set_drvdata(pdev, chip); > > ioh_gpio_remove(struct pci_dev *pdev) # pci_driver.remove() > struct ioh_gpio *chip = pci_get_drvdata(pdev); > > ioh_gpio_suspend(struct device *dev) # pci_driver.driver.pm.suspend() > struct ioh_gpio *chip = dev_get_drvdata(dev); <-- > > The pci_driver methods receive a struct pci_dev and use the > pci_get_drvdata() wrapper. > > The generic power management methods receive a struct device and use > the underlying dev_get_drvdata(). > > It's kind of ugly that readers have to know that pci_get_drvdata() > gives you the same thing as dev_get_drvdata(). > > I guess the generic PM methods could do something like: > > pci_get_drvdata(to_pci_dev(dev)); > > but that seems a little bit circuitous. It's slightly wordier, but I > might prefer to just use this everywhere and skip the pci_* wrappers: > > dev_get_drvdata(&pdev->dev); Strictly speaking the <$BUS)_get_drvdata(<$CONTAINER>) != dev_get_drvdata(dev) it's completely up to the container handling code what to do. In 99% (or 100%?) cases it's equal, but it's not obliged to be so. > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpio/gpio-ml-ioh.c?id=v5.15#n505 -- With Best Regards, Andy Shevchenko