From patchwork Mon May 25 18:26:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 218577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D96CC433E1 for ; Mon, 25 May 2020 18:26:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19A5520776 for ; Mon, 25 May 2020 18:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389391AbgEYS0S (ORCPT ); Mon, 25 May 2020 14:26:18 -0400 Received: from mail-ej1-f67.google.com ([209.85.218.67]:36124 "EHLO mail-ej1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387644AbgEYS0Q (ORCPT ); Mon, 25 May 2020 14:26:16 -0400 Received: by mail-ej1-f67.google.com with SMTP id z5so21375647ejb.3; Mon, 25 May 2020 11:26:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tkUGbMkkypRL042+ieWSoDccuHFghwak5Hi3wVxhDmE=; b=C6FvFlWGYjOrdkQk8jI5gKJ0FH/UIZfAILSeyIMoTRLVytb2uadwYyVnBKtqhCSTxo aj7PGbUmhTcR+JDysusQTqgasRYDpRRQVxdYvRfjAv9VZB2QeepMKCxd5gfoeTRCiG/e Jmgh6y48CMevLk1MxULlpxQvOwdtAh0T6TWBfaG9cwVabEG8HXYWfG+8hlVFUiRJhf7c mtlCsuSP04spjmnUmGR4zpEhwRDaInkTdyS7yw8aXxmvRwo3qaUa74CaZKTiV/4cXz5v TEJMF4mWPLspYAssS60gMRqErYpLcUVYYto+4tR5wIWJ4CrG4vDDmSFwZy+Kdd+wz9mq Thig== X-Gm-Message-State: AOAM5325TrlWaByK3eWEBqeVkTpPT770+FJzp0atfEnrNtZYykD0dU5j Ga9qYIw6jsILnnvzjKMDVjGtN1EA6vzgYy46 X-Google-Smtp-Source: ABdhPJyLZsaw5mEGXRcLaNb9q3bD5AU4cxUKQ8Vo98mbYphbp21kYQ3Rc8jcjNp3ljuzgmIEt8D4Ug== X-Received: by 2002:a17:906:f1c3:: with SMTP id gx3mr19110160ejb.278.1590431172312; Mon, 25 May 2020 11:26:12 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id n15sm15555707ejs.10.2020.05.25.11.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 11:26:11 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Dan Carpenter Cc: "Rafael J. Wysocki" , Len Brown , Kevin Hilman , Ulf Hansson , Pavel Machek , Greg Kroah-Hartman , Johan Hovold , Alex Elder , Bjorn Helgaas , "James E.J. Bottomley" , "Martin K. Petersen" , Felipe Balbi , Julian Wiedmann , Karsten Graul , Ursula Braun , Jakub Kicinski , Bjorn Andersson , John Stultz , "David S. Miller" , greybus-dev@lists.linaro.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 1/8] driver core: Add helper for accessing Power Management callbacs Date: Mon, 25 May 2020 18:26:01 +0000 Message-Id: <20200525182608.1823735-2-kw@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200525182608.1823735-1-kw@linux.com> References: <20200525182608.1823735-1-kw@linux.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add driver_to_pm() helper allowing for accessing the Power Management callbacs for a particular device. Access to the callbacs (struct dev_pm_ops) is normally done through using the pm pointer that is embedded within the device_driver struct. Helper allows for the code required to reference the pm pointer and access Power Management callbas to be simplified. Changing the following: struct device_driver *drv = dev->driver; if (dev->driver && dev->driver->pm && dev->driver->pm->prepare) { int ret = dev->driver->pm->prepare(dev); To: const struct dev_pm_ops *pm = driver_to_pm(dev->driver); if (pm && pm->prepare) { int ret = pm->prepare(dev); Or, changing the following: const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; To: const struct dev_pm_ops *pm = driver_to_pm(dev->driver); Signed-off-by: Krzysztof Wilczyński --- include/linux/device/driver.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h index ee7ba5b5417e..ccd0b315fd93 100644 --- a/include/linux/device/driver.h +++ b/include/linux/device/driver.h @@ -236,6 +236,21 @@ driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev) } #endif +/** + * driver_to_pm - Return Power Management callbacs (struct dev_pm_ops) for + * a particular device. + * @drv: Pointer to a device (struct device_driver) for which you want to access + * the Power Management callbacks. + * + * Returns a pointer to the struct dev_pm_ops embedded within the device (struct + * device_driver), or returns NULL if Power Management is not present and the + * pointer is not valid. + */ +static inline const struct dev_pm_ops *driver_to_pm(struct device_driver *drv) +{ + return drv && drv->pm ? drv->pm : NULL; +} + extern int driver_deferred_probe_timeout; void driver_deferred_probe_add(struct device *dev); int driver_deferred_probe_check_state(struct device *dev); From patchwork Mon May 25 18:26:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 218580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0596C433DF for ; Mon, 25 May 2020 18:26:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CBC820776 for ; Mon, 25 May 2020 18:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389542AbgEYS0Z (ORCPT ); Mon, 25 May 2020 14:26:25 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:46901 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389339AbgEYS0U (ORCPT ); Mon, 25 May 2020 14:26:20 -0400 Received: by mail-ed1-f67.google.com with SMTP id f13so15097900edr.13; Mon, 25 May 2020 11:26:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vks0hIgL1NwjWUU2xJ9iHtmVGdxZKzV+xbSUPqXCfwA=; b=LEo9fgX+z93XCPxtZSv4U/aKOUbDnDTtBoqZfzlugxY222bvkXsGvTqSoRX1/97aI+ dTMjuLSZv1dtVyedOqLsI8JydUy0tq14TPWw01aN4PfNRcc2tJOOZtJLJtAVjTmSrNTY tAkbQvRgUAwB6yYjkqNhn/aEUleNcyyW2TTRqvBmqPm7Q7iErv4Io9VFKeffDBRMhacA 66iLNA/HExgrkbhbd4v6z+vUkgysEuNzZcpmgjCmbaMq5XgIwWvL5BUjm6t8qOZQ12hs bQgGKDPe0uQRAlDYksyHLFSIfnTcr3VopYpXHOv6ctKqm32S/fgs7kY3WuNmSThQsfG4 hdcQ== X-Gm-Message-State: AOAM532GazrAOglUcU6mnKLV+GUU7POZv8HIPvPlf2sa8yKKomJUSs0i xGWM9g4OdxFaZAiQMqib78E= X-Google-Smtp-Source: ABdhPJxpk17hj32HQlVxuKMrJl9fav78GF8tiYkjJ3OmXfQxm5boXKtzfcrmijAtVvsY76ZoDX8sKQ== X-Received: by 2002:aa7:c3cb:: with SMTP id l11mr15735650edr.364.1590431177072; Mon, 25 May 2020 11:26:17 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id n15sm15555707ejs.10.2020.05.25.11.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 11:26:16 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Dan Carpenter Cc: "Rafael J. Wysocki" , Len Brown , Kevin Hilman , Ulf Hansson , Pavel Machek , Greg Kroah-Hartman , Johan Hovold , Alex Elder , Bjorn Helgaas , "James E.J. Bottomley" , "Martin K. Petersen" , Felipe Balbi , Julian Wiedmann , Karsten Graul , Ursula Braun , Jakub Kicinski , Bjorn Andersson , John Stultz , "David S. Miller" , greybus-dev@lists.linaro.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 4/8] scsi: pm: Use the new device_to_pm() helper to access struct dev_pm_ops Date: Mon, 25 May 2020 18:26:04 +0000 Message-Id: <20200525182608.1823735-5-kw@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200525182608.1823735-1-kw@linux.com> References: <20200525182608.1823735-1-kw@linux.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use the new device_to_pm() helper to access Power Management callbacs (struct dev_pm_ops) for a particular device (struct device_driver). No functional change intended. Signed-off-by: Krzysztof Wilczyński --- drivers/scsi/scsi_pm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index 5f0ad8b32e3a..8f40b60d3383 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -53,7 +53,7 @@ static int do_scsi_restore(struct device *dev, const struct dev_pm_ops *pm) static int scsi_dev_type_suspend(struct device *dev, int (*cb)(struct device *, const struct dev_pm_ops *)) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); int err; /* flush pending in-flight resume operations, suspend is synchronous */ @@ -72,7 +72,7 @@ static int scsi_dev_type_suspend(struct device *dev, static int scsi_dev_type_resume(struct device *dev, int (*cb)(struct device *, const struct dev_pm_ops *)) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); int err = 0; err = cb(dev, pm); @@ -232,7 +232,7 @@ static int scsi_bus_restore(struct device *dev) static int sdev_runtime_suspend(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); struct scsi_device *sdev = to_scsi_device(dev); int err = 0; @@ -262,7 +262,7 @@ static int scsi_runtime_suspend(struct device *dev) static int sdev_runtime_resume(struct device *dev) { struct scsi_device *sdev = to_scsi_device(dev); - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); int err = 0; blk_pre_runtime_resume(sdev->request_queue); From patchwork Mon May 25 18:26:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 218579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 582CFC433E1 for ; Mon, 25 May 2020 18:26:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43F9620776 for ; Mon, 25 May 2020 18:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389793AbgEYS02 (ORCPT ); Mon, 25 May 2020 14:26:28 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36104 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389294AbgEYS0W (ORCPT ); Mon, 25 May 2020 14:26:22 -0400 Received: by mail-ed1-f67.google.com with SMTP id b91so15737219edf.3; Mon, 25 May 2020 11:26:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0zGvHrt9YYoiSjZrnFb35ZKjC/21ugPMkpe0HjhFbIE=; b=Sgyj9hjtZEyafbSMpSpYXef8HDKL+AA2+eocPQkxlmHJrAnuAcC8h5KDypURCdOBWH 6UveCF8AECP8ooKg83e8ksIYVNWqOX9HOSkPWTZqgA5WAUzaM+GkbcQ7CNsexU0AY6/l rERvxO+n7FugolWQqpNtzMA1yx+br3Nn/EmCUkJnGBLttiNV8Ei+e+mUiHSzQLk4R4l0 elNtXzuS44aBbTs8jyHoZZzr7Ekh9oRQNQhMJbuf3F5cw+651Hspertztb3UeXiBfjcE otdAsOJbNd3aBwM1x/BiuKnzkgExiqZx9jJl9FMdM/Q8TMglwj9cbV4/jXm1KD74SPvr R9UQ== X-Gm-Message-State: AOAM531fSHVFjrktTfvrlO/b5SxVEz3m6KiK8TH5S1YOU9eHGUfqHR0W Gil1zS6O2xwAUqltQk8mZDcTlzxJkslCAX4o X-Google-Smtp-Source: ABdhPJxu8xj7ETus6I8qz75XV9UcGoEOmg3ZGJLGe0YSg2hAMRNpcfMS5lnkyWZC+sphielpDh7PsA== X-Received: by 2002:a05:6402:948:: with SMTP id h8mr15890575edz.127.1590431178687; Mon, 25 May 2020 11:26:18 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id n15sm15555707ejs.10.2020.05.25.11.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 11:26:18 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Dan Carpenter Cc: "Rafael J. Wysocki" , Len Brown , Kevin Hilman , Ulf Hansson , Pavel Machek , Greg Kroah-Hartman , Johan Hovold , Alex Elder , Bjorn Helgaas , "James E.J. Bottomley" , "Martin K. Petersen" , Felipe Balbi , Julian Wiedmann , Karsten Graul , Ursula Braun , Jakub Kicinski , Bjorn Andersson , John Stultz , "David S. Miller" , greybus-dev@lists.linaro.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 5/8] usb: phy: fsl: Use the new device_to_pm() helper to access struct dev_pm_ops Date: Mon, 25 May 2020 18:26:05 +0000 Message-Id: <20200525182608.1823735-6-kw@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200525182608.1823735-1-kw@linux.com> References: <20200525182608.1823735-1-kw@linux.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use the new device_to_pm() helper to access Power Management callbacs (struct dev_pm_ops) for a particular device (struct device_driver). No functional change intended. Signed-off-by: Krzysztof Wilczyński --- drivers/usb/phy/phy-fsl-usb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index b451f4695f3f..3b9ad5db8380 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c @@ -460,6 +460,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) struct device *dev; struct fsl_otg *otg_dev = container_of(otg->usb_phy, struct fsl_otg, phy); + const struct dev_pm_ops *pm; u32 retval = 0; if (!otg->host) @@ -479,8 +480,9 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) else { otg_reset_controller(); VDBG("host on......\n"); - if (dev->driver->pm && dev->driver->pm->resume) { - retval = dev->driver->pm->resume(dev); + pm = driver_to_pm(dev->driver); + if (pm && pm->resume) { + retval = pm->resume(dev); if (fsm->id) { /* default-b */ fsl_otg_drv_vbus(fsm, 1); @@ -504,8 +506,9 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) else { VDBG("host off......\n"); if (dev && dev->driver) { - if (dev->driver->pm && dev->driver->pm->suspend) - retval = dev->driver->pm->suspend(dev); + pm = driver_to_pm(dev->driver); + if (pm && pm->suspend) + retval = pm->suspend(dev); if (fsm->id) /* default-b */ fsl_otg_drv_vbus(fsm, 0); From patchwork Mon May 25 18:26:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 218578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF82CC433E2 for ; Mon, 25 May 2020 18:26:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B258920776 for ; Mon, 25 May 2020 18:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389832AbgEYS0e (ORCPT ); Mon, 25 May 2020 14:26:34 -0400 Received: from mail-ej1-f68.google.com ([209.85.218.68]:34824 "EHLO mail-ej1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389511AbgEYS01 (ORCPT ); Mon, 25 May 2020 14:26:27 -0400 Received: by mail-ej1-f68.google.com with SMTP id s21so21369947ejd.2; Mon, 25 May 2020 11:26:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zC1sdnSC7gmB2OcNZjocITMtxNUn1YHh0qE5EhXuaW4=; b=MpSY1cc/FPX5YBNPF0FgTsnTnlU57Nm7fGXBFZ0xWSO4WsRSSWoigFB6+JfmR+lVSj DQ9smnAHvRDofwsamvPpsbayqmBv1FYFKEAumddLtnDS4CJh1y8AIBzX05KyqhzYshbx +B+GSdnt/VzM/7aqE5sgLdHJ+V/iOl5m54+e6jFP8bbODtRCsFL9KP5kM1jQ5o0XUqSK BWTmp2Gpr9csb7xzPjnjsYQ8LXGQlMNCaBzSIwcVwlFCC/LgcSLta2nQ4wfZYOZxJjl2 E07By0u0wuPxp77Cc1d4R+zwykeQKFaowI6BP4UUW8e9HSQL0Y9NV7Gqyw2Xm6P7VVKm EG2Q== X-Gm-Message-State: AOAM532BW7ubc4j5honvduSkVe3GSoHUQOzPZC5CXIur5FKSdOvhAoUk Dnp/6Fpmb5IDAdshJ37ZBRQ= X-Google-Smtp-Source: ABdhPJwAZcGCs5OVpkzmitXxPnlCt0gtxwYqTDvcBpN73Kp+EmhxEze7qyyPuNofrda5TH25DnLshg== X-Received: by 2002:a17:906:914a:: with SMTP id y10mr19232438ejw.355.1590431181904; Mon, 25 May 2020 11:26:21 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id n15sm15555707ejs.10.2020.05.25.11.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 11:26:21 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Dan Carpenter Cc: "Rafael J. Wysocki" , Len Brown , Kevin Hilman , Ulf Hansson , Pavel Machek , Greg Kroah-Hartman , Johan Hovold , Alex Elder , Bjorn Helgaas , "James E.J. Bottomley" , "Martin K. Petersen" , Felipe Balbi , Julian Wiedmann , Karsten Graul , Ursula Braun , Jakub Kicinski , Bjorn Andersson , John Stultz , "David S. Miller" , greybus-dev@lists.linaro.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 7/8] PM: Use the new device_to_pm() helper to access struct dev_pm_ops Date: Mon, 25 May 2020 18:26:07 +0000 Message-Id: <20200525182608.1823735-8-kw@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200525182608.1823735-1-kw@linux.com> References: <20200525182608.1823735-1-kw@linux.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use the new device_to_pm() helper to access Power Management callbacs (struct dev_pm_ops) for a particular device (struct device_driver). No functional change intended. This change builds on top of the previous commit 6da2f2ccfd2d ("PCI/PM: Make power management op coding style consistent"). Links: https://lore.kernel.org/driverdev-devel/20191014230016.240912-6-helgaas@kernel.org/ https://lore.kernel.org/driverdev-devel/8592302.r4xC6RIy69@kreacher/ https://lore.kernel.org/driverdev-devel/20191016135002.GA24678@kadam/ Signed-off-by: Krzysztof Wilczyński --- drivers/base/power/domain.c | 12 ++++-- drivers/base/power/generic_ops.c | 65 ++++++++++++++------------------ drivers/base/power/main.c | 48 +++++++++++++++-------- drivers/base/power/runtime.c | 7 ++-- 4 files changed, 73 insertions(+), 59 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 0a01df608849..92a96fcb2717 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -703,6 +703,7 @@ static void genpd_power_off_work_fn(struct work_struct *work) static int __genpd_runtime_suspend(struct device *dev) { int (*cb)(struct device *__dev); + const struct dev_pm_ops *pm; if (dev->type && dev->type->pm) cb = dev->type->pm->runtime_suspend; @@ -713,8 +714,9 @@ static int __genpd_runtime_suspend(struct device *dev) else cb = NULL; - if (!cb && dev->driver && dev->driver->pm) - cb = dev->driver->pm->runtime_suspend; + pm = driver_to_pm(dev->driver); + if (!cb && pm) + cb = pm->runtime_suspend; return cb ? cb(dev) : 0; } @@ -726,6 +728,7 @@ static int __genpd_runtime_suspend(struct device *dev) static int __genpd_runtime_resume(struct device *dev) { int (*cb)(struct device *__dev); + const struct dev_pm_ops *pm; if (dev->type && dev->type->pm) cb = dev->type->pm->runtime_resume; @@ -736,8 +739,9 @@ static int __genpd_runtime_resume(struct device *dev) else cb = NULL; - if (!cb && dev->driver && dev->driver->pm) - cb = dev->driver->pm->runtime_resume; + pm = driver_to_pm(dev->driver); + if (!cb && pm) + cb = pm->runtime_resume; return cb ? cb(dev) : 0; } diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c index 4fa525668cb7..fbd2edef0201 100644 --- a/drivers/base/power/generic_ops.c +++ b/drivers/base/power/generic_ops.c @@ -19,12 +19,9 @@ */ int pm_generic_runtime_suspend(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; - int ret; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); - ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0; - - return ret; + return pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0; } EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend); @@ -38,12 +35,9 @@ EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend); */ int pm_generic_runtime_resume(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; - int ret; - - ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); - return ret; + return pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0; } EXPORT_SYMBOL_GPL(pm_generic_runtime_resume); #endif /* CONFIG_PM */ @@ -57,13 +51,12 @@ EXPORT_SYMBOL_GPL(pm_generic_runtime_resume); */ int pm_generic_prepare(struct device *dev) { - struct device_driver *drv = dev->driver; - int ret = 0; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); - if (drv && drv->pm && drv->pm->prepare) - ret = drv->pm->prepare(dev); + if (pm && pm->prepare) + return pm->prepare(dev); - return ret; + return 0; } /** @@ -72,7 +65,7 @@ int pm_generic_prepare(struct device *dev) */ int pm_generic_suspend_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0; } @@ -84,7 +77,7 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq); */ int pm_generic_suspend_late(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->suspend_late ? pm->suspend_late(dev) : 0; } @@ -96,7 +89,7 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend_late); */ int pm_generic_suspend(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->suspend ? pm->suspend(dev) : 0; } @@ -108,7 +101,7 @@ EXPORT_SYMBOL_GPL(pm_generic_suspend); */ int pm_generic_freeze_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0; } @@ -120,7 +113,7 @@ EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq); */ int pm_generic_freeze_late(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->freeze_late ? pm->freeze_late(dev) : 0; } @@ -132,7 +125,7 @@ EXPORT_SYMBOL_GPL(pm_generic_freeze_late); */ int pm_generic_freeze(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->freeze ? pm->freeze(dev) : 0; } @@ -144,7 +137,7 @@ EXPORT_SYMBOL_GPL(pm_generic_freeze); */ int pm_generic_poweroff_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0; } @@ -156,7 +149,7 @@ EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq); */ int pm_generic_poweroff_late(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0; } @@ -168,7 +161,7 @@ EXPORT_SYMBOL_GPL(pm_generic_poweroff_late); */ int pm_generic_poweroff(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->poweroff ? pm->poweroff(dev) : 0; } @@ -180,7 +173,7 @@ EXPORT_SYMBOL_GPL(pm_generic_poweroff); */ int pm_generic_thaw_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0; } @@ -192,7 +185,7 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq); */ int pm_generic_thaw_early(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->thaw_early ? pm->thaw_early(dev) : 0; } @@ -204,7 +197,7 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw_early); */ int pm_generic_thaw(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->thaw ? pm->thaw(dev) : 0; } @@ -216,7 +209,7 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw); */ int pm_generic_resume_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0; } @@ -228,7 +221,7 @@ EXPORT_SYMBOL_GPL(pm_generic_resume_noirq); */ int pm_generic_resume_early(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->resume_early ? pm->resume_early(dev) : 0; } @@ -240,7 +233,7 @@ EXPORT_SYMBOL_GPL(pm_generic_resume_early); */ int pm_generic_resume(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->resume ? pm->resume(dev) : 0; } @@ -252,7 +245,7 @@ EXPORT_SYMBOL_GPL(pm_generic_resume); */ int pm_generic_restore_noirq(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0; } @@ -264,7 +257,7 @@ EXPORT_SYMBOL_GPL(pm_generic_restore_noirq); */ int pm_generic_restore_early(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->restore_early ? pm->restore_early(dev) : 0; } @@ -276,7 +269,7 @@ EXPORT_SYMBOL_GPL(pm_generic_restore_early); */ int pm_generic_restore(struct device *dev) { - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); return pm && pm->restore ? pm->restore(dev) : 0; } @@ -290,9 +283,9 @@ EXPORT_SYMBOL_GPL(pm_generic_restore); */ void pm_generic_complete(struct device *dev) { - struct device_driver *drv = dev->driver; + const struct dev_pm_ops *pm = driver_to_pm(dev->driver); - if (drv && drv->pm && drv->pm->complete) - drv->pm->complete(dev); + if (pm && pm->complete) + pm->complete(dev); } #endif /* CONFIG_PM_SLEEP */ diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 0e07e17c2def..6c41da0bebb0 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -640,6 +640,7 @@ static pm_callback_t dpm_subsys_suspend_late_cb(struct device *dev, static int device_resume_noirq(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback; + const struct dev_pm_ops *pm; const char *info; bool skip_resume; int error = 0; @@ -687,9 +688,10 @@ static int device_resume_noirq(struct device *dev, pm_message_t state, bool asyn } } - if (dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (pm) { info = "noirq driver "; - callback = pm_noirq_op(dev->driver->pm, state); + callback = pm_noirq_op(pm, state); } Run: @@ -850,6 +852,7 @@ static pm_callback_t dpm_subsys_resume_early_cb(struct device *dev, static int device_resume_early(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback; + const struct dev_pm_ops *pm; const char *info; int error = 0; @@ -867,9 +870,10 @@ static int device_resume_early(struct device *dev, pm_message_t state, bool asyn callback = dpm_subsys_resume_early_cb(dev, state, &info); - if (!callback && dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (!callback && pm) { info = "early driver "; - callback = pm_late_early_op(dev->driver->pm, state); + callback = pm_late_early_op(pm, state); } error = dpm_run_callback(callback, dev, state, info); @@ -963,6 +967,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback = NULL; const char *info = NULL; + const struct dev_pm_ops *pm = NULL; int error = 0; DECLARE_DPM_WATCHDOG_ON_STACK(wd); @@ -1023,9 +1028,10 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) } Driver: - if (!callback && dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (!callback && pm) { info = "driver "; - callback = pm_op(dev->driver->pm, state); + callback = pm_op(pm, state); } End: @@ -1116,6 +1122,7 @@ void dpm_resume(pm_message_t state) static void device_complete(struct device *dev, pm_message_t state) { void (*callback)(struct device *) = NULL; + const struct dev_pm_ops *pm = NULL; const char *info = NULL; if (dev->power.syscore) @@ -1137,9 +1144,10 @@ static void device_complete(struct device *dev, pm_message_t state) callback = dev->bus->pm->complete; } - if (!callback && dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (!callback && pm) { info = "completing driver "; - callback = dev->driver->pm->complete; + callback = pm->complete; } if (callback) { @@ -1312,6 +1320,7 @@ static bool device_must_resume(struct device *dev, pm_message_t state, static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback; + const struct dev_pm_ops *pm; const char *info; bool no_subsys_cb = false; int error = 0; @@ -1336,9 +1345,10 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a if (dev_pm_smart_suspend_and_suspended(dev) && no_subsys_cb) goto Skip; - if (dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (pm) { info = "noirq driver "; - callback = pm_noirq_op(dev->driver->pm, state); + callback = pm_noirq_op(pm, state); } Run: @@ -1514,6 +1524,7 @@ static pm_callback_t dpm_subsys_suspend_late_cb(struct device *dev, static int __device_suspend_late(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback; + const struct dev_pm_ops *pm; const char *info; int error = 0; @@ -1543,9 +1554,10 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as !dpm_subsys_suspend_noirq_cb(dev, state, NULL)) goto Skip; - if (dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (pm) { info = "late driver "; - callback = pm_late_early_op(dev->driver->pm, state); + callback = pm_late_early_op(pm, state); } Run: @@ -1717,6 +1729,7 @@ static void dpm_clear_superiors_direct_complete(struct device *dev) static int __device_suspend(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback = NULL; + const struct dev_pm_ops *pm = NULL; const char *info = NULL; int error = 0; DECLARE_DPM_WATCHDOG_ON_STACK(wd); @@ -1803,9 +1816,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) } Run: - if (!callback && dev->driver && dev->driver->pm) { + pm = driver_to_pm(dev->driver); + if (!callback && pm) { info = "driver "; - callback = pm_op(dev->driver->pm, state); + callback = pm_op(pm, state); } error = dpm_run_callback(callback, dev, state, info); @@ -1917,6 +1931,7 @@ int dpm_suspend(pm_message_t state) static int device_prepare(struct device *dev, pm_message_t state) { int (*callback)(struct device *) = NULL; + const struct dev_pm_ops *pm = NULL; int ret = 0; if (dev->power.syscore) @@ -1946,8 +1961,9 @@ static int device_prepare(struct device *dev, pm_message_t state) else if (dev->bus && dev->bus->pm) callback = dev->bus->pm->prepare; - if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->prepare; + pm = driver_to_pm(dev->driver); + if (!callback && pm) + callback = pm->prepare; if (callback) ret = callback(dev); diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 99c7da112c95..c142824c7541 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -21,7 +21,7 @@ typedef int (*pm_callback_t)(struct device *); static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) { pm_callback_t cb; - const struct dev_pm_ops *ops; + const struct dev_pm_ops *ops, *pm; if (dev->pm_domain) ops = &dev->pm_domain->ops; @@ -39,8 +39,9 @@ static pm_callback_t __rpm_get_callback(struct device *dev, size_t cb_offset) else cb = NULL; - if (!cb && dev->driver && dev->driver->pm) - cb = *(pm_callback_t *)((void *)dev->driver->pm + cb_offset); + pm = driver_to_pm(dev->driver); + if (!cb && pm) + cb = *(pm_callback_t *)((void *)pm + cb_offset); return cb; }