linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/20] power_supply: Allow safe usage of power supply
@ 2015-01-30 14:47 Krzysztof Kozlowski
  2015-01-30 14:47 ` [PATCH v3 01/20] power_supply: Add driver private data Krzysztof Kozlowski
                   ` (20 more replies)
  0 siblings, 21 replies; 32+ messages in thread
From: Krzysztof Kozlowski @ 2015-01-30 14:47 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel, Rafael J. Wysocki, Len Brown,
	Jiri Kosina, David Herrmann, Cezary Jackiewicz, Darren Hart,
	Support Opensource, Milo Kim, Julian Andres Klode, Marc Dietrich,
	Greg Kroah-Hartman, linux-acpi, linux-input, platform-driver-x86,
	patches, ac100, linux-tegra, devel, Linus Walleij, Samuel Ortiz,
	Lee Jones, linux-arm-kernel, Ingo Molnar, H. Peter Anvin, x86,
	Daniel Mack, Haojian Zhuang, Robert Jarzmik, Russell King
  Cc: Thomas Gleixner, Pavel Machek, Kyungmin Park,
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Hi,

The patchset changes power supply API and drivers implementing
power supply class.


TLDR for driver and subsystem maintainers
=========================================
Two patches of patchset change power_supply_register() function so in
the same time they touch all drivers. I am kindly asking for acks,
review and help in testing.

Please look at:
 - patch 2: power_supply: Move run-time configuration to separate structure
 - patch 11: power_supply: Change ownership from driver to core

These are huge.


Introduction
============
Patchset tries to fix following race scenario:

Thread 1: charger manager, CONSUMER
Thread 2: power supply driver, PROVIDER

THREAD 1 (charger manager)         THREAD 2 (power supply driver)
==========================         ==============================
psy = power_supply_get_by_name()
                                   Driver unbind, .remove
                                     power_supply_unregister()
                                     Device fully removed
psy->get_property()

To properly fix the race the patchset:
1. Moves ownership of power_supply structure from driver (provider) to
   power supply core.
2. Adds power_supply_get_property()-like API for safe access by consumer.
3. Adds power_supply_put() which will reclaim memory.


Description
=========== 
The patchset is quite big and touches power supply API so a lot of
changes in drivers are needed.

I modifed all drivers I found. However I only compile tested them
(plus Smatch, Sparse and coccicheck). I did not test them on real
hardware (except max14577, max77693, max17040, max17042
and charger-manager).

This is a little different than my previous approaches [1][2] for fixing
usage of power supply by some consumer, if driver implementing it is
unbound.

My previous approach [1][2] limited the race but did not close it.
Still the consumer of power supply by calling power_supply_get_propert(psy...)
may reference invalid memory because the producer freed it.

Actually, because struct power_supply is exposed to consumers, the
core should be the owner of it. This is accomplished in patch 11/20
("power_supply: Change ownership from driver to core").


