Skip to content

Commit 660bba3

Browse files
committed
pinctrl: gpiochips section is only for pointers
The previous implementation of DECLARE_GPIO_CHIP was unintentionally putting variable amounts of additional data in the "gpiochips" section, which could lead to a crash. Restrict the section contents to pointers to the actual structures. Signed-off-by: Phil Elwell <[email protected]>
1 parent 1539249 commit 660bba3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pinctrl/gpiochip.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "gpiolib.h"
55

66
#define DECLARE_GPIO_CHIP(name, compatible, iface, size, data) \
7-
const GPIO_CHIP_T name ## _chip __attribute__ ((section ("gpiochips"))) __attribute__ ((used)) = \
8-
{ #name, compatible, iface, size, data }
7+
const GPIO_CHIP_T name ## _chip = { #name, compatible, iface, size, data }; \
8+
const GPIO_CHIP_T *name ## _chip_ptr __attribute__ ((section ("gpiochips"))) __attribute__ ((used)) = &(name ## _chip)
99

1010
typedef struct GPIO_CHIP_INTERFACE_ GPIO_CHIP_INTERFACE_T;
1111

@@ -36,7 +36,7 @@ struct GPIO_CHIP_INTERFACE_
3636
const char * (*gpio_get_fsel_name)(void *priv, uint32_t gpio, GPIO_FSEL_T fsel);
3737
};
3838

39-
extern const GPIO_CHIP_T __start_gpiochips;
40-
extern const GPIO_CHIP_T __stop_gpiochips;
39+
extern const GPIO_CHIP_T *__start_gpiochips;
40+
extern const GPIO_CHIP_T *__stop_gpiochips;
4141

4242
#endif

pinctrl/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ const char *gpio_get_drive_name(GPIO_DRIVE_T drive)
394394

395395
static const GPIO_CHIP_T *gpio_find_chip(const char *name)
396396
{
397-
const GPIO_CHIP_T *chip;
397+
const GPIO_CHIP_T **chip_ptr;
398398

399-
for (chip = &__start_gpiochips; name && chip < &__stop_gpiochips; chip++) {
399+
for (chip_ptr = &__start_gpiochips; name && chip_ptr < &__stop_gpiochips; chip_ptr++) {
400+
const GPIO_CHIP_T *chip = *chip_ptr;
400401
if (!strcmp(name, chip->name) ||
401402
!strcmp(name, chip->compatible))
402403
return chip;

0 commit comments

Comments
 (0)