2024-06-09 07:27:50

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 0/5] ACPI: (mostly) battery: various fixes

Signed-off-by: Thomas Weißschuh <[email protected]>
---
Thomas Weißschuh (5):
ACPI: AC: constify powersupply properties
ACPI: SBS: constify powersupply properties
ACPI: battery: constify powersupply properties
ACPI: battery: use sysfs_emit over sprintf
ACPI: battery: create alarm sysfs attribute atomically

drivers/acpi/ac.c | 2 +-
drivers/acpi/battery.c | 26 +++++++++++++++++---------
drivers/acpi/sbs.c | 6 +++---
3 files changed, 21 insertions(+), 13 deletions(-)
---
base-commit: 771ed66105de9106a6f3e4311e06451881cdac5e
change-id: 20240609-acpi-battery-cleanup-6b00f8baa1df

Best regards,
--
Thomas Weißschuh <[email protected]>



2024-06-09 07:27:52

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 3/5] ACPI: battery: constify powersupply properties

The arrays are never modified, make them const.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
drivers/acpi/battery.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index b379401ff1c2..984236b95dff 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -308,7 +308,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
return ret;
}

-static enum power_supply_property charge_battery_props[] = {
+static const enum power_supply_property charge_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -326,7 +326,7 @@ static enum power_supply_property charge_battery_props[] = {
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};

-static enum power_supply_property charge_battery_full_cap_broken_props[] = {
+static const enum power_supply_property charge_battery_full_cap_broken_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -340,7 +340,7 @@ static enum power_supply_property charge_battery_full_cap_broken_props[] = {
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};

-static enum power_supply_property energy_battery_props[] = {
+static const enum power_supply_property energy_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -358,7 +358,7 @@ static enum power_supply_property energy_battery_props[] = {
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};

-static enum power_supply_property energy_battery_full_cap_broken_props[] = {
+static const enum power_supply_property energy_battery_full_cap_broken_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,

--
2.45.2


2024-06-09 07:27:59

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 4/5] ACPI: battery: use sysfs_emit over sprintf

sysfs_emit validates assumptions made by sysfs and is the correct
mechanism to format data for sysfs.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
drivers/acpi/battery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 984236b95dff..5f47bd58aff3 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -661,7 +661,7 @@ static ssize_t acpi_battery_alarm_show(struct device *dev,
{
struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));

- return sprintf(buf, "%d\n", battery->alarm * 1000);
+ return sysfs_emit(buf, "%d\n", battery->alarm * 1000);
}

static ssize_t acpi_battery_alarm_store(struct device *dev,

--
2.45.2


2024-06-09 07:29:29

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 5/5] ACPI: battery: create alarm sysfs attribute atomically

Let the power supply core register the attribute.
This ensures that the attribute is created before the device is
announced to userspace, avoid a race condition.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
drivers/acpi/battery.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 5f47bd58aff3..d289b98a2cca 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -678,12 +678,18 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
return count;
}

-static const struct device_attribute alarm_attr = {
+static struct device_attribute alarm_attr = {
.attr = {.name = "alarm", .mode = 0644},
.show = acpi_battery_alarm_show,
.store = acpi_battery_alarm_store,
};

+static struct attribute *acpi_battery_attrs[] = {
+ &alarm_attr.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(acpi_battery);
+
/*
* The Battery Hooking API
*
@@ -823,7 +829,10 @@ static void __exit battery_hook_exit(void)

static int sysfs_add_battery(struct acpi_battery *battery)
{
- struct power_supply_config psy_cfg = { .drv_data = battery, };
+ struct power_supply_config psy_cfg = {
+ .drv_data = battery,
+ .attr_grp = acpi_battery_groups,
+ };
bool full_cap_broken = false;

if (!ACPI_BATTERY_CAPACITY_VALID(battery->full_charge_capacity) &&
@@ -868,7 +877,7 @@ static int sysfs_add_battery(struct acpi_battery *battery)
return result;
}
battery_hook_add_battery(battery);
- return device_create_file(&battery->bat->dev, &alarm_attr);
+ return 0;
}

static void sysfs_remove_battery(struct acpi_battery *battery)
@@ -879,7 +888,6 @@ static void sysfs_remove_battery(struct acpi_battery *battery)
return;
}
battery_hook_remove_battery(battery);
- device_remove_file(&battery->bat->dev, &alarm_attr);
power_supply_unregister(battery->bat);
battery->bat = NULL;
mutex_unlock(&battery->sysfs_lock);

--
2.45.2


2024-06-13 19:49:15

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 0/5] ACPI: (mostly) battery: various fixes

On Sun, Jun 9, 2024 at 9:27 AM Thomas Weißschuh <[email protected]> wrote:
>
> Signed-off-by: Thomas Weißschuh <[email protected]>
> ---
> Thomas Weißschuh (5):
> ACPI: AC: constify powersupply properties
> ACPI: SBS: constify powersupply properties
> ACPI: battery: constify powersupply properties
> ACPI: battery: use sysfs_emit over sprintf
> ACPI: battery: create alarm sysfs attribute atomically
>
> drivers/acpi/ac.c | 2 +-
> drivers/acpi/battery.c | 26 +++++++++++++++++---------
> drivers/acpi/sbs.c | 6 +++---
> 3 files changed, 21 insertions(+), 13 deletions(-)
> ---

Whole series applied as 6.11 material, thanks!