diff options
author | Nathan Chancellor <nathan@kernel.org> | 2023-06-22 18:12:41 +0200 |
---|---|---|
committer | Lee Jones <lee@kernel.org> | 2023-06-23 11:57:14 +0200 |
commit | 877e91191ccf0782ae18c5dfa7522fb1e5bfba8c (patch) | |
tree | f977816707be36ed981c487a3e6edaf953ef7958 /drivers/leds | |
parent | leds: sgm3140: Add richtek,rt5033-led compatible (diff) | |
download | linux-877e91191ccf0782ae18c5dfa7522fb1e5bfba8c.tar.xz linux-877e91191ccf0782ae18c5dfa7522fb1e5bfba8c.zip |
leds: leds-mt6323: Adjust return/parameter types in wled get/set callbacks
Clang's kernel Control Flow Integrity (kCFI) is a compiler-based
security mitigation that ensures the target of an indirect function call
matches the expected type of the call and trapping if they do not match
exactly. The warning -Wincompatible-function-pointer-types-strict aims
to catch these issues at compile time, which reveals:
drivers/leds/leds-mt6323.c:598:49: error: incompatible function pointer types assigning to 'int (*)(struct led_classdev *, enum led_brightness)' from 'int (struct led_classdev *, unsigned int)' [-Werror,-Wincompatible-function-pointer-types-strict]
598 | leds->led[reg]->cdev.brightness_set_blocking =
| ^
599 | mt6323_wled_set_brightness;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/leds/leds-mt6323.c:600:40: error: incompatible function pointer types assigning to 'enum led_brightness (*)(struct led_classdev *)' from 'unsigned int (struct led_classdev *)' [-Werror,-Wincompatible-function-pointer-types-strict]
600 | leds->led[reg]->cdev.brightness_get =
| ^
601 | mt6323_get_wled_brightness;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
While 'unsigned int' is ABI compatible with 'enum led_brightness' (hence
no warning from -Wincompatible-function-pointer-types) and the callers
of these callbacks use/pass the values as 'unsigned int', the mismatch
between the prototype and the called function will trip kCFI at runtime.
Change the types in the implementations to match the prototypes, clearing
up the warning and avoiding kCFI failures.
Fixes: 9bb0a9e0626c ("leds: leds-mt6323: Add support for WLEDs and MT6332")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20230622-mt6323-wled-wincompatible-function-pointer-types-strict-v1-1-6ad256f220e8@kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/leds-mt6323.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c index e8fecfc2e90a..24f35bdb55fb 100644 --- a/drivers/leds/leds-mt6323.c +++ b/drivers/leds/leds-mt6323.c @@ -76,7 +76,7 @@ struct mt6323_led { int id; struct mt6323_leds *parent; struct led_classdev cdev; - unsigned int current_brightness; + enum led_brightness current_brightness; }; /** @@ -451,7 +451,7 @@ static int mtk_wled_hw_off(struct led_classdev *cdev) return 0; } -static unsigned int mt6323_get_wled_brightness(struct led_classdev *cdev) +static enum led_brightness mt6323_get_wled_brightness(struct led_classdev *cdev) { struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); struct mt6323_leds *leds = led->parent; @@ -471,7 +471,7 @@ static unsigned int mt6323_get_wled_brightness(struct led_classdev *cdev) } static int mt6323_wled_set_brightness(struct led_classdev *cdev, - unsigned int brightness) + enum led_brightness brightness) { struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); struct mt6323_leds *leds = led->parent; |