From patchwork Thu Dec 21 19:54:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10128335 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 30C386056F for ; Thu, 21 Dec 2017 19:54:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22EFA29E14 for ; Thu, 21 Dec 2017 19:54:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172BD29E1C; Thu, 21 Dec 2017 19:54:43 +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 BBFFC29E24 for ; Thu, 21 Dec 2017 19:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753163AbdLUTyl (ORCPT ); Thu, 21 Dec 2017 14:54:41 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:43655 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751057AbdLUTyk (ORCPT ); Thu, 21 Dec 2017 14:54:40 -0500 Received: by mail-wm0-f66.google.com with SMTP id n138so18115095wmg.2; Thu, 21 Dec 2017 11:54:39 -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=7pPnkwrmPIlVZt9BnEgs5Dvb8gFPcK5J6sROFBDU1co=; b=L3PAnh8FIHI5cMNcEDRp8K48wzp4akxXRhRIzjp2hvFJFvtps+lrBzQbsSAexO6YER D4HA41wlJH/bFI50WVY16lgyqRgXfhrXh5SnqJPLlboLQjlZ40E3LdlYGkJ8bRGM2KkB u/e45VUyeEYmrxdyj/C5jn5cla0AMfrZyPY7gZ18yEsnN0hoLn407F7CvMklk/RId2Bq 2DhPTbZK/XZIdEur81PBUnB3SSOJqSQEVfwr5iFzUBCHb8PWeNR+Jd4a7bomJFE2wYoN aoEFUDeqdTMcFRJe9NJejwnGYifjysi5a2SWTGRQUysGuCoh/6u2IGGMj07GamfNfsng sg+w== 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=7pPnkwrmPIlVZt9BnEgs5Dvb8gFPcK5J6sROFBDU1co=; b=pKGUNwLL7V5hH4kFf5JnvWXFqu3JcR7LEN5xGMjat2yhOsNclsahWIxtIk3tcbEEIC 4sEOK9dJmdkzDjDwPGk8yzFm8NFXlXpK58qIp2b3q6MZmipGQooAZeq+6CT+CN61Lwk7 a+aDyiTTuLIoMnhYwitvRYyID6TES9elShqL/sOMy97D2a95QYxnR6/n6Jm4rAi8crZj ZdOlpDPj1tBkoiLDxFoVmMp4jaolt/TusvZ/ComFiqSB9kzIr6/we1I57DLELUqCJSHT qe2jhAppakyJBo4r7qle/4mpagWmnb2ahgRE+CZuX+eYFeJyXU9w8Mc9/tdA8Ai/aCKj GY5g== X-Gm-Message-State: AKGB3mKNzJWafhTIz2xG1QsJiROgbp79/iMU7gOkj5fR9e+kAV89yGuv soOvdfsmGIsXHej3d5iSInQ= X-Google-Smtp-Source: ACJfBovsAVMhJ2l48EI260N/op0180h27kgFzw8397DTD08dmZDU27f3pJqTfevWcfz2sAOVf+JD1A== X-Received: by 10.28.7.133 with SMTP id 127mr9941827wmh.31.1513886078778; Thu, 21 Dec 2017 11:54:38 -0800 (PST) Received: from thinkpad (pppoe-46-239-10-167.teol.net. [46.239.10.167]) by smtp.gmail.com with ESMTPSA id l25sm8441093wmi.35.2017.12.21.11.54.37 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Dec 2017 11:54:37 -0800 (PST) Date: Thu, 21 Dec 2017 20:54:37 +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 v9 2/4] pm: add to_power_supply macro to the API Message-ID: <20171221195437.GA17470@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 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;