What the patchset does in steps
===============================
1. Some preparation steps are necessary - patch 1 and 2. The driver
   implementing power supply won't be able to fill structure before
   calling power_supply_register(). So 'power_supply_config'
   is introduced in patch 2 ("power_supply: Move run-time configuration
   to separate structure"). Unfortunately this touches all drivers.
   *All drivers touched.*

2. Safe API wrappers (and usage counter) are added (power_supply_*()).

3. Patch 11: ownership of 'struct power_supply' is moved from driver
   to the core.
   *All drivers touched.*

4. power_supply_put() is added which reclaims resources.


The patchset is rebased on next-20150129. Bisectability is preserved.
All later patches depend on previous ones so it could be pulled in
steps, but cherry-picking won't work.

Changes since v2
================
1. Rewrite all drivers to new power_supply_register().
2. Add reviewed-by Bartlomiej Zolnierkiewicz (internal review)
3. Add reviewed-by Sebastian Reichel [3] (to patches which I did not
   change in major way between v2 and v3).
4. Use atomic usage counter of power supply on each of:
   a. register/unregister,
   b. get/put.

Changes since v1
================
1. Add new patches (1, 2, 11, 19).
2. Preserved ack-s where there weren't any changes.
3. Patch 3: Add use counter.
4. Patch 3: Don't add wrapper for set_charged() because already exists
   one.


[1] https://lkml.org/lkml/2014/11/4/527
[2] https://lkml.org/lkml/2014/10/16/89
[3] https://lkml.org/lkml/2015/1/21/471

Best regards,
Krzysztof


Krzysztof Kozlowski (20):
  power_supply: Add driver private data
  power_supply: Move run-time configuration to separate structure
  power_supply: Add API for safe access of power supply function attrs
  power_supply: sysfs: Use power_supply_*() API for accessing function
    attrs
  power_supply: 88pm860x_charger: Use power_supply_*() API for accessing
    function attrs
  power_supply: ab8500: Use power_supply_*() API for accessing function
    attrs
  mfd: ab8500: Use power_supply_*() API for accessing function attrs
  power_supply: apm_power: Use power_supply_*() API for accessing
    function attrs
  power_supply: bq2415x_charger: Use power_supply_*() API for accessing
    function attrs
  power_supply: charger-manager: Use power_supply_*() API for accessing
    function attrs
  power_supply: Change ownership from driver to core
  power_supply: Add power_supply_put for decrementing device reference
    counter
  power_supply: Increment power supply use counter when obtaining
    references
  power_supply: charger-manager: Decrement the power supply's device
    reference counter
  x86/olpc/xo1/sci: Use newly added power_supply_put API
  x86/olpc/xo15/sci: Use newly added power_supply_put API
  power_supply: 88pm860x_charger: Decrement the power supply's device
    reference counter
  power_supply: bq2415x_charger: Decrement the power supply's device
    reference counter
  mfd: ab8500: Decrement the power supply's device reference counter
  arm: mach-pxa: Decrement the power supply's device reference counter

 arch/arm/mach-pxa/raumfeld.c              |   4 +-
 arch/x86/platform/olpc/olpc-xo1-sci.c     |   4 +-
 arch/x86/platform/olpc/olpc-xo15-sci.c    |   4 +-
 drivers/acpi/ac.c                         |  32 ++--
 drivers/acpi/battery.c                    |  54 ++++---
 drivers/acpi/sbs.c                        |  68 +++++----
 drivers/hid/hid-input.c                   |  51 ++++---
 drivers/hid/hid-sony.c                    |  43 +++---
 drivers/hid/hid-wiimote-modules.c         |  41 ++---
 drivers/hid/hid-wiimote.h                 |   3 +-
 drivers/hid/wacom.h                       |   8 +-
 drivers/hid/wacom_sys.c                   |  70 +++++----
 drivers/mfd/ab8500-sysctrl.c              |   9 +-
 drivers/platform/x86/compal-laptop.c      |  29 ++--
 drivers/power/88pm860x_battery.c          |  40 ++---
 drivers/power/88pm860x_charger.c          |  61 +++++---
 drivers/power/ab8500_btemp.c              |  75 +++++----
 drivers/power/ab8500_charger.c            | 139 +++++++++--------
 drivers/power/ab8500_fg.c                 | 129 +++++++---------
 drivers/power/abx500_chargalg.c           |  98 ++++++------
 drivers/power/apm_power.c                 |   6 +-
 drivers/power/bq2415x_charger.c           | 107 +++++++------
 drivers/power/bq24190_charger.c           | 103 ++++++-------
 drivers/power/bq24735-charger.c           |  53 ++++---
 drivers/power/bq27x00_battery.c           |  70 ++++-----
 drivers/power/charger-manager.c           | 158 +++++++++++--------
 drivers/power/collie_battery.c            |  75 +++++----
 drivers/power/da9030_battery.c            |  32 ++--
 drivers/power/da9052-battery.c            |  25 +--
 drivers/power/ds2760_battery.c            |  56 +++----
 drivers/power/ds2780_battery.c            |  45 +++---
 drivers/power/ds2781_battery.c            |  46 +++---
 drivers/power/ds2782_battery.c            |  30 ++--
 drivers/power/generic-adc-battery.c       |  54 ++++---
 drivers/power/goldfish_battery.c          |  62 ++++----
 drivers/power/gpio-charger.c              |  42 +++---
 drivers/power/intel_mid_battery.c         |  57 ++++---
 drivers/power/ipaq_micro_battery.c        |  34 +++--
 drivers/power/isp1704_charger.c           |  49 +++---
 drivers/power/jz4740-battery.c            |  37 +++--
 drivers/power/lp8727_charger.c            |  94 ++++++------
 drivers/power/lp8788-charger.c            |  62 +++++---
 drivers/power/ltc2941-battery-gauge.c     |  51 ++++---
 drivers/power/max14577_charger.c          |  34 +++--
 drivers/power/max17040_battery.c          |  31 ++--
 drivers/power/max17042_battery.c          |  45 ++++--
 drivers/power/max77693_charger.c          |  32 ++--
 drivers/power/max8903_charger.c           |  52 ++++---
 drivers/power/max8925_power.c             |  98 ++++++------
 drivers/power/max8997_charger.c           |  31 ++--
 drivers/power/max8998_charger.c           |  32 ++--
 drivers/power/olpc_battery.c              |  54 ++++---
 drivers/power/pcf50633-charger.c          | 105 +++++++------
 drivers/power/pda_power.c                 |  65 ++++----
 drivers/power/pm2301_charger.c            |  48 +++---
 drivers/power/pm2301_charger.h            |   1 +
 drivers/power/pmu_battery.c               |  42 ++++--
 drivers/power/power_supply_core.c         | 243 ++++++++++++++++++++++--------
 drivers/power/power_supply_leds.c         |  25 +--
 drivers/power/power_supply_sysfs.c        |  24 +--
 drivers/power/rt5033_battery.c            |  27 ++--
 drivers/power/rx51_battery.c              |  27 ++--
 drivers/power/s3c_adc_battery.c           |  76 +++++-----
 drivers/power/sbs-battery.c               |  71 ++++-----
 drivers/power/smb347-charger.c            | 108 +++++++------
 drivers/power/test_power.c                |  53 ++++---
 drivers/power/tosa_battery.c              | 112 ++++++++------
 drivers/power/tps65090-charger.c          |  43 +++---
 drivers/power/twl4030_charger.c           |  65 ++++----
 drivers/power/twl4030_madc_battery.c      |  41 ++---
 drivers/power/wm831x_backup.c             |  26 ++--
 drivers/power/wm831x_power.c              |  95 ++++++------
 drivers/power/wm8350_power.c              |  89 ++++++-----
 drivers/power/wm97xx_battery.c            |  37 ++---
 drivers/power/z2_battery.c                |  60 ++++----
 drivers/staging/nvec/nvec_power.c         |  34 +++--
 include/linux/hid.h                       |   6 +-
 include/linux/mfd/abx500/ux500_chargalg.h |  11 +-
 include/linux/mfd/rt5033.h                |   2 +-
 include/linux/mfd/wm8350/supply.h         |   6 +-
 include/linux/power/charger-manager.h     |   3 +-
 include/linux/power_supply.h              |  70 +++++++--
 82 files changed, 2467 insertions(+), 1867 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2015-02-11 22:12 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30 14:47 [PATCH v3 00/20] power_supply: Allow safe usage of power supply Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 01/20] power_supply: Add driver private data Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 02/20] power_supply: Move run-time configuration to separate structure Krzysztof Kozlowski
