From patchwork Sat Dec 23 10:53:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10131477 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 2109960388 for ; Sat, 23 Dec 2017 10:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EB6329A3C for ; Sat, 23 Dec 2017 10:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02A1728E3C; Sat, 23 Dec 2017 10:53:22 +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=ham 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 A668E28E3C for ; Sat, 23 Dec 2017 10:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750810AbdLWKxU (ORCPT ); Sat, 23 Dec 2017 05:53:20 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:44416 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713AbdLWKxT (ORCPT ); Sat, 23 Dec 2017 05:53:19 -0500 Received: by mail-wr0-f195.google.com with SMTP id l41so17651508wre.11; Sat, 23 Dec 2017 02:53:18 -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=silMvoDMQ+0ujy/K4ObP4h7zWwJdCL22ZQ1+FfiBJUw=; b=m9R6aAknqBYwztTGyBGkmxqxhQgYOvrOFCFAv9Bt8DzTmUgsnLLv1mzMDU2A808Aw5 SxVYgVs040qdiUGWi0ioh09eXxB6DtLvrNxNe7AMwFaRPbYWE7alchgngsRjFp4joF+/ vKt872PCVUje3JphNrhfVGNtw3u4kQJ8C7lBieniNhVkNFBsERtBf0je8m5M7sIEd0Vi op7uqsNNe4yJCtJzWWiFrX29t7TTirzKQBC2tysJ5g21j7F84DapW/VcyhwDA4bUaEom 9EpwRURT8Mr41BiG8SiaNcOXKEUFZqXcI12NZaasEZqmbsSC6K9I6S7GXAs6CPDdcxTJ vmvA== 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=silMvoDMQ+0ujy/K4ObP4h7zWwJdCL22ZQ1+FfiBJUw=; b=GDazrZ1FVsEIxg+m3tvKm2HqUSgSnL+NsO0PSg8hTTLjPi99RVGy284u3X/4slGBfl vxl/MwwEHipNh2aIzQnJrOLWFN/XHEI4V9GZIiVFywSscZzwB41waEVqOIxVgr9yl70e MiJNvQ0tO6COU306q7fx7aTMvaJRwkpax7IrEJxgR1MQUg1sam7b9WAdiC3028ir2dnk TRO8oUVUEbo4bGbKKvIqL0RCqOVShxd66YJ4eeP3+vBQgrL7QQnvqifi0uTHfqy8PI8j D87Kh/Zf6FcIKep+oIaE6o766YtUFwumSvUoHJDTV2+nLCr4f8xlzHWG6XeOpjuDwesZ cPIQ== X-Gm-Message-State: AKGB3mJachu9A4PS4EoJu7ro3AHAVfherq5r2iyLLSzTqbLxszhwMxI+ AFh+WyySGv+n+2R9SREzIKg= X-Google-Smtp-Source: ACJfBot+MRDfzLeLnBwBYeIGYHoCFu06Ft6Sj26fvEOFYIZCDpla8W56tqf+yhQJKCAIzsdQmOulSA== X-Received: by 10.223.154.225 with SMTP id a88mr19382689wrc.8.1514026398196; Sat, 23 Dec 2017 02:53:18 -0800 (PST) Received: from thinkpad (pppoe-46-239-10-236.teol.net. [46.239.10.236]) by smtp.gmail.com with ESMTPSA id m78sm12677757wmg.46.2017.12.23.02.53.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 23 Dec 2017 02:53:16 -0800 (PST) Date: Sat, 23 Dec 2017 11:53:16 +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 v10 2/4] pm: add to_power_supply macro to the API Message-ID: <20171223105316.GA4352@thinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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. --- v9: * Split the pm changes from the thinkpad_acpi patch into its own patch v10: * No changes in this patch in v10 Signed-off-by: Ognjen Galic --- drivers/power/supply/power_supply_core.c | 2 +- include/linux/power_supply.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 82f998a..feac7b0 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 79e90b3..f0139b4 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;