platform/x86: thinkpad_acpi: 4 bug-fixes + 2 cleanups
cover platform/x86: thinkpad_acpi: 4 bug-fixes + 2 cleanups
Hi All,
Here is a thinkpad_acpi series with 4 bug-fixes fixing various bugs which I missed while merging the big patch to move to dev_groups + 2 small cleanups on top.
The first bug-fixes is 5.16-rc# material since one initial patch to move the hotkeys stuff to using is_visible already landed in 5.16-rc1.
Regards,
Hans
Hans de Goede (6):
platform/x86: thinkpad_acpi: Restore missing hotkey_tablet_mode and
hotkey_radio_sw sysfs-attr
platform/x86: thinkpad_acpi: Register tpacpi_pdriver after subdriver
init
platform/x86: thinkpad_acpi: tpacpi_attr_group contains driver
attributes not device attrs
platform/x86: thinkpad_acpi: Fix the hwmon sysfs-attr showing up in
the wrong place
platform/x86: thinkpad_acpi: Remove unused
sensors_pdev_attrs_registered flag
platform/x86: thinkpad_acpi: Move input_unregister_device() to the top
of thinkpad_acpi_module_exit()
drivers/platform/x86/thinkpad_acpi.c | 113 ++++++++++++++++----------- 1 file changed, 66 insertions(+), 47 deletions(-)
Signature · 1 line
2.33.1
PATCH 1/6 platform/x86: thinkpad_acpi: Restore missing hotkey_tablet_mode and hotkey_radio_sw sysfs-attr
Commit c99ca78d67a6 ("platform/x86: thinkpad_acpi: Switch to common use of attributes") removed the conditional adding of the hotkey_tablet_mode and hotkey_radio_sw sysfs-attributes, replacing this with a hotkey_attr_is_visible() callback which hides them when the feature is not present.
But this commit forgot to add these 2 attributes to the default hotkey_attributes[] set, so they would now never get added at all.
Add the 2 attributes to the default hotkey_attributes[] set so that they are available on systems with these features once more.
--- drivers/platform/x86/thinkpad_acpi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +2 -0
@@ -2962,6 +2962,8 @@ static struct attribute *hotkey_attributes[] = { &dev_attr_hotkey_all_mask.attr, &dev_attr_hotkey_adaptive_all_mask.attr, &dev_attr_hotkey_recommended_mask.attr, + &dev_attr_hotkey_tablet_mode.attr, + &dev_attr_hotkey_radio_sw.attr, #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL &dev_attr_hotkey_source_mask.attr, &dev_attr_hotkey_poll_freq.attr,
Signature · 1 line
2.33.1
PATCH 2/6 platform/x86: thinkpad_acpi: Register tpacpi_pdriver after subdriver init
In reply to Hans de GoedeCommit c99ca78d67a6 ("platform/x86: thinkpad_acpi: Switch to common use of attributes") introduces the use of attribute_group.is_visible callbacks replacing the conditional calling of driver_create_file() for optional attributes.
The is_visible callbacks rely on various tp_features.has_foo flags, which get set by the subdriver init functions.
But before this fix, thinkpad_acpi_module_init() would call the subdriver init functions after registering the platform_device and the tpacpi_pdriver. Which would cause the is_visible callbacks to get called before the subdriver init functions, which in turn would cause optional attributes to not get registered at all, even when the feature is actually present.
Fix this by moving the platform_driver_register(&tpacpi_pdriver) to after the subdriver init calls; and do the same for the tpacpi_hmon_pdriver.
--- drivers/platform/x86/thinkpad_acpi.c | 41 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +21 -20
@@ -11166,6 +11166,11 @@ static void thinkpad_acpi_module_exit(void) tpacpi_lifecycle =TPACPI_LIFE_EXITING ; +if (tp_features.sensors_pdrv_registered) +platform_driver_unregister (&tpacpi_hwmon_pdriver); +if (tp_features.platform_drv_registered) +platform_driver_unregister (&tpacpi_pdriver); +list_for_each_entry_safe_reverse (ibm, itmp, &tpacpi_all_drivers, all_drivers) {
@@ -11188,10 +11193,6 @@ static void thinkpad_acpi_module_exit(void)platform_device_unregister (tpacpi_sensors_pdev);if (tpacpi_pdev)platform_device_unregister (tpacpi_pdev); -if (tp_features.sensors_pdrv_registered) -platform_driver_unregister (&tpacpi_hwmon_pdriver); -if (tp_features.platform_drv_registered) -platform_driver_unregister (&tpacpi_pdriver);if (proc_dir)remove_proc_entry (TPACPI_PROC_DIR , acpi_root_dir);if (tpacpi_wq)
@@ -11245,22 +11246,6 @@ static int __init thinkpad_acpi_module_init(void)return -ENODEV ; } - ret =platform_driver_register (&tpacpi_pdriver); -if (ret) { -pr_err ("unable to register main platform driver\n" ); -thinkpad_acpi_module_exit (); -return ret; - } - tp_features.platform_drv_registered =1 ; - - ret =platform_driver_register (&tpacpi_hwmon_pdriver); -if (ret) { -pr_err ("unable to register hwmon platform driver\n" ); -thinkpad_acpi_module_exit (); -return ret; - } - tp_features.sensors_pdrv_registered =1 ; -/* Device initialization */ tpacpi_pdev =platform_device_register_simple (TPACPI_DRVR_NAME ,-1 ,NULL ,0 );
@@ -11324,6 +11309,22 @@ static int __init thinkpad_acpi_module_init(void) tpacpi_lifecycle =TPACPI_LIFE_RUNNING ; + ret =platform_driver_register (&tpacpi_pdriver); +if (ret) { +pr_err ("unable to register main platform driver\n" ); +thinkpad_acpi_module_exit (); +return ret; + } + tp_features.platform_drv_registered =1 ; + + ret =platform_driver_register (&tpacpi_hwmon_pdriver); +if (ret) { +pr_err ("unable to register hwmon platform driver\n" ); +thinkpad_acpi_module_exit (); +return ret; + } + tp_features.sensors_pdrv_registered =1 ; + ret =input_register_device (tpacpi_inputdev);if (ret <0 ) {pr_err ("unable to register input device\n" );
Signature · 1 line
2.33.1
PATCH 3/6 platform/x86: thinkpad_acpi: tpacpi_attr_group contains driver attributes not device attrs
In reply to Hans de GoedeCommit 79f960e29cfc ("platform/x86: thinkpad_acpi: Convert platform driver to use dev_groups") put the debug_level, interface_version, version and the THINKPAD_ACPI_DEBUGFACILITIES attributes in a new tpacpi_attr_group and added those to the tpacpi_groups groups-array which is used to initialize the driver.dev_groups member.
But before this commit these attributes were registered with driver_create_file(), so they should be part of the groups-array which is used to initialize the driver.groups member instead.
And also make the same change for the fan_watchdog hwmon driver attribute.
--- drivers/platform/x86/thinkpad_acpi.c | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +25 -5
@@ -8646,7 +8646,6 @@ static struct attribute *fan_attributes[] = { &dev_attr_pwm1.attr, &dev_attr_fan1_input.attr, &dev_attr_fan2_input.attr, - &driver_attr_fan_watchdog.attr, NULL };
@@ -8670,6 +8669,16 @@ static const struct attribute_group fan_attr_group = { .attrs = fan_attributes, }; +static struct attribute *fan_driver_attributes[] = { + &driver_attr_fan_watchdog.attr, +NULL +}; + +static const struct attribute_group fan_driver_attr_group = { + .is_visible = fan_attr_is_visible, + .attrs = fan_driver_attributes, +}; +#define TPACPI_FAN_Q1 0x0001/* Unitialized HFSP */ #define TPACPI_FAN_2FAN 0x0002/* EC 0x31 bit 0 selects fan2 */ #define TPACPI_FAN_2CTL 0x0004/* selects fan2 control */
@@ -10435,7 +10444,7 @@ static struct ibm_struct dprc_driver_data = {/* --------------------------------------------------------------------- */ -static struct attribute *tpacpi_attributes[] = { +static struct attribute *tpacpi_driver_attributes[] = { &driver_attr_debug_level.attr, &driver_attr_version.attr, &driver_attr_interface_version.attr,
@@ -10470,11 +10479,16 @@ static umode_t tpacpi_attr_is_visible(struct kobject *kobj, }#endif -static const struct attribute_group tpacpi_attr_group = { +static const struct attribute_group tpacpi_driver_attr_group = { #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES .is_visible = tpacpi_attr_is_visible, #endif - .attrs = tpacpi_attributes, + .attrs = tpacpi_driver_attributes, +}; + +static const struct attribute_group *tpacpi_driver_groups[] = { + &tpacpi_driver_attr_group, +NULL , };static const struct attribute_group *tpacpi_groups[] = {
@@ -10486,7 +10500,6 @@ static const struct attribute_group *tpacpi_groups[] = { &proxsensor_attr_group, &kbdlang_attr_group, &dprc_attr_group, - &tpacpi_attr_group, NULL, };
@@ -10497,6 +10510,11 @@ static const struct attribute_group *tpacpi_hwmon_groups[] = { NULL, }; +static const struct attribute_group *tpacpi_hwmon_driver_groups[] = { + &fan_driver_attr_group, +NULL , +}; +/**************************************************************************** **************************************************************************** *
@@ -10509,6 +10527,7 @@ static struct platform_driver tpacpi_pdriver = { .driver = { .name = TPACPI_DRVR_NAME, .pm = &tpacpi_pm, + .groups = tpacpi_driver_groups, .dev_groups = tpacpi_groups, }, .shutdown = tpacpi_shutdown_handler,
@@ -10517,6 +10536,7 @@ static struct platform_driver tpacpi_pdriver = {static struct platform_driver tpacpi_hwmon_pdriver = { .driver = { .name =TPACPI_HWMON_DRVR_NAME , + .groups = tpacpi_hwmon_driver_groups, .dev_groups = tpacpi_hwmon_groups, }, };
Signature · 1 line
2.33.1
PATCH 4/6 platform/x86: thinkpad_acpi: Fix the hwmon sysfs-attr showing up in the wrong place
In reply to Hans de GoedeThe hwmon sysfs-attr should show up under the hwmon-classdev, not under the tpacpi_sensors_pdev. Pass the tpacpi_hwmon_groups attr-groups array to hwmon_device_register_with_groups() instead of setting tpacpi_hwmon_pdriver.driver.dev_groups to it to fix this.
This also requires moving the hwmon_device_register_with_groups() call to after the subdriver init functions have run so that the is_visible() calls will work properly.
--- drivers/platform/x86/thinkpad_acpi.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +12 -12
@@ -10537,7 +10537,6 @@ static struct platform_driver tpacpi_hwmon_pdriver = { .driver = { .name = TPACPI_HWMON_DRVR_NAME, .groups = tpacpi_hwmon_driver_groups, - .dev_groups = tpacpi_hwmon_groups, }, };
@@ -11186,6 +11185,8 @@ static void thinkpad_acpi_module_exit(void) tpacpi_lifecycle =TPACPI_LIFE_EXITING ; +if (tpacpi_hwmon) +hwmon_device_unregister (tpacpi_hwmon);if (tp_features.sensors_pdrv_registered)platform_driver_unregister (&tpacpi_hwmon_pdriver);if (tp_features.platform_drv_registered)
@@ -11207,8 +11208,6 @@ static void thinkpad_acpi_module_exit(void)kfree (hotkey_keycode_map); } -if (tpacpi_hwmon) -hwmon_device_unregister (tpacpi_hwmon);if (tpacpi_sensors_pdev)platform_device_unregister (tpacpi_sensors_pdev);if (tpacpi_pdev)
@@ -11287,16 +11286,7 @@ static int __init thinkpad_acpi_module_init(void)return ret; } tp_features.sensors_pdev_attrs_registered =1 ; - tpacpi_hwmon =hwmon_device_register_with_groups ( - &tpacpi_sensors_pdev->dev,TPACPI_NAME ,NULL ,NULL ); -if (IS_ERR (tpacpi_hwmon)) { - ret =PTR_ERR (tpacpi_hwmon); - tpacpi_hwmon =NULL ; -pr_err ("unable to register hwmon device\n" ); -thinkpad_acpi_module_exit (); -return ret; - }mutex_init (&tpacpi_inputdev_send_mutex); tpacpi_inputdev =input_allocate_device ();if (!tpacpi_inputdev) {
@@ -11345,6 +11335,16 @@ static int __init thinkpad_acpi_module_init(void) } tp_features.sensors_pdrv_registered =1 ; + tpacpi_hwmon =hwmon_device_register_with_groups ( + &tpacpi_sensors_pdev->dev,TPACPI_NAME ,NULL , tpacpi_hwmon_groups); +if (IS_ERR (tpacpi_hwmon)) { + ret =PTR_ERR (tpacpi_hwmon); + tpacpi_hwmon =NULL ; +pr_err ("unable to register hwmon device\n" ); +thinkpad_acpi_module_exit (); +return ret; + } + ret =input_register_device (tpacpi_inputdev);if (ret <0 ) {pr_err ("unable to register input device\n" );
Signature · 1 line
2.33.1
PATCH 5/6 platform/x86: thinkpad_acpi: Remove unused sensors_pdev_attrs_registered flag
In reply to Hans de GoedeAfter the recent sysfs-attributes registration cleanups, the tp_features.sensors_pdev_attrs_registered flag only ever gets set and never gets read, remove it.
--- drivers/platform/x86/thinkpad_acpi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +0 -2
@@ -335,7 +335,6 @@ static struct { u32 input_device_registered:1; u32 platform_drv_registered:1; u32 sensors_pdrv_registered:1; - u32 sensors_pdev_attrs_registered:1; u32 hotkey_poll_active:1; u32 has_adaptive_kbd:1; u32 kbd_lang:1;
@@ -11285,7 +11284,6 @@ static int __init thinkpad_acpi_module_init(void)thinkpad_acpi_module_exit ();return ret; } - tp_features.sensors_pdev_attrs_registered =1 ;mutex_init (&tpacpi_inputdev_send_mutex); tpacpi_inputdev =input_allocate_device ();
Signature · 1 line
2.33.1
PATCH 6/6 platform/x86: thinkpad_acpi: Move input_unregister_device() to the top of thinkpad_acpi_module_exit()
In reply to Hans de GoedeMake input_unregister_device() the first step of thinkpad_acpi_module_exit(), so that the order in thinkpad_acpi_module_exit() properly mirrors the order in thinkpad_acpi_module_init();
And move the kfree(hotkey_keycode_map) call to hotkey_exit() (the exit handler of the hotkey subdriver) where it belongs.
--- drivers/platform/x86/thinkpad_acpi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +6 -8
@@ -3050,6 +3050,8 @@ static void hotkey_exit(void) hotkey_mask_set(hotkey_orig_mask)) | hotkey_status_set(false)) != 0)pr_err ("failed to restore hot key mask to BIOS defaults\n" ); + +kfree (hotkey_keycode_map); }static void __init hotkey_unmap (const unsigned int scancode)
@@ -11184,6 +11186,8 @@ static void thinkpad_acpi_module_exit(void) tpacpi_lifecycle =TPACPI_LIFE_EXITING ; +if (tp_features.input_device_registered) +input_unregister_device (tpacpi_inputdev);if (tpacpi_hwmon)hwmon_device_unregister (tpacpi_hwmon);if (tp_features.sensors_pdrv_registered)
@@ -11199,14 +11203,8 @@ static void thinkpad_acpi_module_exit(void)dbg_printk (TPACPI_DBG_INIT ,"finished subdriver exit path...\n" ); -if (tpacpi_inputdev) { -if (tp_features.input_device_registered) -input_unregister_device (tpacpi_inputdev); -else -input_free_device (tpacpi_inputdev); -kfree (hotkey_keycode_map); - } - +if (tpacpi_inputdev) +input_free_device (tpacpi_inputdev);if (tpacpi_sensors_pdev)platform_device_unregister (tpacpi_sensors_pdev);if (tpacpi_pdev)
Signature · 1 line
2.33.1
Hi all,
Quoted 8 lines · Hans de Goede
Hi All,
Here is a
thinkpad_acpiseries with 4 bug-fixes fixing various bugs which I missed while merging the big patch to move todev_groups+ 2 small cleanups on top.The first bug-fixes is 5.16-rc# material since one initial patch to move the hotkeys stuff to using
is_visiblealready landed in 5.16-rc1.
I've added this series to my review-hans branch now.
Regards,
Hans
Quoted 17 lines
Hans de Goede (6):
platform/x86:thinkpad_acpi: Restore missinghotkey_tablet_modeand
hotkey_radio_swsysfs-attr
platform/x86:thinkpad_acpi: Registertpacpi_pdriverafter subdriver
init
platform/x86:thinkpad_acpi:tpacpi_attr_groupcontains driver
attributes not device attrs
platform/x86:thinkpad_acpi: Fix the hwmon sysfs-attr showing up in
the wrong place
platform/x86:thinkpad_acpi: Remove unused
sensors_pdev_attrs_registeredflag
platform/x86:thinkpad_acpi: Moveinput_unregister_device()to the top
ofthinkpad_acpi_module_exit()drivers/platform/x86/thinkpad_acpi.c | 113 ++++++++++++++++----------- 1 file changed, 66 insertions(+), 47 deletions(-)