2015-02-07  2:19   ` Darren Hart
2015-01-30 14:47 ` [PATCH v3 03/20] power_supply: Add API for safe access of power supply function attrs Krzysztof Kozlowski
2015-02-04 13:44   ` Pavel Machek
2015-01-30 14:47 ` [PATCH v3 04/20] power_supply: sysfs: Use power_supply_*() API for accessing " Krzysztof Kozlowski
2015-02-09 19:02   ` Stefan Wahren
2015-02-10  7:39     ` Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 05/20] power_supply: 88pm860x_charger: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 06/20] power_supply: ab8500: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 07/20] mfd: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 08/20] power_supply: apm_power: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 09/20] power_supply: bq2415x_charger: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 10/20] power_supply: charger-manager: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 11/20] power_supply: Change ownership from driver to core Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 12/20] power_supply: Add power_supply_put for decrementing device reference counter Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 13/20] power_supply: Increment power supply use counter when obtaining references Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 14/20] power_supply: charger-manager: Decrement the power supply's device reference counter Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 15/20] x86/olpc/xo1/sci: Use newly added power_supply_put API Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 16/20] x86/olpc/xo15/sci: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 17/20] power_supply: 88pm860x_charger: Decrement the power supply's device reference counter Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 18/20] power_supply: bq2415x_charger: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 19/20] mfd: ab8500: " Krzysztof Kozlowski
2015-01-30 14:47 ` [PATCH v3 20/20] arm: mach-pxa: " Krzysztof Kozlowski
2015-02-06 13:49   ` Pavel Machek
2015-02-06 14:43     ` Krzysztof Kozlowski
2015-02-06 14:59       ` Pavel Machek
2015-02-09 10:07         ` Krzysztof Kozlowski
2015-02-11 22:12           ` Pavel Machek
2015-02-07 12:54   ` Robert Jarzmik
2015-02-02  8:58 ` [PATCH v3 00/20] power_supply: Allow safe usage of power supply Marc Dietrich

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).