power: supply: Drop use_cnt check from power_supply_property_is_writeable()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hans de Goede <hdegoede@xxxxxxxxxx>

commit 78f281e5bdeb6476fab97a2c3fcece1094b42aaf upstream.

power_supply_property_is_writeable() gets called from the is_visible()
callback for the sysfs attributes of power_supply class devices and for
the sysfs attributes of power_supply core instantiated hwmon class devices.

These sysfs attributes get registered by the device_add() respectively
power_supply_add_hwmon_sysfs() calls in power_supply_register().

use_cnt gets initialized to 0 and is incremented only after these calls.
So when power_supply_property_is_writeable() gets called it always return
-ENODEV because of use_cnt == 0.

This causes all the attributes to have permissions of 444 even those which
should be writable. This used to be a problem only for hwmon sysfs
attributes but since commit be6299c6e55e ("power: supply: sysfs: use
power_supply_property_is_writeable()") this now also impacts power_supply
class sysfs attributes.

Fixes: be6299c6e55e ("power: supply: sysfs: use power_supply_property_is_writeable()")
Fixes: e67d4dfc9ff1 ("power: supply: Add HWMON compatibility layer")
Cc: stable@xxxxxxxxxxxxxxx
Cc: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
Cc: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
Link: https://lore.kernel.org/stable/20240908185337.103696-1-hdegoede%40redhat.com
Link: https://lore.kernel.org/r/20240908185337.103696-1-hdegoede@xxxxxxxxxx
Signed-off-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/power/supply/power_supply_core.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1232,11 +1232,7 @@ EXPORT_SYMBOL_GPL(power_supply_set_prope
 int power_supply_property_is_writeable(struct power_supply *psy,
 					enum power_supply_property psp)
 {
-	if (atomic_read(&psy->use_cnt) <= 0 ||
-			!psy->desc->property_is_writeable)
-		return -ENODEV;
-
-	return psy->desc->property_is_writeable(psy, psp);
+	return psy->desc->property_is_writeable && psy->desc->property_is_writeable(psy, psp);
 }
 EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
 


Patches currently in stable-queue which might be from hdegoede@xxxxxxxxxx are

queue-6.11/hid-i2c-hid-ensure-various-commands-do-not-interfere.patch
queue-6.11/power-supply-drop-use_cnt-check-from-power_supply_property_is_writeable.patch
queue-6.11/platform-x86-isst-fix-the-kasan-report-slab-out-of-bounds-bug.patch
queue-6.11/platform-x86-x86-android-tablets-fix-use-after-free-on-platform_device_register-errors.patch
queue-6.11/power-supply-hwmon-fix-missing-temp1_max_alarm-attribute.patch
queue-6.11/platform-x86-lenovo-ymc-ignore-the-0x0-state.patch
queue-6.11/platform-mellanox-mlxbf-pmc-fix-lockdep-warning.patch
queue-6.11/hid-ignore-battery-for-all-elan-i2c-hid-devices.patch
queue-6.11/acpi-video-add-force_vendor-quirk-for-panasonic-toug.patch
queue-6.11/platform-x86-x86-android-tablets-adjust-xiaomi-pad-2.patch
queue-6.11/platform-x86-amd-pmf-add-quirk-for-tuf-gaming-a14.patch
queue-6.11/platform-x86-touchscreen_dmi-add-nanote-next-quirk.patch
queue-6.11/acpi-ec-do-not-release-locks-during-operation-region.patch




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux