Hi, On 9/12/22 13:53, Armin Wolf wrote: > Since a driver may register multiple instances of a > battery hook, passing data to each instance is > convenient. > > Signed-off-by: Armin Wolf <W_Armin@xxxxxx> Thanks, patch looks good to me: Reviewed-by: Hans de Goede <hdegoede@xxxxxxxxxx> Regards, Hans > --- > drivers/acpi/battery.c | 11 ++++++----- > drivers/platform/x86/asus-wmi.c | 7 ++++--- > drivers/platform/x86/huawei-wmi.c | 6 +++--- > drivers/platform/x86/lg-laptop.c | 6 +++--- > drivers/platform/x86/system76_acpi.c | 6 +++--- > drivers/platform/x86/thinkpad_acpi.c | 6 +++--- > include/acpi/battery.h | 7 ++++--- > 7 files changed, 26 insertions(+), 23 deletions(-) > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 15bb5d868a56..396a7324216c 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -696,7 +696,7 @@ void battery_hook_unregister(struct acpi_battery_hook *hook) > mutex_lock(&hook_mutex); > > list_for_each_entry(battery, &acpi_battery_list, list) { > - hook->ops->remove_battery(battery->bat); > + hook->ops->remove_battery(hook->data, battery->bat); > } > list_del(&hook->list); > > @@ -706,7 +706,7 @@ void battery_hook_unregister(struct acpi_battery_hook *hook) > } > EXPORT_SYMBOL_GPL(battery_hook_unregister); > > -struct acpi_battery_hook *battery_hook_register(const char *name, > +struct acpi_battery_hook *battery_hook_register(const char *name, void *data, > const struct acpi_battery_hook_ops *ops) > { > struct acpi_battery_hook *hook = kzalloc(sizeof(*hook), GFP_KERNEL); > @@ -716,6 +716,7 @@ struct acpi_battery_hook *battery_hook_register(const char *name, > return ERR_PTR(-ENOMEM); > > hook->name = name; > + hook->data = data; > hook->ops = ops; > > mutex_lock(&hook_mutex); > @@ -728,7 +729,7 @@ struct acpi_battery_hook *battery_hook_register(const char *name, > * its attributes. > */ > list_for_each_entry(battery, &acpi_battery_list, list) { > - hook->ops->add_battery(battery->bat); > + hook->ops->add_battery(hook->data, battery->bat); > } > pr_info("new extension: %s\n", hook->name); > > @@ -758,7 +759,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery) > * during the battery module initialization. > */ > list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) { > - hook_node->ops->add_battery(battery->bat); > + hook_node->ops->add_battery(hook_node->data, battery->bat); > } > mutex_unlock(&hook_mutex); > } > @@ -773,7 +774,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery) > * custom attributes from the battery. > */ > list_for_each_entry(hook, &battery_hook_list, list) { > - hook->ops->remove_battery(battery->bat); > + hook->ops->remove_battery(hook->data, battery->bat); > } > /* Then, just remove the battery from the list */ > list_del(&battery->list); > diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c > index 37d8649418f4..18afcf38931f 100644 > --- a/drivers/platform/x86/asus-wmi.c > +++ b/drivers/platform/x86/asus-wmi.c > @@ -882,7 +882,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device, > > static DEVICE_ATTR_RW(charge_control_end_threshold); > > -static int asus_wmi_battery_add(struct power_supply *battery) > +static int asus_wmi_battery_add(void *data, struct power_supply *battery) > { > /* The WMI method does not provide a way to specific a battery, so we > * just assume it is the first battery. > @@ -909,7 +909,7 @@ static int asus_wmi_battery_add(struct power_supply *battery) > return 0; > } > > -static int asus_wmi_battery_remove(struct power_supply *battery) > +static int asus_wmi_battery_remove(void *data, struct power_supply *battery) > { > device_remove_file(&battery->dev, > &dev_attr_charge_control_end_threshold); > @@ -924,7 +924,8 @@ static const struct acpi_battery_hook_ops battery_hook_ops = { > static void asus_wmi_battery_init(struct asus_wmi *asus) > { > if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_RSOC)) { > - asus->hook = battery_hook_register("ASUS Battery Extension", &battery_hook_ops); > + asus->hook = battery_hook_register("ASUS Battery Extension", NULL, > + &battery_hook_ops); > } > } > > diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c > index 6fd02b25a97b..f23806299c1a 100644 > --- a/drivers/platform/x86/huawei-wmi.c > +++ b/drivers/platform/x86/huawei-wmi.c > @@ -469,7 +469,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold); > static DEVICE_ATTR_RW(charge_control_end_threshold); > static DEVICE_ATTR_RW(charge_control_thresholds); > > -static int huawei_wmi_battery_add(struct power_supply *battery) > +static int huawei_wmi_battery_add(void *data, struct power_supply *battery) > { > int err = 0; > > @@ -484,7 +484,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery) > return err; > } > > -static int huawei_wmi_battery_remove(struct power_supply *battery) > +static int huawei_wmi_battery_remove(void *data, struct power_supply *battery) > { > device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold); > device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold); > @@ -507,7 +507,7 @@ static void huawei_wmi_battery_setup(struct device *dev) > return; > } > > - huawei->hook = battery_hook_register("Huawei Battery Extension", > + huawei->hook = battery_hook_register("Huawei Battery Extension", NULL, > &huawei_wmi_battery_hook_ops); > device_create_file(dev, &dev_attr_charge_control_thresholds); > } > diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c > index d8a61a07313e..f1abb1924150 100644 > --- a/drivers/platform/x86/lg-laptop.c > +++ b/drivers/platform/x86/lg-laptop.c > @@ -547,7 +547,7 @@ static DEVICE_ATTR_RW(fn_lock); > static DEVICE_ATTR_RW(charge_control_end_threshold); > static DEVICE_ATTR_RW(battery_care_limit); > > -static int lg_battery_add(struct power_supply *battery) > +static int lg_battery_add(void *data, struct power_supply *battery) > { > if (device_create_file(&battery->dev, > &dev_attr_charge_control_end_threshold)) > @@ -556,7 +556,7 @@ static int lg_battery_add(struct power_supply *battery) > return 0; > } > > -static int lg_battery_remove(struct power_supply *battery) > +static int lg_battery_remove(void *data, struct power_supply *battery) > { > device_remove_file(&battery->dev, > &dev_attr_charge_control_end_threshold); > @@ -750,7 +750,7 @@ static int acpi_add(struct acpi_device *device) > led_classdev_register(&pf_device->dev, &tpad_led); > > wmi_input_setup(); > - hook = battery_hook_register("LG Battery Extension", &battery_hook_ops); > + hook = battery_hook_register("LG Battery Extension", NULL, &battery_hook_ops); > > return 0; > > diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c > index 1ec22db32bd0..9414b9491806 100644 > --- a/drivers/platform/x86/system76_acpi.c > +++ b/drivers/platform/x86/system76_acpi.c > @@ -255,7 +255,7 @@ static struct attribute *system76_battery_attrs[] = { > > ATTRIBUTE_GROUPS(system76_battery); > > -static int system76_battery_add(struct power_supply *battery) > +static int system76_battery_add(void *data, struct power_supply *battery) > { > // System76 EC only supports 1 battery > if (strcmp(battery->desc->name, "BAT0") != 0) > @@ -267,7 +267,7 @@ static int system76_battery_add(struct power_supply *battery) > return 0; > } > > -static int system76_battery_remove(struct power_supply *battery) > +static int system76_battery_remove(void *data, struct power_supply *battery) > { > device_remove_groups(&battery->dev, system76_battery_groups); > return 0; > @@ -280,7 +280,7 @@ static const struct acpi_battery_hook_ops system76_battery_hook_ops = { > > static void system76_battery_init(struct system76_data *data) > { > - data->hook = battery_hook_register("System76 Battery Extension", > + data->hook = battery_hook_register("System76 Battery Extension", NULL, > &system76_battery_hook_ops); > } > > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c > index 8adafc3c31fa..6008d88e0727 100644 > --- a/drivers/platform/x86/thinkpad_acpi.c > +++ b/drivers/platform/x86/thinkpad_acpi.c > @@ -9898,7 +9898,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery); > > /* ACPI battery hooking */ > > -static int tpacpi_battery_add(struct power_supply *battery) > +static int tpacpi_battery_add(void *data, struct power_supply *battery) > { > int batteryid = tpacpi_battery_get_id(battery->desc->name); > > @@ -9909,7 +9909,7 @@ static int tpacpi_battery_add(struct power_supply *battery) > return 0; > } > > -static int tpacpi_battery_remove(struct power_supply *battery) > +static int tpacpi_battery_remove(void *data, struct power_supply *battery) > { > device_remove_groups(&battery->dev, tpacpi_battery_groups); > return 0; > @@ -9943,7 +9943,7 @@ static int __init tpacpi_battery_init(struct ibm_init_struct *ibm) > battery_quirk_table, > ARRAY_SIZE(battery_quirk_table)); > > - battery_info.hook = battery_hook_register("ThinkPad Battery Extension", > + battery_info.hook = battery_hook_register("ThinkPad Battery Extension", NULL, > &battery_hook_ops); > > return 0; > diff --git a/include/acpi/battery.h b/include/acpi/battery.h > index b3c81abada1e..cca401b793b2 100644 > --- a/include/acpi/battery.h > +++ b/include/acpi/battery.h > @@ -11,17 +11,18 @@ > #define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82 > > struct acpi_battery_hook_ops { > - int (*add_battery)(struct power_supply *battery); > - int (*remove_battery)(struct power_supply *battery); > + int (*add_battery)(void *data, struct power_supply *battery); > + int (*remove_battery)(void *data, struct power_supply *battery); > }; > > struct acpi_battery_hook { > const char *name; > const struct acpi_battery_hook_ops *ops; > + void *data; > struct list_head list; > }; > > -struct acpi_battery_hook *battery_hook_register(const char *name, > +struct acpi_battery_hook *battery_hook_register(const char *name, void *data, > const struct acpi_battery_hook_ops *hook); > void battery_hook_unregister(struct acpi_battery_hook *hook); > > -- > 2.30.2 >