From patchwork Wed Jan 3 11:59:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ognjen Galic X-Patchwork-Id: 10142163 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 7943D6063B for ; Wed, 3 Jan 2018 11:59:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62E0129090 for ; Wed, 3 Jan 2018 11:59:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5776B29092; Wed, 3 Jan 2018 11:59:13 +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 035D929091 for ; Wed, 3 Jan 2018 11:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752229AbeACL7M (ORCPT ); Wed, 3 Jan 2018 06:59:12 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34270 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751145AbeACL7K (ORCPT ); Wed, 3 Jan 2018 06:59:10 -0500 Received: by mail-wm0-f65.google.com with SMTP id y82so19893703wmg.1; Wed, 03 Jan 2018 03:59:09 -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=4x1BzhJnzpUE2Zn2m9jMFFx6d4musuL5WZWk/vRHV3c=; b=cHAu2tSjr1W4HIqYptdIHbKv1sAxomRbZbK4NhFnzo2zXHB8O5YfJquKlxalWwxyvA t5wD11/9hmBAbPMkIXGZJMY1JKcWmlneRFnZRZu7F9JRVfTWfQ8zwR9lChSwjrPkyLUW JuClkTayANDCBel0JeRiA6+EAoi9RPxsKh1K/dsTwYnSuYUKg8ZfRIMwpFAW9DLC0G2U pjJpvKxQYiLewSPtJYoTpJ+34RagVGSiNN06J84nLLKXyJdSJrt0XRLTiMHANhnC9Pby F3XJh01kG2Y1r9QIF03hR535J4ATNIueR13s6/hw3Xc1w0lBR61vq7Xa1h5LNThytg4E foyQ== 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=4x1BzhJnzpUE2Zn2m9jMFFx6d4musuL5WZWk/vRHV3c=; b=AWjBL5hAUlLBP49io3riEES6fjLSIEghrnq/XMnTklYEwxa0qdzLPYAyGEmAnaqQzH QlVe9/onVqRguSpZ12XOXi+hDc7c8BKMXckBPDTQDKl0iUAk7DZOVlT2rANcOIA+ucRS tbja2bVu6j+fYFu5DeGu5dUuvaqCGonx43fLZ44yjmByBynzyXGqij/jbbVjKOnmmNYs 7BF44AiU1+pLhr96DJXjGPrTuaWEEAJiSTZOi0jqtWRz0QowLC3Go01Jf8jCnWAgrv3C RMiAKMu3GgN2WoNHt7iGBG5JxG6ZQBP0yUkcyVcsiKPCbbrbvt3qE+ruyw1euq+BBnyu gYBQ== X-Gm-Message-State: AKGB3mJJ7ZOo2peNWfu7JZ9TeZAsDefXjuFq4eKMAn2/zsSgxUz7C3Mo 2/H86WQQoXStrU4jqC3FtUE= X-Google-Smtp-Source: ACJfBot4LygBxptIW6js5Lz9Sd5bppARqv0m26zr5PrwQ1uR1GGRydXXoKd9BwFFauQRfKLCg9wbdA== X-Received: by 10.28.178.85 with SMTP id b82mr1161956wmf.47.1514980749145; Wed, 03 Jan 2018 03:59:09 -0800 (PST) Received: from thinkpad (pppoe-46-239-11-72.teol.net. [46.239.11.72]) by smtp.googlemail.com with ESMTPSA id j10sm1632604wrb.49.2018.01.03.03.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jan 2018 03:59:08 -0800 (PST) Date: Wed, 3 Jan 2018 12:59:05 +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 v12 2/4] pm: add to_power_supply macro to the API Message-ID: <20180103115905.GA10115@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 Reviewed-by: Andy Shevchenko --- 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 drivers 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 e5d81b4..370e910 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 efe83ef..d1b5a19 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 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;