Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 6bad28c

Browse files
t-8chrafaeljw
authored andcommitted
ACPI: SBS: manage alarm sysfs attribute through psy core
Let the power supply core register the attribute. This ensures that the attribute is created before the device is announced to userspace, avoiding a race condition. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a231eed commit 6bad28c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

drivers/acpi/sbs.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct acpi_battery {
7777
u16 spec;
7878
u8 id;
7979
u8 present:1;
80-
u8 have_sysfs_alarm:1;
8180
};
8281

8382
#define to_acpi_battery(x) power_supply_get_drvdata(x)
@@ -462,12 +461,18 @@ static ssize_t acpi_battery_alarm_store(struct device *dev,
462461
return count;
463462
}
464463

465-
static const struct device_attribute alarm_attr = {
464+
static struct device_attribute alarm_attr = {
466465
.attr = {.name = "alarm", .mode = 0644},
467466
.show = acpi_battery_alarm_show,
468467
.store = acpi_battery_alarm_store,
469468
};
470469

470+
static struct attribute *acpi_battery_attrs[] = {
471+
&alarm_attr.attr,
472+
NULL
473+
};
474+
ATTRIBUTE_GROUPS(acpi_battery);
475+
471476
/* --------------------------------------------------------------------------
472477
Driver Interface
473478
-------------------------------------------------------------------------- */
@@ -518,7 +523,10 @@ static int acpi_battery_read(struct acpi_battery *battery)
518523
static int acpi_battery_add(struct acpi_sbs *sbs, int id)
519524
{
520525
struct acpi_battery *battery = &sbs->battery[id];
521-
struct power_supply_config psy_cfg = { .drv_data = battery, };
526+
struct power_supply_config psy_cfg = {
527+
.drv_data = battery,
528+
.attr_grp = acpi_battery_groups,
529+
};
522530
int result;
523531

524532
battery->id = id;
@@ -548,10 +556,6 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
548556
goto end;
549557
}
550558

551-
result = device_create_file(&battery->bat->dev, &alarm_attr);
552-
if (result)
553-
goto end;
554-
battery->have_sysfs_alarm = 1;
555559
end:
556560
pr_info("%s [%s]: Battery Slot [%s] (battery %s)\n",
557561
ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
@@ -563,11 +567,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
563567
{
564568
struct acpi_battery *battery = &sbs->battery[id];
565569

566-
if (battery->bat) {
567-
if (battery->have_sysfs_alarm)
568-
device_remove_file(&battery->bat->dev, &alarm_attr);
570+
if (battery->bat)
569571
power_supply_unregister(battery->bat);
570-
}
571572
}
572573

573574
static int acpi_charger_add(struct acpi_sbs *sbs)

0 commit comments

Comments
 (0)