platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events
Subsystems (3)
PATCH v4 1/3 platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events
This will be used by the Dell and Lenovo WMI management drivers to prevent both drivers being active.
---
Changes in v2:
- This is a new file requested as part of the review of the proposedthink_lmi.c driver. Labeling as V2 to keep series consistent
Changes in v3:
- Set default in Kconfig, and removed help text
- Allow multiple modules to register with module. Change API names to better reflect this.
Changes in v4:
- version bump for consistency in series
drivers/platform/x86/Kconfig | 4 ++ drivers/platform/x86/Makefile | 1 + .../platform/x86/firmware_attributes_class.c | 53 +++++++++++++++++++ .../platform/x86/firmware_attributes_class.h | 13 +++++ 4 files changed, 71 insertions(+) create mode 100644 drivers/platform/x86/firmware_attributes_class.c create mode 100644 drivers/platform/x86/firmware_attributes_class.h
drivers/platform/x86/Kconfig +4 -0
@@ -1076,6 +1076,10 @@ config TOUCHSCREEN_DMI the OS-image for the device. This option supplies the missing info. Enable this for x86 tablets with Silead or Chipone touchscreens. +config FW_ATTR_CLASS + tristate "Firmware attributes class helper module" + default n + config INTEL_IMR bool "Intel Isolated Memory Region support" depends on X86_INTEL_QUARK && IOSF_MBI
drivers/platform/x86/Makefile +1 -0
@@ -115,6 +115,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o +obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.o # Intel uncore drivers obj-$(CONFIG_INTEL_IPS) += intel_ips.o
drivers/platform/x86/firmware_attributes_class.c new file +53 -0
53 lines not on this page · raw message
drivers/platform/x86/firmware_attributes_class.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* Firmware attributes class helper module */ + +#ifndef FW_ATTR_CLASS_H +#define FW_ATTR_CLASS_H + +int fw_attributes_class_get (struct class **fw_attr_class); +int fw_attributes_class_put (void ); + +#endif /* FW_ATTR_CLASS_H */ + +
Signature · 1 line
2.31.1
PATCH v4 2/3 platform/x86: dell-wmi-sysman: Use firmware_attributes_class helper
Update Dell WMI sysman driver to use newly implemented helper module.
---
Changes in v2:
- firmare_attributes_class.c added as reqested during review of the proposed think_lmi.c driver. Labeling as V2 to keep series consistent
- Note, compile tested only due to lack of HW to test on. Matching changes were made in the think-lmi.c driver and worked. Please let me know if any problems!
Changes in v3:
- Updated to use new firmware attribute class API names
Changes in v4:
- version bump for consistency in series
drivers/platform/x86/dell/Kconfig | 1 + .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/platform/x86/dell/Kconfig +1 -0
@@ -197,6 +197,7 @@ config DELL_WMI_SYSMAN depends on ACPI_WMI depends on DMI select NLS + select FW_ATTR_CLASS help This driver allows changing BIOS settings on many Dell machines from 2018 and newer without the use of any additional software.
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +8 -10
@@ -13,14 +13,11 @@#include <linux/kernel.h> #include <linux/wmi.h> #include "dell-wmi-sysman.h" +#include "../../firmware_attributes_class.h" #define MAX_TYPES 4#include <linux/nls.h> -static struct class firmware_attributes_class = { - .name ="firmware-attributes" , -}; -struct wmi_sysman_priv wmi_priv = { .mutex =__MUTEX_INITIALIZER (wmi_priv.mutex), };
@@ -28,6 +25,7 @@ struct wmi_sysman_priv wmi_priv = {/* reset bios to defaults */ static const char *const reset_types[] = {"builtinsafe" ,"lastknowngood" ,"factory" ,"custom" };static int reset_option =-1 ; +struct class *fw_attr_class;/**
@@ -541,11 +539,11 @@ static int __init sysman_init(void) goto err_exit_bios_attr_pass_interface; } - ret =class_register (&firmware_attributes_class); + ret =fw_attributes_class_get (&fw_attr_class);if (ret) goto err_exit_bios_attr_pass_interface; - wmi_priv.class_dev =device_create (&firmware_attributes_class,NULL ,MKDEV (0 ,0 ), + wmi_priv.class_dev =device_create (fw_attr_class,NULL ,MKDEV (0 ,0 ),NULL ,"%s" ,DRIVER_NAME );if (IS_ERR (wmi_priv.class_dev)) { ret =PTR_ERR (wmi_priv.class_dev);
@@ -602,10 +600,10 @@ static int __init sysman_init(void)release_attributes_data (); err_destroy_classdev: -device_destroy (&firmware_attributes_class,MKDEV (0 ,0 )); +device_destroy (fw_attr_class,MKDEV (0 ,0 )); err_unregister_class: -class_unregister (&firmware_attributes_class); +fw_attributes_class_put (); err_exit_bios_attr_pass_interface:exit_bios_attr_pass_interface ();
@@ -619,8 +617,8 @@ static int __init sysman_init(void) static void __exit sysman_exit(void) {release_attributes_data (); -device_destroy (&firmware_attributes_class,MKDEV (0 ,0 )); -class_unregister (&firmware_attributes_class); +device_destroy (fw_attr_class,MKDEV (0 ,0 )); +fw_attributes_class_put ();exit_bios_attr_set_interface ();exit_bios_attr_pass_interface (); }
Signature · 1 line
2.31.1
PATCH v4 3/3 platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Mark PearsonFor Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
---
Changes in V2:
- Improved error handling
- updated to use kobj's better (thanks Hans for pointers). Makes code simpler and cleaner
- Removed some dead code from previous implementation that I'd missed
- Moved think-lmi.h into platform/x86 directory
- Use firmware_attributes_class helper
- Corrected some bad indexing when storing an attribute
- improved encoding options to limit selection
- Added details on encoding and kbdlang to sysfs-class-firmware-attributes documentation
Changes in v3:
- Clean up is_enabled display
- Use new firmware-attributes class API names
- Correct release of kobj objects
- Change pwd_type to const char
- Add role field to pwd_settings
- Improved checking when setting new password
Changes in v4:
- Updated documentation with password update specifics
- Implement tlmi_errs to make error string scanning cleaner
- Clean up pointer check handling
- Clean up pointer free handling
- Clean up pwd string length handling as recommended
- Use kasprintf where appropriate
- use strreplace where appropriate
- Cosmetic cleanups as recommended
.../testing/sysfs-class-firmware-attributes | 18 +- drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/think-lmi.c | 884 ++++++++++++++++++ drivers/platform/x86/think-lmi.h | 80 ++ 5 files changed, 993 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/x86/think-lmi.c create mode 100644 drivers/platform/x86/think-lmi.h
Documentation/ABI/testing/sysfs-class-firmware-attributes +17 -1
@@ -197,8 +197,24 @@ Description: Drivers may emit a CHANGE uevent when a password is set or unset userspace may check it again. - On Dell systems, if Admin password is set, then all BIOS attributes + On Dell and Lenovo systems, if Admin password is set, then all BIOS attributes require password validation. + On Lenovo systems if you change the Admin password the new password is not active until + the next boot. + + Lenovo specific class extensions + ------------------------------ + + On Lenovo systems the following additional settings are available: + + lenovo_encoding: + The encoding method that is used. This can be either "ascii" + or "scancode". Default is set to "ascii" + + lenovo_kbdlang: + The keyboard language method that is used. This is generally a + two char code (e.g. "us", "fr", "gr") and may vary per platform. + Default is set to "us" What: /sys/class/firmware-attributes/*/attributes/pending_reboot Date: February 2021
drivers/platform/x86/Kconfig +11 -0
@@ -639,6 +639,17 @@ config THINKPAD_ACPI_HOTKEY_POLL If you are not sure, say Y here. The driver enables polling only if it is strictly necessary to do so. +config THINKPAD_LMI + tristate "Lenovo WMI-based systems management driver" + depends on ACPI_WMI + select FW_ATTR_CLASS + help + This driver allows changing BIOS settings on Lenovo machines whose + BIOS support the WMI interface. + + To compile this driver as a module, choose M here: the module will + be called think-lmi. + config INTEL_ATOMISP2_LED tristate "Intel AtomISP2 camera LED driver" depends on GPIOLIB && LEDS_GPIO
drivers/platform/x86/Makefile +1 -0
@@ -64,6 +64,7 @@ obj-$(CONFIG_IBM_RTL) += ibm_rtl.o obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o +obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o # Intel obj-$(CONFIG_INTEL_ATOMISP2_LED) += intel_atomisp2_led.o
drivers/platform/x86/think-lmi.c new file +884 -0
884 lines not on this page · raw message
drivers/platform/x86/think-lmi.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.31.1
Hi Mark, Andy,
Overall this looks pretty good. There are a few very small issues remaining, but they are so small that I've decided to fix them up and merge this into my review-hans branch with the issues fixed up.
I plan to let this sit in review-hans a bit longer then usual to give you (Mark) a chance to check out the changes and ack them and to give Andy the time to check if his review remarks were addressed to his liking.
I've put remarks inline / below about the few things which I've fixed up in this patch. I'll also reply to patch 3/3 with the fixups which I've done there.
Quoted 30 lines · Mark Pearson
This will be used by the Dell and Lenovo WMI management drivers to prevent both drivers being active.
Signed-off-by Mark Pearson <[email protected]>---
Changes in v2:
- This is a new file requested as part of the review of the proposedthink_lmi.cdriver. Labeling as V2 to keep series consistentChanges in v3:
- Set default inKconfig, and removed help text
- Allow multiple modules to register with module. Change API names to better reflect this.Changes in v4:
- version bump for consistency in seriesdrivers/platform/x86/Kconfig | 4 ++ drivers/platform/x86/Makefile | 1 + .../platform/x86/firmware_attributes_class.c | 53 +++++++++++++++++++ .../platform/x86/firmware_attributes_class.h | 13 +++++ 4 files changed, 71 insertions(+) create mode 100644 drivers/platform/x86/firmware_attributes_class.c create mode 100644 drivers/platform/x86/firmware_attributes_class.hdrivers/platform/x86/Kconfig +0
-0
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1080
Quoted 5 lines
drivers/platform/x86/Kconfig +2
-0@@ -1076,6 +1076,10 @@ config TOUCHSCREEN_DMI the OS-image for the device. This option supplies the missing info. Enable this for x86 tablets with Silead or Chipone touchscreens. +config FW_ATTR_CLASS + tristate "Firmware attributes class helper module"
This should be just " tristate" adding a string after the "tristate"
makes this user selectable, I've dropped the string.
Quoted 10 lines
drivers/platform/x86/Kconfig +2
-0+ default n + config INTEL_IMR bool "Intel Isolated Memory Region support" depends on X86_INTEL_QUARK && IOSF_MBIdrivers/platform/x86/Makefile +0
-0
drivers/platform/x86/Makefile obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o · line 118
Quoted 4 lines
drivers/platform/x86/Makefile +1
-0@@ -115,6 +115,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o +obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.o
This was using spaces instead of tabs for indent before the += and
it did not apply because of the "platform/x86: Rename hp-wireless to wireless-hotkey" patch in review-hans.
drivers/platform/x86/firmware_attributes_class.c
Quoted 7 lines
drivers/platform/x86/Makefile +0
-0# Intel uncore drivers obj-$(CONFIG_INTEL_IPS) += intel_ips.odrivers/platform/x86/firmware_attributes_class.c new file +0
-0
This file had a couple of trailing empty lines which I've stripped.
drivers/platform/x86/firmware_attributes_class.h
Quoted 2 lines
drivers/platform/x86/firmware_attributes_class.h new file +0
-0
Idem, and also the same for think-lmi.c from patch 3/3.
Regards,
Hans
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Mark PearsonHi Mark, Andy,
So as mentioned in my reply to patch 1/3, overall this looks pretty good. There are a few very small issues remaining, but they are so small that I've decided to fix them up and merge this into my review-hans branch with the issues fixed up.
I plan to let this sit in review-hans a bit longer then usual to give you (Mark) a chance to check out the changes and ack them and to give Andy the time to check if his review remarks were addressed to his liking.
I've put remarks inline / below about the 2 things which I've fixed up in this patch.
Andy, thank you for your review of this. Your suggestions have improved this driver, esp. the use of kasprintf has made some of the functions a lot better.
On 5/26/21 10:14 PM, Mark Pearson wrote:
<snip>
drivers/platform/x86/think-lmi.c line 156
Quoted 10 lines
drivers/platform/x86/think-lmi.c new file +10
-0+/* Extract error string from WMI return buffer */ +static int tlmi_extract_error (const struct acpi_buffer *output) +{ +const union acpi_object *obj; + + obj = output->pointer; +if (!obj) +return -ENOMEM ; +if (obj->type !=ACPI_TYPE_STRING || !obj->string.pointer) { +kfree (obj);
This kfree() should not be here, all the callers of tlmi_extract_error() unconditionally call:
kfree(output->pointer);
after calling tlmi_extract_error() so if hit this path with the kfree(obj) in place we get a double free.
I've dropped the kfree() in my review-hans branch, as well as the now no longer necessary {}.
Quoted 37 lines
drivers/platform/x86/think-lmi.c new file +37
-0+return -EIO ; + } +return tlmi_errstr_to_err (obj->string.pointer); +} + +/* Utility function to execute WMI call to BIOS */ +static int tlmi_simple_call (const char *guid,const char *arg) +{ +const struct acpi_buffer input = {strlen (arg), (char *)arg }; +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +acpi_status status; +int i, err; + +/* +* Duplicated call required to match bios workaround for behavior +* seen when WMI accessed via scripting on other OS. +*/ +for (i =0 ; i <2 ; i++) { +/* (re)initialize output buffer to default state */ + output.length =ACPI_ALLOCATE_BUFFER ; + output.pointer =NULL ; + + status =wmi_evaluate_method (guid,0 ,0 , &input, &output); +if (ACPI_FAILURE (status)) { +kfree (output.pointer); +return -EIO ; + } + err =tlmi_extract_error (&output); +kfree (output.pointer); +if (err) +return err; + } +return 0 ; +} + +/* Extract output string from WMI return buffer */ +static int tlmi_extract_output_string(const struct acpi_buffer *output,
drivers/platform/x86/think-lmi.c line 203
Quoted 10 lines
drivers/platform/x86/think-lmi.c new file +10
-0+ char **string) +{ +const union acpi_object *obj; +char *s; + + obj = output->pointer; +if (!obj) +return -ENOMEM ; +if (obj->type !=ACPI_TYPE_STRING || !obj->string.pointer) { +kfree (obj);
Same as above, also fixed in the same way.
drivers/platform/x86/think-lmi.c line 214
Quoted 11 lines
drivers/platform/x86/think-lmi.c new file +11
-0+return -EIO ; + } + + s =kstrdup (obj->string.pointer,GFP_KERNEL ); +if (!s) +return -ENOMEM ; + *string = s; +return 0 ; +} + +/* ------ Core interface functions ------------*/
Regards,
Hans
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Mark PearsonHi again,
Quoted 5 lines · Mark Pearson
For Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
Signed-off-by Mark Pearson <[email protected]>
Mark, checkpatch.pl is complaining about this patch not adding a MAINTAINERS entry for the think-lmi driver, can you please do a follow-up patch adding a MAINTAINERS entry for this?
Regards,
Hans
Re: [External] Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Hans de GoedeThanks Hans
Quoted 11 lines · Hans de Goede
Hi Mark, Andy,
So as mentioned in my reply to patch 1/3, overall this looks pretty good. There are a few very small issues remaining, but they are so small that I've decided to fix them up and merge this into my review-hans branch with the issues fixed up.
I plan to let this sit in review-hans a bit longer then usual to give you (Mark) a chance to check out the changes and ack them and to give Andy the time to check if his review remarks were addressed to his liking.
Sounds good to me.
Quoted 7 lines
I've put remarks inline / below about the 2 things which I've fixed up in this patch.
Andy, thank you for your review of this. Your suggestions have improved this driver, esp. the use of kasprintf has made some of the functions a lot better.
Seconded :)
Thank you to both of you for the reviews - I learnt a lot with this particular patch set.
Quoted 19 lines · Mark Pearson
<snip>
drivers/platform/x86/think-lmi.c line 156
Quoted 10 lines
drivers/platform/x86/think-lmi.c new file +10
-0+/* Extract error string from WMI return buffer */ +static int tlmi_extract_error (const struct acpi_buffer *output) +{ +const union acpi_object *obj; + + obj = output->pointer; +if (!obj) +return -ENOMEM ; +if (obj->type !=ACPI_TYPE_STRING || !obj->string.pointer) { +kfree (obj);This
kfree()should not be here, all the callers oftlmi_extract_error()unconditionally call:
Quoted 7 lines
kfree(output->pointer);after calling
tlmi_extract_error()so if hit this path with the kfree(obj) in place we get a double free.I've dropped the
kfree()in my review-hans branch, as well as the now no longer necessary {}.
Agreed - I should have noticed that one. Thanks
Quoted 42 lines
Quoted 42 lines
drivers/platform/x86/think-lmi.c new file +41
-0+return -EIO ; + } +return tlmi_errstr_to_err (obj->string.pointer); +} + +/* Utility function to execute WMI call to BIOS */ +static int tlmi_simple_call (const char *guid,const char *arg) +{ +const struct acpi_buffer input = {strlen (arg), (char *)arg }; +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +acpi_status status; +int i, err; + +/* +* Duplicated call required to match bios workaround for behavior +* seen when WMI accessed via scripting on other OS. +*/ +for (i =0 ; i <2 ; i++) { +/* (re)initialize output buffer to default state */ + output.length =ACPI_ALLOCATE_BUFFER ; + output.pointer =NULL ; + + status =wmi_evaluate_method (guid,0 ,0 , &input, &output); +if (ACPI_FAILURE (status)) { +kfree (output.pointer); +return -EIO ; + } + err =tlmi_extract_error (&output); +kfree (output.pointer); +if (err) +return err; + } +return 0 ; +} + +/* Extract output string from WMI return buffer */ +static int tlmi_extract_output_string (const struct acpi_buffer *output, +char **string) +{ +const union acpi_object *obj; +char *s;
Quoted 8 lines
drivers/platform/x86/think-lmi.c line 156
Quoted 6 lines
drivers/platform/x86/think-lmi.c new file +6
-0+ + obj = output->pointer; +if (!obj) +return -ENOMEM ; +if (obj->type !=ACPI_TYPE_STRING || !obj->string.pointer) { +kfree (obj);Same as above, also fixed in the same way.
Thanks
Quoted 13 lines
drivers/platform/x86/think-lmi.c line 214
Quoted 12 lines
drivers/platform/x86/think-lmi.c new file +11
-0+return -EIO ; + } + + s =kstrdup (obj->string.pointer,GFP_KERNEL ); +if (!s) +return -ENOMEM ; + *string = s; +return 0 ; +} + +/* ------ Core interface functions ------------*/
Mark
Re: [External] Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Hans de GoedeQuoted 7 lines · Hans de Goede
Hi again,
Quoted 4 lines · Mark Pearson
For Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
Quoted 6 lines
Quoted 1 line
Signed-off-by Mark Pearson <[email protected]>Mark, checkpatch.pl is complaining about this patch not adding a
MAINTAINERSentry for the think-lmi driver, can you please do a follow-up patch adding aMAINTAINERSentry for this?
Will do.
Mark
Thanks Hans
Quoted 49 lines · Hans de Goede
Hi Mark, Andy,
Overall this looks pretty good. There are a few very small issues remaining, but they are so small that I've decided to fix them up and merge this into my review-hans branch with the issues fixed up.
I plan to let this sit in review-hans a bit longer then usual to give you (Mark) a chance to check out the changes and ack them and to give Andy the time to check if his review remarks were addressed to his liking.
I've put remarks inline / below about the few things which I've fixed up in this patch. I'll also reply to patch 3/3 with the fixups which I've done there.
Quoted 33 lines · Mark Pearson
This will be used by the Dell and Lenovo WMI management drivers to prevent both drivers being active.
Signed-off-by Mark Pearson <[email protected]>---
Changes in v2:
- This is a new file requested as part of the review of the proposedthink_lmi.cdriver. Labeling as V2 to keep series consistentChanges in v3:
- Set default inKconfig, and removed help text
- Allow multiple modules to register with module. Change API names to better reflect this.Changes in v4:
- version bump for consistency in seriesdrivers/platform/x86/Kconfig | 4 ++ drivers/platform/x86/Makefile | 1 + .../platform/x86/firmware_attributes_class.c | 53 +++++++++++++++++++ .../platform/x86/firmware_attributes_class.h | 13 +++++ 4 files changed, 71 insertions(+) create mode 100644 drivers/platform/x86/firmware_attributes_class.c create mode 100644 drivers/platform/x86/firmware_attributes_class.hdrivers/platform/x86/Kconfig +0
-0@@ -1076,6 +1076,10 @@ config TOUCHSCREEN_DMI the OS-image for the device. This option supplies the missing info. Enable this for x86 tablets with Silead or Chipone touchscreens.
Quoted 5 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1080
Quoted 2 lines
drivers/platform/x86/Kconfig +2
-0+config FW_ATTR_CLASS + tristate "Firmware attributes class helper module"This should be just " tristate" adding a string after the "tristate"
makes this user selectable, I've dropped the string.
Ah - my bad. Thanks for fixing.
Quoted 11 lines
Quoted 11 lines
drivers/platform/x86/Kconfig +2
-0+ default n + config INTEL_IMR bool "Intel Isolated Memory Region support" depends on X86_INTEL_QUARK && IOSF_MBIdrivers/platform/x86/Makefile +0
-0@@ -115,6 +115,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o
Quoted 8 lines
drivers/platform/x86/Makefile obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o · line 118
Quoted 4 lines
drivers/platform/x86/Makefile +1
-0obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o +obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.oThis was using spaces instead of tabs for indent before the += and
it did not apply because of the "platform/x86: Rename hp-wireless to wireless-hotkey" patch in review-hans.
Ack.
Quoted 11 lines
drivers/platform/x86/firmware_attributes_class.c
Quoted 9 lines
drivers/platform/x86/Makefile +0
-0# Intel uncore drivers obj-$(CONFIG_INTEL_IPS) += intel_ips.odrivers/platform/x86/firmware_attributes_class.c new file +0
-0This file had a couple of trailing empty lines which I've stripped.
Ack - sorry I missed those.
Quoted 9 lines
drivers/platform/x86/firmware_attributes_class.h
Quoted 3 lines
drivers/platform/x86/firmware_attributes_class.h new file +0
-0Idem, and also the same for
think-lmi.cfrom patch 3/3> Regards,Hans
Mark
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Mark PearsonQuoted 4 lines · Mark Pearson
For Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
Thanks for an update! My comments below.
...
Quoted 2 lines
+/*
+ *think-lmi.c- Think LMI BIOS configuration driver
It's not the best idea to include the file name into the file. If the file gets renamed (by whatever reason) often this either brings an additional burden or simply forgotten (as from my experience). I recommend to drop the file names from the source code.
Quoted 6 lines
+ * Copyright(C) 2019-2021 Lenovo
+ *
+ * Original code from Thinkpad-wmi project https://github.com/iksaif/thinkpad-wmi
+ * Copyright(C) 2017 Corentin Chary <[email protected]>
+ * Distributed under the GPL-2.0 license
+ */
...
Quoted 1 line
+#include <
linux/acpi.h>
linux/errno.h ?
Quoted 1 line
+#include <
linux/fs.h>
linux/string.h ?linux/types.h ?
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+#include <linux/wmi.h> +#include "firmware_attributes_class.h" +#include "think-lmi.h"
...
Quoted 6 lines
+ * Type:
+ * Method
+ * Arguments:
+ * "Item,Value,Password,Encoding,KbdLang;"
+ * Example:
+ * "WakeOnLAN,Disable,pswd,ascii,us;"
Is 'pswd' here an example of the password? Hacker's language can make it more visible, e.g. 'pa55w0rd'.
Same for other examples.
Quoted 1 line
+ */
...
drivers/platform/x86/think-lmi.c line 171
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* +* Duplicated call required to match bios workaround for behavior
bios -> BIOS
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+* seen when WMI accessed via scripting on other OS. +*/
...
Quoted 1 line
+ struct
tlmi_pwd_setting*setting =container_of(kobj, struct tlmi_pwd_setting, kobj);
Candidate to have something like
#define to_tlmi_pwd_setting(obj) container_of(...)
since it has appeared a few times.
drivers/platform/x86/think-lmi.c line 304
Quoted 4 lines
drivers/platform/x86/think-lmi.c new file +3
-0+return sysfs_emit (buf,"%d\n" , setting->valid); +} +
Unneeded blank line. Same for other similar places.
Quoted 1 line
+static struct
kobj_attributeauth_is_pass_set=__ATTR_RO(is_enabled);
Hmm... We have already define_one_global_ro(). The problems with that are the name and location. But perhaps you can copy that macro here with the same name and at least we can see the common grounds to clean up in the future. Another possibility is to comment that it can be replaced with the above mentioned macro. Ideally would be to refactor right now, but it's not anyhow crucial or required for this series, so may be postponed.
...
Quoted 1 line
+ int pwdlen;
Strictly speaking it should be size_t.
drivers/platform/x86/think-lmi.c line 316
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (buf); +if (buf[pwdlen-1 ] =='\n' ) + pwdlen--;
But the question is what will happen with the string like 'pa55\nw0rd\n' (note all \n:s)?
See also below.
drivers/platform/x86/think-lmi.c line 319
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* pwdlen == 0 is allowed to clear the password */ +if (pwdlen !=0 && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))
The ' != 0' part is redundant.
drivers/platform/x86/think-lmi.c line 323
Quoted 4 lines
drivers/platform/x86/think-lmi.c new file +3
-0+return -EINVAL ; +memcpy (setting->password, buf, pwdlen); + setting->password[pwdlen] ='\0' ;
I'm not sure why we can't use strscpy() like you did in the other function.
Quoted 1 line
+ return count;
...
drivers/platform/x86/think-lmi.c line 349
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Strip out CR if one is present, setting password won't work if it is present */ +strreplace (new_pwd,'\n' ,'\0' );
Basically it will stop on the first one. See the strchrnul() trick below.
drivers/platform/x86/think-lmi.c line 353
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (new_pwd); +/* pwdlen == 0 is allowed to clear the password */ +if (pwdlen !=0 && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen))) {
No need for ' != 0'.
Quoted 5 lines
drivers/platform/x86/think-lmi.c new file +4
-0+ ret = -EINVAL ; + goto out; + } +}
...
drivers/platform/x86/think-lmi.c line 451
Quoted 12 lines
drivers/platform/x86/think-lmi.c new file +12
-0+int length; + + length =strlen (buf); +if (buf[length-1 ] =='\n' ) + length--; + +if (!length || (length >=TLMI_LANG_MAXLEN )) +return -EINVAL ; + +memcpy (setting->kbdlang, buf, length); + setting->kbdlang[length] ='\0' ; +return count;
Similar comments as per above.
...
drivers/platform/x86/think-lmi.c line 522
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+char *set_str =NULL , *new_setting =NULL ; +char *auth_str =NULL ;
The rule of thumb is to avoid forward assignments on stack allocated variables. It may decrease readability, hide real issues, and simply be unneeded churn, like here. Please revisit all of them in entire series.
...
drivers/platform/x86/think-lmi.c line 533
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Strip out CR if one is present */ +strreplace (new_setting,'\n' ,'\0' );
As per above.
...
drivers/platform/x86/think-lmi.c line 782
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Remove the value part */ +strreplace (item,',' ,'\0' );
This is kinda non-standard pattern.
I would see rather something like
char *p;
p = strchrnul(item, ',');
*p = '\0';
Yes, it's longer, but better to understand what's going on here.
drivers/platform/x86/think-lmi.c line 785
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Create a setting entry */ + setting =kzalloc (sizeof (struct tlmi_attr_setting ),GFP_KERNEL );
sizeof(*setting) ?
Quoted 6 lines
drivers/platform/x86/think-lmi.c new file +6
-0+if (!setting) { + ret = -ENOMEM ; + goto fail_clear_attr; + } + setting->index = i; +strscpy (setting->display_name, item,TLMI_SETTINGS_MAXLEN );
...
drivers/platform/x86/think-lmi.c line 816
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+sprintf (tlmi_priv.pwd_admin->display_name,"admin" ); +sprintf (tlmi_priv.pwd_admin->kbdlang,"us" );
Not sure why you need printf() type of function here. strcpy() or strscpy() should be enough.
...
drivers/platform/x86/think-lmi.c line 822
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+if (WARN_ON (pwdcfg.max_length >=TLMI_PWD_BUFSIZE )) + pwdcfg.max_length =TLMI_PWD_BUFSIZE -1 ;
Not sure if WARN_ON() is really what has to be called here. But I haven't checked the context deeply.
...
drivers/platform/x86/think-lmi.c line 833
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+sprintf (tlmi_priv.pwd_power->display_name,"power-on" ); +sprintf (tlmi_priv.pwd_power->kbdlang,"us" );
As above.
...
drivers/platform/x86/think-lmi.h line 4
Quoted 2 lines
drivers/platform/x86/think-lmi.h new file +2
-0+#ifndef _THINK_LMI_H_ +#define _THINK_LMI_H_
+ linux/types.h
(At leas bool is from there)
Quoted 1 line
+#endif /* !_THINK_LMI_H_ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Hans de GoedeQuoted 8 lines · Hans de Goede
Hi Mark, Andy,
So as mentioned in my reply to patch 1/3, overall this looks pretty good. There are a few very small issues remaining, but they are so small that I've decided to fix them up and merge this into my review-hans branch with the issues fixed up.
Quoted 4 lines
I plan to let this sit in review-hans a bit longer then usual to give you (Mark) a chance to check out the changes and ack them and to give Andy the time to check if his review remarks were addressed to his liking.
I looked into it again and commented on some stuff, but nothing serious noted, so I think the next version would be ready to go.
Quoted 6 lines
I've put remarks inline / below about the 2 things which I've fixed up in this patch.
Andy, thank you for your review of this. Your suggestions have improved this driver, esp. the use of kasprintf has made some of the functions a lot better.
You are welcome!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Andy ShevchenkoHi,
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Mark Pearson
For Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
Thanks for an update! My comments below.
Since you have more remarks then I anticipated I guess it is best if I drop v4 from my review-hans branch and Mark does a v5.
Mark, you can then also just squash the addition of the MAINTAINERS entry into v5.
<snip>
Quoted 11 lines
Quoted 1 line
+ int pwdlen;
Strictly speaking it should be
size_t.drivers/platform/x86/think-lmi.c line 316
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (buf); +if (buf[pwdlen-1 ] =='\n' ) + pwdlen--;But the question is what will happen with the string like 'pa55\nw0rd\n' (note all \n:s)?
See also below.
As I already explained in a previous reply the password cannot contain '\n' so this cannot happen. I did miss that this was still there, where as new_password_store() uses strreplace() which is not really consistent with each other...
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 522
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+char *set_str =NULL , *new_setting =NULL ; +char *auth_str =NULL ;The rule of thumb is to avoid forward assignments on stack allocated variables. It may decrease readability, hide real issues, and simply be unneeded churn, like here. Please revisit all of them in entire series.
I asked for all this to be set to NULL in my review of v2, since there are various "goto out"s in the function and out:
calls kfree() on all 3, in v2 there was a path which would end up calling kfree() on an uninitialized char *. IMHO just initializing all of them up front is best here because that guarantees that they are either still NULL, or point to memory returned by kmalloc.
Quoted 5 lines
drivers/platform/x86/think-lmi.c line 782
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Remove the value part */ +strreplace (item,',' ,'\0' );This is kinda non-standard pattern.
Quoted 8 lines
I would see rather something like
char *p;
p =
strchrnul(item, ',');
*p = '\0';Yes, it's longer, but better to understand what's going on here.
Erm, you actually suggested using strreplace() here in your previous review ...
Quoted 5 lines
drivers/platform/x86/think-lmi.c line 822
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+if (WARN_ON (pwdcfg.max_length >=TLMI_PWD_BUFSIZE )) + pwdcfg.max_length =TLMI_PWD_BUFSIZE -1 ;Not sure if
WARN_ON()is really what has to be called here. But I haven't checked the context deeply.
There are 2 max_lengths, one hardcoded in the driver so we don't need to dynamically manage memory for the password storage and one which is actually queried from the BIOS, the BIOS max-length should always be less then the hardcoded one in the driver (and currently this is true for all known models).
I suggested adding the WARN_ON so that if future BIOS-es ever bump max_length we will get a bug-report about this and then we can bump the driver's TLMI_PWD_BUFSIZE value.
Regards,
Hans
Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Wed, May 26, 2021 at 11:15 PM Mark Pearson <[email protected]> wrote:
...
Quoted 8 lines
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 522
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+char *set_str =NULL , *new_setting =NULL ; +char *auth_str =NULL ;The rule of thumb is to avoid forward assignments on stack allocated variables. It may decrease readability, hide real issues, and simply be unneeded churn, like here. Please revisit all of them in entire series.
Quoted 7 lines
I asked for all this to be set to NULL in my review of v2, since there are various "goto out"s in the function and out:
callskfree()on all 3, in v2 there was a path which would end up callingkfree()on an uninitialized char *. IMHO just initializing all of them up front is best here because that guarantees that they are either still NULL, or point to memory returned by kmalloc.
I see your point, fine with me!
...
Quoted 7 lines
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 782
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Remove the value part */ +strreplace (item,',' ,'\0' );This is kinda non-standard pattern.
I would see rather something like
Quoted 8 lines
Quoted 6 lines
char *p;
p =
strchrnul(item, ',');
*p = '\0';Yes, it's longer, but better to understand what's going on here.
Erm, you actually suggested using
strreplace()here in your previous review ...
There is strreplace() in use somewhere still which is what I suggested. It might be that I missed the fact that in some places the change happens to the ''\0' rather than another non-NUL character.
So, strreplace() is basically for changing '$a' to '$b' where neither of them is NUL.
Otherwise we have
- strsep()
- strchrnul()
- strtrim()
depending on the case.
Sorry if I was not completely clear about something.
...
Quoted 12 lines
Quoted 5 lines
drivers/platform/x86/think-lmi.c line 822
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+if (WARN_ON (pwdcfg.max_length >=TLMI_PWD_BUFSIZE )) + pwdcfg.max_length =TLMI_PWD_BUFSIZE -1 ;Not sure if
WARN_ON()is really what has to be called here. But I haven't checked the context deeply.There are 2
max_lengths, one hardcoded in the driver so we don't need to dynamically manage memory for the password storage and one which is actually queried from the BIOS, the BIOS max-length should always be less then the hardcoded one in the driver (and currently this is true for all known models).
Quoted 3 lines
I suggested adding the
WARN_ONso that if future BIOS-es ever bumpmax_lengthwe will get a bug-report about this and then we can bump the driver'sTLMI_PWD_BUFSIZEvalue.
I see your point, thanks for elaboration.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [External] Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
In reply to Andy ShevchenkoHi Andy,
Quoted 10 lines · Andy Shevchenko
Quoted 4 lines · Mark Pearson
For Lenovo platforms that support a WMI interface to the BIOS add support, using the firmware-attributes class, to allow users to access and modify various BIOS related settings.
Thanks for an update! My comments below.
...
Quoted 7 lines
Quoted 2 lines
+/*
+ *think-lmi.c- Think LMI BIOS configuration driverIt's not the best idea to include the file name into the file. If the file gets renamed (by whatever reason) often this either brings an additional burden or simply forgotten (as from my experience). I recommend to drop the file names from the source code.
Good advice - I'll update
Quoted 14 lines
Quoted 7 lines
+ * Copyright(C) 2019-2021 Lenovo
+ *
+ * Original code from Thinkpad-wmi project https://github.com/iksaif/thinkpad-wmi
+ * Copyright(C) 2017 Corentin Chary <[email protected]>
+ * Distributed under the GPL-2.0 license
+ */...
Quoted 1 line
+#include <
linux/acpi.h>
linux/errno.h?
Quoted 8 lines
Quoted 1 line
+#include <
linux/fs.h>
linux/string.h?linux/types.h?drivers/platform/x86/think-lmi.c line 18
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+#include <linux/wmi.h> +#include "firmware_attributes_class.h" +#include "think-lmi.h"
I hadn't included those as they call get pulled in by linux/acpi.h - so aren't needed here. I take it best practice is to add them. I'd deliberately stripped down the list to the bare minimu previously but happy to reverse that if it's preferred.
Quoted 10 lines
...
Quoted 6 lines
+ * Type:
+ * Method
+ * Arguments:
+ * "Item,Value,Password,Encoding,KbdLang;"
+ * Example:
+ * "WakeOnLAN,Disable,pswd,ascii,us;"
Quoted 3 lines
Is 'pswd' here an example of the password? Hacker's language can make it more visible, e.g. 'pa55w0rd'.
Same for other examples.
Yes it is. I can update that :)
Quoted 9 lines
Quoted 2 lines
+ */
...
drivers/platform/x86/think-lmi.c line 171
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* +* Duplicated call required to match bios workaround for behavior bios -> BIOS
Ack
Quoted 6 lines
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +2
-0+* seen when WMI accessed via scripting on other OS. +*/ ...
Quoted 7 lines
Quoted 1 line
+ struct
tlmi_pwd_setting*setting =container_of(kobj, struct tlmi_pwd_setting, kobj);Candidate to have something like
#define
to_tlmi_pwd_setting(obj)container_of(...)since it has appeared a few times.
Ack
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 304
Quoted 5 lines
drivers/platform/x86/think-lmi.c new file +3
-0+return sysfs_emit (buf,"%d\n" , setting->valid); +} +Unneeded blank line. Same for other similar places.
Shoot - I thought I'd cleaned a bunch of these up. I'll do another pass.
Quoted 10 lines
Quoted 2 lines
+static struct
kobj_attributeauth_is_pass_set=__ATTR_RO(is_enabled);Hmm... We have already
define_one_global_ro(). The problems with that are the name and location. But perhaps you can copy that macro here with the same name and at least we can see the common grounds to clean up in the future. Another possibility is to comment that it can be replaced with the above mentioned macro. Ideally would be to refactor right now, but it's not anyhow crucial or required for this series, so may be postponed.
OK - I'll have a look. I'm not 100% sure I understand the issues, but hopefully it will become clearer once I play with it a bit
Quoted 7 lines
...
Quoted 1 line
+ int pwdlen;
Strictly speaking it should be
size_t.
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 316
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (buf); +if (buf[pwdlen-1 ] =='\n' ) + pwdlen--;But the question is what will happen with the string like 'pa55\nw0rd\n' (note all \n:s)?
See also below.
I know there is discussion on this in future mails, so I'll leave this one for those
Quoted 5 lines
drivers/platform/x86/think-lmi.c line 319
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* pwdlen == 0 is allowed to clear the password */ +if (pwdlen !=0 && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))The ' != 0' part is redundant.
Ack
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 323
Quoted 5 lines
drivers/platform/x86/think-lmi.c new file +3
-0+return -EINVAL ; +memcpy (setting->password, buf, pwdlen); + setting->password[pwdlen] ='\0' ;I'm not sure why we can't use
strscpy()like you did in the other function.
I'm not sure either :) I'll update
Quoted 9 lines
Quoted 2 lines
+ return count;
...
drivers/platform/x86/think-lmi.c line 349
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Strip out CR if one is present, setting password won't work if it is present */ +strreplace (new_pwd,'\n' ,'\0' );Basically it will stop on the first one. See the
strchrnul()trick below.
Thanks for the strchrnul trick - happy to use that
Quoted 6 lines
drivers/platform/x86/think-lmi.c line 353
Quoted 4 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (new_pwd); +/* pwdlen == 0 is allowed to clear the password */ +if (pwdlen !=0 && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen))) {No need for ' != 0'.
Ack
Quoted 10 lines
Quoted 6 lines
drivers/platform/x86/think-lmi.c new file +4
-0+ ret = -EINVAL ; + goto out; + } +}...
Quoted 14 lines
drivers/platform/x86/think-lmi.c line 451
Quoted 12 lines
drivers/platform/x86/think-lmi.c new file +12
-0+int length; + + length =strlen (buf); +if (buf[length-1 ] =='\n' ) + length--; + +if (!length || (length >=TLMI_LANG_MAXLEN )) +return -EINVAL ; + +memcpy (setting->kbdlang, buf, length); + setting->kbdlang[length] ='\0' ; +return count;Similar comments as per above.
Ack
Quoted 10 lines
...
drivers/platform/x86/think-lmi.c line 522
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+char *set_str =NULL , *new_setting =NULL ; +char *auth_str =NULL ;The rule of thumb is to avoid forward assignments on stack allocated variables. It may decrease readability, hide real issues, and simply be unneeded churn, like here. Please revisit all of them in entire series.
Covered in Hans reply. Leaving as is
Quoted 15 lines
...
drivers/platform/x86/think-lmi.c line 533
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Strip out CR if one is present */ +strreplace (new_setting,'\n' ,'\0' );As per above.
...
drivers/platform/x86/think-lmi.c line 782
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Remove the value part */ +strreplace (item,',' ,'\0' );This is kinda non-standard pattern.
Quoted 8 lines
I would see rather something like
char *p;
p =
strchrnul(item, ',');
*p = '\0';Yes, it's longer, but better to understand what's going on here.
Fair enough. I'll change. I quite liked the fact I had a one-liner do the same thing - oh well :)
Quoted 5 lines
drivers/platform/x86/think-lmi.c line 785
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Create a setting entry */ + setting =kzalloc (sizeof (struct tlmi_attr_setting ),GFP_KERNEL );
sizeof(*setting)?
OK.
Quoted 8 lines
drivers/platform/x86/think-lmi.c line 791
Quoted 7 lines
drivers/platform/x86/think-lmi.c new file +6
-0+if (!setting) { + ret = -ENOMEM ; + goto fail_clear_attr; + } + setting->index = i; +strscpy (setting->display_name, item,TLMI_SETTINGS_MAXLEN );
Quoted 7 lines
...
drivers/platform/x86/think-lmi.c line 816
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+sprintf (tlmi_priv.pwd_admin->display_name,"admin" ); +sprintf (tlmi_priv.pwd_admin->kbdlang,"us" );Not sure why you need
printf()type of function here.strcpy()orstrscpy()should be enough.
OK - I can update.
Quoted 8 lines
...
drivers/platform/x86/think-lmi.c line 822
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+if (WARN_ON (pwdcfg.max_length >=TLMI_PWD_BUFSIZE )) + pwdcfg.max_length =TLMI_PWD_BUFSIZE -1 ;Not sure if
WARN_ON()is really what has to be called here. But I haven't checked the context deeply.
Covered in Hans' reply.. Leaving as is
Quoted 7 lines
...
drivers/platform/x86/think-lmi.c line 833
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+sprintf (tlmi_priv.pwd_power->display_name,"power-on" ); +sprintf (tlmi_priv.pwd_power->kbdlang,"us" );As above.
Ack
Quoted 9 lines
...
drivers/platform/x86/think-lmi.h line 4
Quoted 2 lines
drivers/platform/x86/think-lmi.h new file +2
-0+#ifndef _THINK_LMI_H_ +#define _THINK_LMI_H_+
linux/types.h(At leas bool is from there)
Ack
Quoted 4 lines
Quoted 3 lines
+#endif /* !_THINK_LMI_H_ */
Re: [External] Re: [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms
Quoted 2 lines · Mark Pearson
Quoted 1 line · Andy Shevchenko
On Wed, May 26, 2021 at 11:15 PM Mark Pearson <[email protected]> wrote:
...
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
+#include <
linux/acpi.h>
linux/errno.h?Quoted 1 line
+#include <
linux/fs.h>
linux/string.h?linux/types.h?
Quoted 8 lines
Quoted 3 lines
drivers/platform/x86/think-lmi.c line 18
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+#include <linux/wmi.h> +#include "firmware_attributes_class.h" +#include "think-lmi.h" I hadn't included those as they call get pulled in by
linux/acpi.h- so aren't needed here. I take it best practice is to add them. I'd deliberately stripped down the list to the bare minimu previously but happy to reverse that if it's preferred.
Basic headers like that are kinda what almost any file uses, but acpi.h is not the one which guarantees their inclusion (you see, it's a layering violation: acpi is not low level generic library).
...
Quoted 11 lines
Quoted 9 lines
Quoted 1 line
+static struct
kobj_attributeauth_is_pass_set=__ATTR_RO(is_enabled);Hmm... We have already
define_one_global_ro(). The problems with that are the name and location. But perhaps you can copy that macro here with the same name and at least we can see the common grounds to clean up in the future. Another possibility is to comment that it can be replaced with the above mentioned macro. Ideally would be to refactor right now, but it's not anyhow crucial or required for this series, so may be postponed.OK - I'll have a look. I'm not 100% sure I understand the issues, but hopefully it will become clearer once I play with it a bit
Including cpufreq.h in your code will seem weird. That's why I marked it as an issue.
...
Quoted 9 lines
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 316
Quoted 3 lines
drivers/platform/x86/think-lmi.c new file +3
-0+ pwdlen =strlen (buf); +if (buf[pwdlen-1 ] =='\n' ) + pwdlen--;But the question is what will happen with the string like 'pa55\nw0rd\n' (note all \n:s)?
See also below.I know there is discussion on this in future mails, so I'll leave this one for those
OK.
...
Quoted 7 lines
Quoted 7 lines
drivers/platform/x86/think-lmi.c line 782
Quoted 2 lines
drivers/platform/x86/think-lmi.c new file +2
-0+/* Remove the value part */ +strreplace (item,',' ,'\0' );This is kinda non-standard pattern.
I would see rather something like
Quoted 8 lines
Quoted 6 lines
char *p;
p =
strchrnul(item, ',');
*p = '\0';Yes, it's longer, but better to understand what's going on here.
Fair enough. I'll change. I quite liked the fact I had a one-liner do the same thing - oh well :)
Me too, but the problem with strreplace(..., '\0') is that it sounds like a half-baked strsep() solution. First of all, it will go and replace all \n to \0 while you stop anyway on the first one in the following code.
Signature · 2 lines
With Best Regards, Andy Shevchenko