platform/x86: huawei-wmi: do not hard-code sizes
PATCH 1/3 platform/x86: huawei-wmi: do not hard-code sizes
Use sizeof() and ARRAY_SIZE() instead of
hard-coding buffer sizes and indices.
--- drivers/platform/x86/huawei-wmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/huawei-wmi.c +2 -2
@@ -323,12 +323,12 @@ static int huawei_wmi_battery_get(int *start, int *end)u8 ret[0x100 ];int err, i; - err =huawei_wmi_cmd (BATTERY_THRESH_GET , ret,0x100 ); + err =huawei_wmi_cmd (BATTERY_THRESH_GET , ret,sizeof (ret));if (err)return err;/* Find the last two non-zero values. Return status is ignored. */ - i =0xff ; + i =ARRAY_SIZE (ret) -1 ; do { if (start) *start = ret[i-1];
--
2.38.0
PATCH 2/3 platform/x86: huawei-wmi: fix return value calculation
Previously, huawei_wmi_input_setup() returned the result of logical or-ing the return values of two functions that return negative errno-style error codes and one that returns acpi_status. If this returned value was non-zero, then it was propagated from the platform driver's probe function. That function should return a negative errno-style error code, so the result of the logical or that huawei_wmi_input_setup() returned was not appropriate.
Fix that by checking each function separately and returning the error code unmodified.
--- drivers/platform/x86/huawei-wmi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/platform/x86/huawei-wmi.c +16 -4
@@ -760,6 +760,9 @@ static int huawei_wmi_input_setup(struct device *dev,const char *guid, struct input_dev **idev) { + acpi_status status; +int err; + *idev =devm_input_allocate_device (dev);if (!*idev)return -ENOMEM ;
@@ -769,10 +772,19 @@ static int huawei_wmi_input_setup(struct device *dev, (*idev)->id.bustype =BUS_HOST ; (*idev)->dev.parent = dev; -return sparse_keymap_setup (*idev, huawei_wmi_keymap,NULL ) || -input_register_device (*idev) || -wmi_install_notify_handler (guid, huawei_wmi_input_notify, - *idev); + err =sparse_keymap_setup (*idev, huawei_wmi_keymap,NULL ); +if (err) +return err; + + err =input_register_device (*idev); +if (err) +return err; + + status =wmi_install_notify_handler (guid, huawei_wmi_input_notify, *idev); +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; }static void huawei_wmi_input_exit (struct device *dev,const char *guid)
--
2.38.0
PATCH 3/3 platform/x86: huawei-wmi: remove unnecessary member
In reply to Barnabás PőczeThe huawei_wmi::idev array is not actually used by the driver, so remove it. The piece of code that - I believe - was supposed to fill the array is flawed, it did not actually set any of the values inside the array. This was most likely masked by the fact that the input devices are devm managed and that the only function that needs a reference to the input devices is huawei_wmi_input_notify(), however, that does not access the appropriate input device via the huawei_wmi object.
--- drivers/platform/x86/huawei-wmi.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/platform/x86/huawei-wmi.c +12 -17
@@ -63,7 +63,6 @@ struct huawei_wmi {bool fn_lock_available;struct huawei_wmi_debug debug; -struct input_dev *idev[2 ];struct led_classdev cdev;struct device *dev;
@@ -756,31 +755,30 @@ static void huawei_wmi_input_notify(u32 value, void *context)kfree (response.pointer); } -static int huawei_wmi_input_setup (struct device *dev, -const char *guid, -struct input_dev **idev) +static int huawei_wmi_input_setup (struct device *dev,const char *guid) { +struct input_dev *idev;acpi_status status;int err; - *idev =devm_input_allocate_device (dev); -if (!*idev) + idev =devm_input_allocate_device (dev); +if (!idev)return -ENOMEM ; - (*idev)->name ="Huawei WMI hotkeys" ; - (*idev)->phys ="wmi/input0" ; - (*idev)->id.bustype =BUS_HOST ; - (*idev)->dev.parent = dev; + idev->name ="Huawei WMI hotkeys" ; + idev->phys ="wmi/input0" ; + idev->id.bustype =BUS_HOST ; + idev->dev.parent = dev; - err =sparse_keymap_setup (*idev, huawei_wmi_keymap,NULL ); + err =sparse_keymap_setup (idev, huawei_wmi_keymap,NULL );if (err)return err; - err =input_register_device (*idev); + err =input_register_device (idev);if (err)return err; - status =wmi_install_notify_handler (guid, huawei_wmi_input_notify, *idev); + status =wmi_install_notify_handler (guid, huawei_wmi_input_notify, idev);if (ACPI_FAILURE (status))return -EIO ;
@@ -809,17 +807,14 @@ static int huawei_wmi_probe(struct platform_device *pdev) huawei_wmi->dev = &pdev->dev;while (*guid->guid_string) { -struct input_dev *idev = *huawei_wmi->idev; -if (wmi_has_guid (guid->guid_string)) { - err =huawei_wmi_input_setup (&pdev->dev, guid->guid_string, &idev); + err =huawei_wmi_input_setup (&pdev->dev, guid->guid_string);if (err) {dev_err (&pdev->dev,"Failed to setup input on %s\n" , guid->guid_string);return err; } } - idev++; guid++; }
--
2.38.0
Hi,
Quoted 4 lines · Barnabás Pőcze
Use
sizeof()andARRAY_SIZE()instead of
hard-coding buffer sizes and indices.Signed-off-by Barnabás Pőcze <[email protected]>
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 27 lines
--- drivers/platform/x86/huawei-wmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/platform/x86/huawei-wmi.c +2
-3@@ -323,12 +323,12 @@ static int huawei_wmi_battery_get(int *start, int *end)u8 ret[0x100 ];int err, i; - err =huawei_wmi_cmd (BATTERY_THRESH_GET , ret,0x100 ); + err =huawei_wmi_cmd (BATTERY_THRESH_GET , ret,sizeof (ret));if (err)return err;/* Find the last two non-zero values. Return status is ignored. */ - i =0xff ; + i =ARRAY_SIZE (ret) -1 ; do { if (start) *start = ret[i-1]; --2.38.0