linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCHv2 00/19] power_supply: Allow safe usage of power supply
@ 2015-01-05 15:47 Krzysztof Kozlowski
  2015-01-05 15:47 ` [RFC PATCHv2 01/19] power_supply: Add driver private data Krzysztof Kozlowski
                   ` (19 more replies)
  0 siblings, 20 replies; 29+ messages in thread
From: Krzysztof Kozlowski @ 2015-01-05 15:47 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,


This is RFC, please don't apply yet but let me know if this approach
is OK.


TLDR
====
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. Adds power_supply_get_property()-like API for safe access by consumer.
2. Moves ownership of power_supply structure from driver (provider) to
   power supply core.
3. Adds power_supply_put() which will reclaim memory.


Description
=========== 
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.

The patchset is quite big and touches power supply API so a lot of
changes in drivers are needed. These changes *are not finished yet*.
I've done them only for:
 - bq24190_charger.c
 - charger-manager.c
 - max14577_charger.c
 - max17040_battery.c
 - max17042_battery.c
 - sbs-battery.c
 - tps65090-charger.c
So allyesconfig won't build.

If this approach is OK, I'll prepare full patchset changing all the
drivers.

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/19
("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.
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.
4. power_supply_put() is added which reclaims resources.


The patchset is rebased on next-20141226. It should be pulled at once.
Bisectability is preserved.

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

Best regards,
Krzysztof


Krzysztof Kozlowski (19):
  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: 88pm860x_charger: Use power_supply_*() API for accessing
    function attrs
  power: ab8500: Use power_supply_*() API for accessing function attrs
  mfd: ab8500: Use power_supply_*() API for accessing function attrs
  power: apm_power: Use power_supply_*() API for accessing function
    attrs
  power: bq2415x_charger: Use power_supply_*() API for accessing
    function attrs
  power: 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: 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: 88pm860x_charger: Decrement the power supply's device reference
    counter
  power: 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/battery.c                 |   3 +-
 drivers/mfd/ab8500-sysctrl.c           |   9 +-
 drivers/power/88pm860x_charger.c       |  24 ++--
 drivers/power/ab8500_btemp.c           |   2 +-
 drivers/power/ab8500_charger.c         |   2 +-
 drivers/power/ab8500_fg.c              |   2 +-
 drivers/power/abx500_chargalg.c        |   4 +-
 drivers/power/apm_power.c              |   4 +-
 drivers/power/bq2415x_charger.c        |   9 +-
 drivers/power/bq24190_charger.c        | 103 ++++++++-------
 drivers/power/charger-manager.c        | 158 +++++++++++++----------
 drivers/power/max14577_charger.c       |  34 ++---
 drivers/power/max17040_battery.c       |  31 ++---
 drivers/power/max17042_battery.c       |  45 ++++---
 drivers/power/power_supply_core.c      | 223 ++++++++++++++++++++++++---------
 drivers/power/power_supply_leds.c      |  25 ++--
 drivers/power/power_supply_sysfs.c     |  24 ++--
 drivers/power/sbs-battery.c            |  71 +++++------
 drivers/power/tps65090-charger.c       |  43 ++++---
 include/linux/power/charger-manager.h  |   3 +-
 include/linux/power_supply.h           |  70 ++++++++---
 24 files changed, 562 insertions(+), 339 deletions(-)

-- 
1.9.1

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

end of thread, other threads:[~2015-01-21 15:42 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05 15:47 [RFC PATCHv2 00/19] power_supply: Allow safe usage of power supply Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 01/19] power_supply: Add driver private data Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 02/19] power_supply: Move run-time configuration to separate structure Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 03/19] power_supply: Add API for safe access of power supply function attrs Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 04/19] power_supply: sysfs: Use power_supply_*() API for accessing " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 05/19] power: 88pm860x_charger: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 06/19] power: ab8500: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 07/19] mfd: " Krzysztof Kozlowski
2015-01-20 13:36   ` Lee Jones
2015-01-20 14:16     ` Krzysztof Kozlowski
2015-01-20 15:51       ` Lee Jones
2015-01-20 16:01         ` Krzysztof Kozlowski
2015-01-20 16:26           ` Lee Jones
2015-01-20 16:06         ` Pavel Machek
2015-01-05 15:47 ` [RFC PATCHv2 08/19] power: apm_power: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 09/19] power: bq2415x_charger: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 10/19] power: charger-manager: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 11/19] power_supply: Change ownership from driver to core Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 12/19] power_supply: Add power_supply_put for decrementing device reference counter Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 13/19] power: charger-manager: Decrement the power supply's " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 14/19] x86/olpc/xo1/sci: Use newly added power_supply_put API Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 15/19] x86/olpc/xo15/sci: " Krzysztof Kozlowski
2015-01-05 15:47 ` [RFC PATCHv2 16/19] power: 88pm860x_charger: Decrement the power supply's device reference counter Krzysztof Kozlowski
2015-01-05 15:48 ` [RFC PATCHv2 17/19] power: bq2415x_charger: " Krzysztof Kozlowski
2015-01-05 15:48 ` [RFC PATCHv2 18/19] mfd: ab8500: " Krzysztof Kozlowski
2015-01-20 13:36   ` Lee Jones
2015-01-05 15:48 ` [RFC PATCHv2 19/19] arm: mach-pxa: " Krzysztof Kozlowski
2015-01-21 15:22 ` [RFC PATCHv2 00/19] power_supply: Allow safe usage of power supply Sebastian Reichel
2015-01-21 15:42   ` Krzysztof Kozlowski

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