Skip to content

Commit 877e911

Browse files
nathanchancelag-linaro
authored andcommitted
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: 9bb0a9e ("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>
1 parent 7bd932d commit 877e911

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/leds/leds-mt6323.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct mt6323_led {
7676
int id;
7777
struct mt6323_leds *parent;
7878
struct led_classdev cdev;
79-
unsigned int current_brightness;
79+
enum led_brightness current_brightness;
8080
};
8181

8282
/**
@@ -451,7 +451,7 @@ static int mtk_wled_hw_off(struct led_classdev *cdev)
451451
return 0;
452452
}
453453

454-
static unsigned int mt6323_get_wled_brightness(struct led_classdev *cdev)
454+
static enum led_brightness mt6323_get_wled_brightness(struct led_classdev *cdev)
455455
{
456456
struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
457457
struct mt6323_leds *leds = led->parent;
@@ -471,7 +471,7 @@ static unsigned int mt6323_get_wled_brightness(struct led_classdev *cdev)
471471
}
472472

473473
static int mt6323_wled_set_brightness(struct led_classdev *cdev,
474-
unsigned int brightness)
474+
enum led_brightness brightness)
475475
{
476476
struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
477477
struct mt6323_leds *leds = led->parent;

0 commit comments

Comments
 (0)