linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Lubomir Rintel <lkundrak@v3.sk>
Cc: Mark Brown <broonie@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	James Cameron <quozl@laptop.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Eric Miao <eric.y.miao@gmail.com>,
	Haojian Zhuang <haojian.zhuang@gmail.com>,
	Daniel Mack <daniel@zonque.org>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	linux-spi@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 14/17] power: supply: olpc_battery: Move priv data to a struct
Date: Wed, 5 Dec 2018 21:57:06 +0100	[thread overview]
Message-ID: <20181205205706.t2kvn2smjgsjmy2e@earth.universe> (raw)
In-Reply-To: <20181116162403.49854-15-lkundrak@v3.sk>

[-- Attachment #1: Type: text/plain, Size: 6578 bytes --]

On Fri, Nov 16, 2018 at 05:24:00PM +0100, Lubomir Rintel wrote:
> The global variables for private data are not too nice. I'd like some
> more, and that would clutter the global name space even further.
> 
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> ---
> Changes since v1:
> - Split out the move to devm_* into a separate patch
> 
>  drivers/power/supply/olpc_battery.c | 68 +++++++++++++++++------------
>  1 file changed, 40 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
> index 5323987d9284..b091f897c1d4 100644
> --- a/drivers/power/supply/olpc_battery.c
> +++ b/drivers/power/supply/olpc_battery.c
> @@ -53,6 +53,12 @@
>  
>  #define BAT_ADDR_MFR_TYPE	0x5F
>  
> +struct olpc_battery_data {
> +	struct power_supply *olpc_ac;
> +	struct power_supply *olpc_bat;
> +	char bat_serial[17];
> +};
> +
>  /*********************************************************************
>   *		Power
>   *********************************************************************/
> @@ -91,11 +97,8 @@ static const struct power_supply_desc olpc_ac_desc = {
>  	.get_property = olpc_ac_get_prop,
>  };
>  
> -static struct power_supply *olpc_ac;
> -
> -static char bat_serial[17]; /* Ick */
> -
> -static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte)
> +static int olpc_bat_get_status(struct olpc_battery_data *data,
> +		union power_supply_propval *val, uint8_t ec_byte)
>  {
>  	if (olpc_platform_info.ecver > 0x44) {
>  		if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
> @@ -326,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
>  				 enum power_supply_property psp,
>  				 union power_supply_propval *val)
>  {
> +	struct olpc_battery_data *data = power_supply_get_drvdata(psy);
>  	int ret = 0;
>  	__be16 ec_word;
>  	uint8_t ec_byte;
> @@ -347,7 +351,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
>  
>  	switch (psp) {
>  	case POWER_SUPPLY_PROP_STATUS:
> -		ret = olpc_bat_get_status(val, ec_byte);
> +		ret = olpc_bat_get_status(data, val, ec_byte);
>  		if (ret)
>  			return ret;
>  		break;
> @@ -450,8 +454,8 @@ static int olpc_bat_get_property(struct power_supply *psy,
>  		if (ret)
>  			return ret;
>  
> -		sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
> -		val->strval = bat_serial;
> +		sprintf(data->bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
> +		val->strval = data->bat_serial;
>  		break;
>  	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
>  		ret = olpc_bat_get_voltage_max_design(val);
> @@ -579,17 +583,17 @@ static struct power_supply_desc olpc_bat_desc = {
>  	.use_for_apm = 1,
>  };
>  
> -static struct power_supply *olpc_bat;
> -
>  static int olpc_battery_suspend(struct platform_device *pdev,
>  				pm_message_t state)
>  {
> -	if (device_may_wakeup(&olpc_ac->dev))
> +	struct olpc_battery_data *data = platform_get_drvdata(pdev);
> +
> +	if (device_may_wakeup(&data->olpc_ac->dev))
>  		olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
>  	else
>  		olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
>  
> -	if (device_may_wakeup(&olpc_bat->dev))
> +	if (device_may_wakeup(&data->olpc_bat->dev))
>  		olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
>  				   | EC_SCI_SRC_BATERR);
>  	else
> @@ -601,7 +605,8 @@ static int olpc_battery_suspend(struct platform_device *pdev,
>  
>  static int olpc_battery_probe(struct platform_device *pdev)
>  {
> -	int ret;
> +	struct power_supply_config psy_cfg = {};
> +	struct olpc_battery_data *data;

^ uninitialized pointer

>  	uint8_t status;
>  
>  	/*
> @@ -620,9 +625,13 @@ static int olpc_battery_probe(struct platform_device *pdev)
>  
>  	/* Ignore the status. It doesn't actually matter */
>  
> -	olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, NULL);
> -	if (IS_ERR(olpc_ac))
> -		return PTR_ERR(olpc_ac);
> +	psy_cfg.of_node = pdev->dev.of_node;
> +	psy_cfg.drv_data = data;

^ usage of uninitialized pointer. You are missing a kmalloc call.

-- Sebastian

> +	data->olpc_ac = power_supply_register(&pdev->dev, &olpc_ac_desc, &psy_cfg);
> +	if (IS_ERR(data->olpc_ac))
> +		return PTR_ERR(data->olpc_ac);
> +
>  	if (of_property_match_string(pdev->dev.of_node, "compatible",
>  					"olpc,xo1.5-battery") >= 0) {
>  		/* XO-1.5 */
> @@ -634,42 +643,45 @@ static int olpc_battery_probe(struct platform_device *pdev)
>  		olpc_bat_desc.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
>  	}
>  
> -	olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, NULL);
> +	data->olpc_bat = power_supply_register(&pdev->dev, &olpc_bat_desc, &psy_cfg);
>  	if (IS_ERR(olpc_bat)) {
>  		ret = PTR_ERR(olpc_bat);
>  		goto battery_failed;
>  	}
>  
> -	ret = device_create_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> +	ret = device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
>  	if (ret)
>  		goto eeprom_failed;
>  
> -	ret = device_create_file(&olpc_bat->dev, &olpc_bat_error);
> +	ret = device_create_file(&data->olpc_bat->dev, &olpc_bat_error);
>  	if (ret)
>  		goto error_failed;
>  
>  	if (olpc_ec_wakeup_available()) {
> -		device_set_wakeup_capable(&olpc_ac->dev, true);
> -		device_set_wakeup_capable(&olpc_bat->dev, true);
> +		device_set_wakeup_capable(&data->olpc_ac->dev, true);
> +		device_set_wakeup_capable(&data->olpc_bat->dev, true);
>  	}
>  
>  	return 0;
>  
>  error_failed:
> -	device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> +	device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
>  eeprom_failed:
> -	power_supply_unregister(olpc_bat);
> +	power_supply_unregister(data->olpc_bat);
>  battery_failed:
> -	power_supply_unregister(olpc_ac);
> +	power_supply_unregister(data->olpc_ac);
>  	return ret;
>  }
>  
>  static int olpc_battery_remove(struct platform_device *pdev)
>  {
> -	device_remove_file(&olpc_bat->dev, &olpc_bat_error);
> -	device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom);
> -	power_supply_unregister(olpc_bat);
> -	power_supply_unregister(olpc_ac);
> +	struct olpc_battery_data *data = platform_get_drvdata(pdev);
> +
> +	device_remove_file(&data->olpc_bat->dev, &olpc_bat_error);
> +	device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom);
> +	power_supply_unregister(data->olpc_bat);
> +	power_supply_unregister(data->olpc_ac);
> +
>  	return 0;
>  }
>  
> -- 
> 2.19.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-12-05 20:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16 16:23 [PATCH v2 0/17] Add support for OLPC XO 1.75 Embedded Controller Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 01/17] power: supply: olpc_battery: correct the temperature units Lubomir Rintel
2018-12-05 21:05   ` Sebastian Reichel
2018-11-16 16:23 ` [PATCH v2 02/17] dt-bindings: olpc,xo1.75-ec: Add OLPC XO-1.75 EC bindings Lubomir Rintel
2018-11-17 16:03   ` Rob Herring
2018-11-16 16:23 ` [PATCH v2 03/17] Platform: OLPC: Remove an unused include Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 04/17] Revert "platform/olpc: Make ec explicitly non-modular" Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 05/17] Platform: OLPC: Move OLPC config symbol out of x86 tree Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 06/17] Platform: OLPC: Add XO-1.75 EC driver Lubomir Rintel
2018-12-02 23:13   ` Darren Hart
2018-12-03  7:54     ` Andy Shevchenko
2018-11-16 16:23 ` [PATCH v2 07/17] Platform: OLPC: Avoid a warning if the EC didn't register yet Lubomir Rintel
2018-12-02 23:15   ` Darren Hart
2018-11-16 16:23 ` [PATCH v2 08/17] Platform: OLPC: Move EC-specific functionality out from x86 Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 09/17] Platform: OLPC: Use BIT() and GENMASK() for event masks Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 10/17] Platform: OLPC: add a regulator for the DCON Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 11/17] dt-bindings: olpc_battery: Add XO-1.5 battery Lubomir Rintel
2018-12-05 20:53   ` Sebastian Reichel
2018-11-16 16:23 ` [PATCH v2 12/17] x86, olpc: Use a correct version when making up a battery node Lubomir Rintel
2018-11-16 16:23 ` [PATCH v2 13/17] power: supply: olpc_battery: Use DT to get battery version Lubomir Rintel
2018-12-02 23:24   ` Darren Hart
2018-12-05 20:54   ` Sebastian Reichel
2019-01-07 18:25     ` Lubomir Rintel
2018-11-16 16:24 ` [PATCH v2 14/17] power: supply: olpc_battery: Move priv data to a struct Lubomir Rintel
2018-12-05 20:57   ` Sebastian Reichel [this message]
2018-11-16 16:24 ` [PATCH v2 15/17] power: supply: olpc_battery: Use devm_power_supply_register() Lubomir Rintel
2018-12-05 20:58   ` Sebastian Reichel
2018-11-16 16:24 ` [PATCH v2 16/17] power: supply: olpc_battery: Avoid using platform_info Lubomir Rintel
2018-12-05 20:59   ` Sebastian Reichel
2018-11-16 16:24 ` [PATCH v2 17/17] power: supply: olpc_battery: Add OLPC XO 1.75 support Lubomir Rintel
2018-12-02 23:34   ` Darren Hart
2019-01-07 18:02     ` Lubomir Rintel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181205205706.t2kvn2smjgsjmy2e@earth.universe \
    --to=sebastian.reichel@collabora.com \
    --cc=andy@infradead.org \
    --cc=broonie@kernel.org \
    --cc=daniel@zonque.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dvhart@infradead.org \
    --cc=eric.y.miao@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=haojian.zhuang@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lkundrak@v3.sk \
    --cc=mark.rutland@arm.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=quozl@laptop.org \
    --cc=robert.jarzmik@free.fr \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).