linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] power_supply: Small improvements for 4.2
@ 2015-05-19  7:16 Krzysztof Kozlowski
  2015-05-19  7:16 ` [PATCH 1/2] power_supply: Use wrappers to avoid races when registering power supply Krzysztof Kozlowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-19  7:16 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

Hi,

I send these separately because they are not fixes for current
RC cycle.

The patch 1 could look like fix... but still this is for theoretical
race condition.

Best regards,
Krzysztof

Krzysztof Kozlowski (2):
  power_supply: Use wrappers to avoid races when registering power
    supply
  power_supply: charger-manager: Add parent for power supply

 drivers/power/charger-manager.c    | 3 ++-
 drivers/power/power_supply_leds.c  | 4 ++--
 drivers/power/power_supply_sysfs.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

-- 
1.9.1


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

* [PATCH 1/2] power_supply: Use wrappers to avoid races when registering power supply
  2015-05-19  7:16 [PATCH 0/2] power_supply: Small improvements for 4.2 Krzysztof Kozlowski
@ 2015-05-19  7:16 ` Krzysztof Kozlowski
  2015-05-19  7:16 ` [PATCH 2/2] power_supply: charger-manager: Add parent for " Krzysztof Kozlowski
  2015-05-24 19:47 ` [PATCH 0/2] power_supply: Small improvements for 4.2 Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-19  7:16 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

Use wrappers over get_property() and set_property() internally in power
supply and for sysfs interface. The wrappers provide safe access if
power supply is not yet registered or t is being destroyed.

In case of syfs the theoretical race could happen between ending of
driver's probe and parallel sysfs access:
some_driver_probe()                    userspace
====================================   ===========================
  drv->psy = power_supply_register()
    device_add()
      sysfs entries are created
    atomic_inc(&psy->use_cnt);
                                       store on sysfs attributes
                                         drv->set_property()
                                           dereference of drv->psy
  drv->psy = returned psy;

For leds the race could happen between power supply being destroyed and
ongoing power_supply_changed_work().

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/power/power_supply_leds.c  | 4 ++--
 drivers/power/power_supply_sysfs.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/power_supply_leds.c b/drivers/power/power_supply_leds.c
index 2d41a43fc81a..2277ad9c2f68 100644
--- a/drivers/power/power_supply_leds.c
+++ b/drivers/power/power_supply_leds.c
@@ -25,7 +25,7 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
 	unsigned long delay_on = 0;
 	unsigned long delay_off = 0;
 
-	if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
+	if (power_supply_get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
 		return;
 
 	dev_dbg(&psy->dev, "%s %d\n", __func__, status.intval);
@@ -115,7 +115,7 @@ static void power_supply_update_gen_leds(struct power_supply *psy)
 {
 	union power_supply_propval online;
 
-	if (psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
+	if (power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
 		return;
 
 	dev_dbg(&psy->dev, "%s %d\n", __func__, online.intval);
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index 9134e3d2d95e..af026806cba5 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -125,7 +125,7 @@ static ssize_t power_supply_store_property(struct device *dev,
 
 	value.intval = long_val;
 
-	ret = psy->desc->set_property(psy, off, &value);
+	ret = power_supply_set_property(psy, off, &value);
 	if (ret < 0)
 		return ret;
 
-- 
1.9.1


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

* [PATCH 2/2] power_supply: charger-manager: Add parent for power supply
  2015-05-19  7:16 [PATCH 0/2] power_supply: Small improvements for 4.2 Krzysztof Kozlowski
  2015-05-19  7:16 ` [PATCH 1/2] power_supply: Use wrappers to avoid races when registering power supply Krzysztof Kozlowski
@ 2015-05-19  7:16 ` Krzysztof Kozlowski
  2015-05-24 19:47 ` [PATCH 0/2] power_supply: Small improvements for 4.2 Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-19  7:16 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel
  Cc: Krzysztof Kozlowski

The 'parent' argument passed to power_supply_register() is now used to
postpone callbacks to the driver until the driver's probe end.

Pass current device from charger-manager to utilize that. This will move
created power supply from virtual to platform devices.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/power/charger-manager.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 0aed13f90891..1c202ccbd2a6 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -1768,7 +1768,8 @@ static int charger_manager_probe(struct platform_device *pdev)
 
 	INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
 
-	cm->charger_psy = power_supply_register(NULL, &cm->charger_psy_desc,
+	cm->charger_psy = power_supply_register(&pdev->dev,
+						&cm->charger_psy_desc,
 						&psy_cfg);
 	if (IS_ERR(cm->charger_psy)) {
 		dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
-- 
1.9.1


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

* Re: [PATCH 0/2] power_supply: Small improvements for 4.2
  2015-05-19  7:16 [PATCH 0/2] power_supply: Small improvements for 4.2 Krzysztof Kozlowski
  2015-05-19  7:16 ` [PATCH 1/2] power_supply: Use wrappers to avoid races when registering power supply Krzysztof Kozlowski
  2015-05-19  7:16 ` [PATCH 2/2] power_supply: charger-manager: Add parent for " Krzysztof Kozlowski
@ 2015-05-24 19:47 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2015-05-24 19:47 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm, linux-kernel

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

Hi,

On Tue, May 19, 2015 at 04:16:28PM +0900, Krzysztof Kozlowski wrote:
> I send these separately because they are not fixes for current
> RC cycle.
> 
> The patch 1 could look like fix... but still this is for theoretical
> race condition.

Thanks, queued.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-05-24 19:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19  7:16 [PATCH 0/2] power_supply: Small improvements for 4.2 Krzysztof Kozlowski
2015-05-19  7:16 ` [PATCH 1/2] power_supply: Use wrappers to avoid races when registering power supply Krzysztof Kozlowski
2015-05-19  7:16 ` [PATCH 2/2] power_supply: charger-manager: Add parent for " Krzysztof Kozlowski
2015-05-24 19:47 ` [PATCH 0/2] power_supply: Small improvements for 4.2 Sebastian Reichel

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