From patchwork Wed Feb 7 14:58:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10205347 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B4EC56020F for ; Wed, 7 Feb 2018 14:58:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F07628D65 for ; Wed, 7 Feb 2018 14:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92E1428EC7; Wed, 7 Feb 2018 14:58:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF39028E94 for ; Wed, 7 Feb 2018 14:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754347AbeBGO6e (ORCPT ); Wed, 7 Feb 2018 09:58:34 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37422 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754254AbeBGO6d (ORCPT ); Wed, 7 Feb 2018 09:58:33 -0500 Received: by mail-wr0-f193.google.com with SMTP id a43so1353245wrc.4; Wed, 07 Feb 2018 06:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=4GeS8AQYuH/02GE6LoumPHyFJvh7y6BnqO0IACGJcRU=; b=JGcIqnISDY70C8uOvLCzL5bOqo5cInCpgj0f03B7kQscFE/5sE5FbJSrnorbS5pSSp o3mUjlIPzWcrdbFxrPtARGE+lQKPq6WtaUCBAnghuK28ABbtemHXhFjVqDVRRaP0Sv89 6VaQ03WYcJEI9vYYqPjUBfZOZwdFgWM2OYzfp9+pFVvDyMeoyNOp8bx4zHtN2rMafyKa mxSubNem0kyOW0raH7OjZPqR5UuvKIw/pYNriAL6Xo7ItYVzhCvifXsum5C5PFWtRKvX uRzEjux2swKBUnmD5iElIuJaM8dv/kowevk7rZJfuyt35o3HFGGjdjolMx0Sx1tawOY3 VNiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=4GeS8AQYuH/02GE6LoumPHyFJvh7y6BnqO0IACGJcRU=; b=JfK8eVHf4h2RCUnbVqLiWb56z0G7QE8MBFEbxL/fp0M1iU6EpwEfvBWU6gT4Un0F5P hggR3OK2reKpnyO17JK5HYwjdtJG/GiEVS381j4IDkPeZ3xqwhnIxwfyx+W/M7nd0r/E iFVU1b9dRHNbzZBV63Jnmzt7OZn7l4DLKL0qIXRwtWgnmxAl0+t51j3AU0SfX3IDrkzD LpAWAST14rp0TnF7n5qtHnaIFQ5l+OehHAWx9HC//YMLDhlyjy+YJ+yokuJhLGlvTCRe OhnP7CWtPOSdf+TAfJXmzDRFZFYMGlNdhsAWpGoKXf6qU/SLwj+2wzVs9Quftd/uYi3s EpLg== X-Gm-Message-State: APf1xPA+ZRkXHLv3q7bAE/wJJYL2mP2p9QZ+Jk1tKUylfkFWLFauNjsp DkSxMe7ZE63eGj3ef3ZmTXY= X-Google-Smtp-Source: AH8x224VPBdx+iLJWIIShMb1ilcTxsNMX3yvspgnV2ghR4qWgxi5IPfcrKDble7mcK5J125VyPCe+Q== X-Received: by 10.223.134.237 with SMTP id 42mr6388168wry.283.1518015511730; Wed, 07 Feb 2018 06:58:31 -0800 (PST) Received: from thinkpad (pppoe-46-239-10-245.teol.net. [46.239.10.245]) by smtp.googlemail.com with ESMTPSA id 74sm1802704wmf.38.2018.02.07.06.58.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Feb 2018 06:58:30 -0800 (PST) Date: Wed, 7 Feb 2018 15:58:27 +0100 From: Ognjen Galic To: Andy Shevchenko , "Rafael J. Wysocki" , Ognjen =?utf-8?B?R2FsacSH?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Lv Zheng , ACPI Devel Maling List , devel@acpica.org, Darren Hart , Andy Shevchenko , Henrique de Moraes Holschuh , Sebastian Reichel , Platform Driver , ibm-acpi-devel@lists.sourceforge.net, Linux PM , Christoph =?iso-8859-1?Q?B=F6hmwalder?= , Kevin Locke Subject: [PATCH v13 2/4] pm: add to_power_supply macro to the API Message-ID: <20180207145827.yvramuiotxguff2a@thinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the to_power_supply macro to upcast a device to a power_supply struct. This is needed because the same piece of code using container_of is used in various other places, so we abstract away such low-level operations via a macro. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Ognjen Galic Reviewed-by: Sebastian Reichel --- Notes: v9: * Split the pm changes from the thinkpad_acpi patch into its own patch v10: * No changes in this patch in v10 v11: * Fix changelog formatting v12: * Fix build issues in ds2781 and ds2780 battery driver v13: * No changes in this patch in v13 drivers/power/supply/ds2780_battery.c | 5 ----- drivers/power/supply/ds2781_battery.c | 5 ----- drivers/power/supply/power_supply_core.c | 2 +- include/linux/power_supply.h | 2 ++ 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/ds2780_battery.c b/drivers/power/supply/ds2780_battery.c index e5d81b493..370e91093 100644 --- a/drivers/power/supply/ds2780_battery.c +++ b/drivers/power/supply/ds2780_battery.c @@ -56,11 +56,6 @@ to_ds2780_device_info(struct power_supply *psy) return power_supply_get_drvdata(psy); } -static inline struct power_supply *to_power_supply(struct device *dev) -{ - return dev_get_drvdata(dev); -} - static inline int ds2780_battery_io(struct ds2780_device_info *dev_info, char *buf, int addr, size_t count, int io) { diff --git a/drivers/power/supply/ds2781_battery.c b/drivers/power/supply/ds2781_battery.c index efe83ef86..d1b5a19aa 100644 --- a/drivers/power/supply/ds2781_battery.c +++ b/drivers/power/supply/ds2781_battery.c @@ -54,11 +54,6 @@ to_ds2781_device_info(struct power_supply *psy) return power_supply_get_drvdata(psy); } -static inline struct power_supply *to_power_supply(struct device *dev) -{ - return dev_get_drvdata(dev); -} - static inline int ds2781_battery_io(struct ds2781_device_info *dev_info, char *buf, int addr, size_t count, int io) { diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 82f998ab5..feac7b066 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -668,7 +668,7 @@ EXPORT_SYMBOL_GPL(power_supply_powers); static void power_supply_dev_release(struct device *dev) { - struct power_supply *psy = container_of(dev, struct power_supply, dev); + struct power_supply *psy = to_power_supply(dev); dev_dbg(dev, "%s\n", __func__); kfree(psy); } diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 79e90b3d3..f0139b460 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -371,6 +371,8 @@ devm_power_supply_register_no_ws(struct device *parent, extern void power_supply_unregister(struct power_supply *psy); extern int power_supply_powers(struct power_supply *psy, struct device *dev); +#define to_power_supply(device) container_of(device, struct power_supply, dev) + extern void *power_supply_get_drvdata(struct power_supply *psy); /* For APM emulation, think legacy userspace. */ extern struct class *power_supply_class;