fujitsu-laptop: fix tests of acpi_evaluate_integer() return
Subsystems (3)
PATCH 5/12 fujitsu-laptop: fix tests of acpi_evaluate_integer() return
From: Roel Kluin <[email protected]>
The wrong test was used acpi_status status is unsigned.
---
drivers/platform/x86/fujitsu-laptop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +2 -2
@@ -376,7 +376,7 @@ static int get_lcd_level(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) +if (ACPI_FAILURE (status))return status; fujitsu->brightness_level = state &0x0fffffff ;
@@ -398,7 +398,7 @@ static int get_max_brightness(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"RBLL" ,NULL , &state); -if (status <0 ) +if (ACPI_FAILURE (status))return status; fujitsu->max_brightness = state;
_
Len Brown
reviewerQuoted 17 lines · On Tue, 17 Nov 2009, [email protected] wrote:
From: Roel Kluin <[email protected]>
The wrong test was used
acpi_statusstatus is unsigned.Signed-off-by Roel Kluin <[email protected]>Acked-by Jonathan Woithe <[email protected]>Cc Len Brown <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
drivers/platform/x86/fujitsu-laptop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)diff -puN
drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-returndrivers/platform/x86/fujitsu-laptop.c
drivers/platform/x86/fujitsu-laptop.c static int get_lcd_level(void) · line 380
Quoted 6 lines
drivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +1
-1@@ -376,7 +376,7 @@ static int get_lcd_level(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) +if (ACPI_FAILURE (status))return status;
as status is a positive number, shouldn't we be returning something like -1 here on failure, rather than status?
Quoted 13 lines
drivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +1
-1fujitsu->brightness_level = state &0x0fffffff ;@@ -398,7 +398,7 @@ static int get_max_brightness(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"RBLL" ,NULL , &state); -if (status <0 ) +if (ACPI_FAILURE (status))return status; fujitsu->max_brightness = state;_
Re: [patch 05/12] fujitsu-laptop: fix tests of acpi_evaluate_integer()
Quoted 18 lines
Quoted 18 lines
From: Roel Kluin <[email protected]>
The wrong test was used
acpi_statusstatus is unsigned.Signed-off-by Roel Kluin <[email protected]>Acked-by Jonathan Woithe <[email protected]>Cc Len Brown <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
drivers/platform/x86/fujitsu-laptop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)diff -puN
drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-returndrivers/platform/x86/fujitsu-laptop.cdrivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +0
-0@@ -376,7 +376,7 @@ static int get_lcd_level(void)
Quoted 8 lines
drivers/platform/x86/fujitsu-laptop.c static int get_lcd_level(void) · line 380
Quoted 5 lines
drivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +1
-1status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) +if (ACPI_FAILURE (status))return status;as status is a positive number, shouldn't we be returning something like -1 here on failure, rather than status?
These functions are called via the backlight_ops structure by the standard backlight class framework and it seems, from a real quick look, that the API treats numbers >=0 as valid data. So something like this (untested, off the top of my head) might be more appropriate:
drivers/platform/x86/fujitsu-laptop.c renamed from drivers/platform/x86/fujitsu-laptop.c~fujitsu-laptop-fix-tests-of-acpi_evaluate_integer-return +2 -2
@@ -376,7 +376,7 @@ static int get_lcd_level(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) +return -status; fujitsu->brightness_level = state &0x0fffffff ;
@@ -398,7 +398,7 @@ static int get_max_brightness(void)
status = acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state);
- if (status < 0)
- return status;
+ if (ACPI_FAILURE(status))
+ return -status;
fujitsu->max_brightness = state;
Otherwise "return -1;" would be fine by me. My only reason for going with "-status" is that it might give some clue as to what went wrong. Thoughts?
Regards
jonathan
Re: [patch 05/12] fujitsu-laptop: fix tests of acpi_evaluate_integer()
The wrong test was used, acpi_status status is unsigned. Callers expect an -errno on failure.
---
Quoted 21 lines
Quoted 8 lines
Review
Quoted 5 lines
The wrong test was used
acpi_statusstatus is unsigned.(quoted diff) +1
-1- if (status < 0) + if (ACPI_FAILURE(status)) return status;as status is a positive number, shouldn't we be returning something like -1 here on failure, rather than status?
These functions are called via the
backlight_opsstructure by the standard backlight class framework and it seems, from a real quick look, that the API treats numbers >=0 as valid data. So something like this (untested, off the top of my head) might be more appropriate:(quoted diff) +2
-2status = acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); - if (status < 0) - return status; + if (ACPI_FAILURE(status)) + return -status;
Quoted 2 lines
Otherwise "return -1;" would be fine by me. My only reason for going with "-status" is that it might give some clue as to what went wrong. Thoughts?
The acpi errors have an entirely different range, won't that confuse the caller? Maybe it's better to return an -errno and display the acpi error in a warning message.
Also, acpi_fujitsu_add() and acpi_fujitsu_notify() ignore a get_lcd_level() error return. Is that ok?
e.g. something like:
drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/platform/x86/fujitsu-laptop.c +8 -4
@@ -376,8 +376,10 @@ static int get_lcd_level(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) { +pr_warning ("%s failed, acpi error: %u\n" , __func__, status); +return -EINVAL ; + } fujitsu->brightness_level = state &0x0fffffff ;
@@ -398,8 +400,10 @@ static int get_max_brightness(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"RBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) { +pr_warning ("%s failed, acpi error: %u\n" , __func__, status); +return -EINVAL ; + } fujitsu->max_brightness = state;
Jonathan Woithe
Acked-byRe: [patch 05/12] fujitsu-laptop: fix tests of acpi_evaluate_integer()
Quoted 2 lines
The wrong test was used,
acpi_statusstatus is unsigned. Callers expect an -errno on failure.
Ah, ok - fair enough. The latter point wasn't clear to me.
Quoted 23 lines
Signed-off-by Roel Kluin <[email protected]>---
Quoted 20 lines
Quoted 8 lines
Review
Quoted 5 lines
The wrong test was used
acpi_statusstatus is unsigned.(quoted diff) +1
-1- if (status < 0) + if (ACPI_FAILURE(status)) return status;as status is a positive number, shouldn't we be returning something like -1 here on failure, rather than status?
These functions are called via the
backlight_opsstructure by the standard backlight class framework and it seems, from a real quick look, that the API treats numbers >=0 as valid data. So something like this (untested, off the top of my head) might be more appropriate:drivers/platform/x86/fujitsu-laptop.c +2
-2status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) +return -status;
Quoted 6 lines
Quoted 2 lines
Otherwise "return -1;" would be fine by me. My only reason for going with "-status" is that it might give some clue as to what went wrong. Thoughts?
The acpi errors have an entirely different range, won't that confuse the caller? Maybe it's better to return an -errno and display the acpi error in a warning message.
If an errno is expected by the caller then I agree completely with this suggestion; perhaps -EINVAL is the best choice?
Quoted 2 lines
Also,
acpi_fujitsu_add()andacpi_fujitsu_notify()ignore aget_lcd_level()error return. Is that ok?
In practice I don't expect it to cause any issues, but thanks for flagging it - I'll look into it in more detail. If the functions get this far it means that the relevant ACPI object has been found in the hardware and that therefore these functions should not fail. In any case, a failure to control the brightness does not necessarily mean that other functions provided by that object are broken so it is arguably wrong to fail the add/notify simply on the basis of a failed brightness read.
Quoted 26 lines
e.g. something like:
drivers/platform/x86/fujitsu-laptop.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)drivers/platform/x86/fujitsu-laptop.c +4
-2@@ -376,8 +376,10 @@ static int get_lcd_level(void) status =acpi_evaluate_integer (fujitsu->acpi_handle,"GBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) { +pr_warning ("%s failed, acpi error: %u\n" , __func__, status); +return -EINVAL ; + } fujitsu->brightness_level = state &0x0fffffff ;@@ -398,8 +400,10 @@ static int get_max_brightness(void) status =
drivers/platform/x86/fujitsu-laptop.c static int get_max_brightness(void) · line 409
Quoted 10 lines
drivers/platform/x86/fujitsu-laptop.c +4
-2acpi_evaluate_integer (fujitsu->acpi_handle,"RBLL" ,NULL , &state); -if (status <0 ) -return status; +if (ACPI_FAILURE (status)) { +pr_warning ("%s failed, acpi error: %u\n" , __func__, status); +return -EINVAL ; + } fujitsu->max_brightness = state;
Yes, I'd be happy with that. It seems sensible to me given the circumstances.
Regards
jonathan