From patchwork Sun Dec 31 14:17:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10138179 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 8CE0D605B4 for ; Sun, 31 Dec 2017 14:17:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A9F728553 for ; Sun, 31 Dec 2017 14:17:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F5B62884E; Sun, 31 Dec 2017 14:17:09 +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 5D1AA28844 for ; Sun, 31 Dec 2017 14:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750923AbdLaORG (ORCPT ); Sun, 31 Dec 2017 09:17:06 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36615 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbdLaORF (ORCPT ); Sun, 31 Dec 2017 09:17:05 -0500 Received: by mail-wm0-f67.google.com with SMTP id b76so54802245wmg.1; Sun, 31 Dec 2017 06:17:04 -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=gFLzQ4GWJ8aDEi2ynkp+/oSirzJxvOkUgcwZEi76ZR8=; b=YkCW+rdrU9y/bs5kAtAglUJdcAz7xWmiZMTXRgOj3bxqbYQscMstui3MZgEHPXeC9X y+TQOpoYal5zPexY8lxv7qHQHdnf5Tk6RY89ydSpDEhdVHqjFRaxRiYpmEXFod+ohmes EIIixQNENFh7u52EbcKkdF6O/Nv3Nbvjawzs36FAa4pDs8Hj4orkL/S7dG85sfO//Dgs 3pT9Wr9abOs2A4y2CG3GnX+ph01zHOP9ZQArcTq7xPfz9zYI8pDqkebJE5JlfMpFQ22R YdhaOFCfYYX8Bc9IfACRCHMKDqXn9BlynhfMhwYFXkPIRA1w2cUOsMCiyg/MoY+UjYY3 K6gw== 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=gFLzQ4GWJ8aDEi2ynkp+/oSirzJxvOkUgcwZEi76ZR8=; b=UJ9KT6GYAbd11BDwVYSrHqwzZMKhljC7MSMO/vJVJpfmobOxt5OeFB28klAKfpfQUi ZTAzKjYYK50Fr3ffvL6gLelTSNI8ILrAPF/JD2obI/Om187m6u3UhwtudPMEHKbNtV2K 0vTR2ciCi3e3TsdaWHGqT4VeWREZbZhXwv7C1Xlh8HRosOT0XaggSPQTzqhElq2X7lE3 HLaMA6Y+eDghm2K4JVN64jaeZX8dAqP5WpCjqBdbVpBOBAbrNREijh1KPmZuC9JuBM++ gSWbDRfpX/QTS2ospFqqyFPM+4VC1uXEuIeEzqbcf/fNF1jSNsL/mXZ6UYme8ncLrNSO KzxA== X-Gm-Message-State: AKGB3mLkExvANrsBMm1ujsMu83L2k17u6t7AXTag3NmQExymLLTF8w3F ot+/wGUKANvuR8J33kuueYk= X-Google-Smtp-Source: ACJfBosiIXYaXl4N2r2HWFT5EsCkglnaDB9jwGa+7pcO0NfHC4GjoC/ZtXi4y3c5Tjo24IamYZ/Cbw== X-Received: by 10.80.143.163 with SMTP id y32mr52916232edy.167.1514729824256; Sun, 31 Dec 2017 06:17:04 -0800 (PST) Received: from thinkpad (pppoe-46-239-11-36.teol.net. [46.239.11.36]) by smtp.googlemail.com with ESMTPSA id k19sm35660131ede.35.2017.12.31.06.17.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Dec 2017 06:17:03 -0800 (PST) Date: Sun, 31 Dec 2017 15:17:00 +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 v11 2/5] pm: add to_power_supply macro to the API Message-ID: <20171231141700.GA4612@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. Suggested-by: Andy Shevchenko Signed-off-by: Ognjen Galic 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 --- 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;