diff mbox series

[v1,1/3] platform/x86: huawei-wmi: do not hard-code sizes

Message ID 20221005150032.173198-1-pobrn@protonmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [v1,1/3] platform/x86: huawei-wmi: do not hard-code sizes | expand

Commit Message

Barnabás Pőcze Oct. 5, 2022, 3 p.m. UTC
Use `sizeof()` and `ARRAY_SIZE()` instead of
hard-coding buffer sizes and indices.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
 drivers/platform/x86/huawei-wmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.38.0

Comments

Hans de Goede Oct. 24, 2022, 1:58 p.m. UTC | #1
Hi,

On 10/5/22 17:00, Barnabás Pőcze wrote:
> Use `sizeof()` and `ARRAY_SIZE()` instead of
> hard-coding buffer sizes and indices.
> 
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>

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


> ---
>  drivers/platform/x86/huawei-wmi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
> index eac3e6b4ea11..66b53b90188f 100644
> --- a/drivers/platform/x86/huawei-wmi.c
> +++ b/drivers/platform/x86/huawei-wmi.c
> @@ -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
> 
>
diff mbox series

Patch

diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index eac3e6b4ea11..66b53b90188f 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -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];