Skip to content

Commit 7967aa6

Browse files
Tomasz Bursztykacarlescufi
Tomasz Bursztyka
authored andcommitted
drivers: gpio: Use DEVICE_AND_API_INIT for mmio32 driver
Let's set the api at built time, or this will create a bug once device instance pointers become constant. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent c8cca16 commit 7967aa6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

drivers/gpio/gpio_mmio32.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int gpio_mmio32_pin_interrupt_configure(struct device *dev,
153153
return 0;
154154
}
155155

156-
static const struct gpio_driver_api gpio_mmio32_api = {
156+
const struct gpio_driver_api gpio_mmio32_api = {
157157
.pin_configure = gpio_mmio32_config,
158158
.port_get_raw = gpio_mmio32_port_get_raw,
159159
.port_set_masked_raw = gpio_mmio32_port_set_masked_raw,
@@ -169,7 +169,6 @@ int gpio_mmio32_init(struct device *dev)
169169
const struct gpio_mmio32_config *config = dev->config;
170170

171171
context->config = config;
172-
dev->api = &gpio_mmio32_api;
173172

174173
return 0;
175174
}

include/drivers/gpio/gpio_mmio32.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <drivers/gpio.h>
1212
#include <zephyr/types.h>
1313

14+
extern const struct gpio_driver_api gpio_mmio32_api;
15+
1416
struct gpio_mmio32_config {
1517
/* gpio_driver_config needs to be first */
1618
struct gpio_driver_config common;
@@ -53,11 +55,12 @@ static const struct gpio_mmio32_config _dev_name##_dev_cfg = { \
5355
.mask = _mask, \
5456
}; \
5557
\
56-
DEVICE_INIT(_dev_name, _drv_name, \
57-
&gpio_mmio32_init, \
58-
&_dev_name##_dev_data, \
59-
&_dev_name##_dev_cfg, \
60-
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE)
58+
DEVICE_AND_API_INIT(_dev_name, _drv_name, \
59+
&gpio_mmio32_init, \
60+
&_dev_name##_dev_data, \
61+
&_dev_name##_dev_cfg, \
62+
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
63+
&gpio_mmio32_api)
6164

6265
#else /* CONFIG_GPIO_MMIO32 */
6366

0 commit comments

Comments
 (0)