drivers: gpio: Fix device instance const qualifier loss

It is necessary to wrap the device pointer into data.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-07-08 10:33:47 +02:00 committed by Carles Cufí
parent d1aee6b87f
commit 4917f6f4da
3 changed files with 16 additions and 8 deletions

View File

@ -31,6 +31,7 @@ struct gpio_sam0_config {
struct gpio_sam0_data {
/* gpio_driver_data needs to be first */
struct gpio_driver_data common;
const struct device *dev;
gpio_port_pins_t debounce;
#ifdef CONFIG_SAM0_EIC
sys_slist_t callbacks;
@ -45,10 +46,9 @@ struct gpio_sam0_data {
#ifdef CONFIG_SAM0_EIC
static void gpio_sam0_isr(uint32_t pins, void *arg)
{
const struct device *dev = (const struct device *) arg;
struct gpio_sam0_data *const data = DEV_DATA(dev);
struct gpio_sam0_data *const data = (struct gpio_sam0_data *)arg;
gpio_fire_callbacks(&data->callbacks, dev, pins);
gpio_fire_callbacks(&data->callbacks, data->dev, pins);
}
#endif
@ -167,6 +167,7 @@ static int gpio_sam0_pin_interrupt_configure(const struct device *dev,
enum gpio_int_trig trig)
{
const struct gpio_sam0_config *config = DEV_CFG(dev);
struct gpio_sam0_data *const data = DEV_DATA(dev);
PortGroup *regs = config->regs;
PORT_PINCFG_Type pincfg = {
.reg = regs->PINCFG[pin].reg,
@ -174,6 +175,8 @@ static int gpio_sam0_pin_interrupt_configure(const struct device *dev,
enum sam0_eic_trigger trigger;
int rc = 0;
data->dev = dev;
switch (mode) {
case GPIO_INT_MODE_DISABLED:
pincfg.bit.PMUXEN = 0;
@ -231,7 +234,7 @@ static int gpio_sam0_pin_interrupt_configure(const struct device *dev,
if (rc == 0) {
rc = sam0_eic_acquire(config->id, pin, trigger,
(DEV_DATA(dev)->debounce & BIT(pin)) != 0,
gpio_sam0_isr, dev);
gpio_sam0_isr, data);
}
if (rc == 0) {
rc = sam0_eic_enable_interrupt(config->id, pin);

View File

@ -31,10 +31,9 @@
*/
static void gpio_stm32_isr(int line, void *arg)
{
const struct device *dev = arg;
struct gpio_stm32_data *data = dev->data;
struct gpio_stm32_data *data = arg;
gpio_fire_callbacks(&data->cb, dev, BIT(line));
gpio_fire_callbacks(&data->cb, data->dev, BIT(line));
}
/**
@ -431,6 +430,7 @@ static int gpio_stm32_pin_interrupt_configure(const struct device *dev,
enum gpio_int_trig trig)
{
const struct gpio_stm32_config *cfg = dev->config;
struct gpio_stm32_data *data = dev->data;
int edge = 0;
int err = 0;
@ -450,7 +450,7 @@ static int gpio_stm32_pin_interrupt_configure(const struct device *dev,
goto exit;
}
if (stm32_exti_set_callback(pin, gpio_stm32_isr, dev) != 0) {
if (stm32_exti_set_callback(pin, gpio_stm32_isr, data) != 0) {
err = -EBUSY;
goto exit;
}
@ -510,6 +510,9 @@ static const struct gpio_driver_api gpio_stm32_driver = {
static int gpio_stm32_init(const struct device *device)
{
const struct gpio_stm32_config *cfg = device->config;
struct gpio_stm32_data *data = device->data;
data->dev = device;
/* enable clock for subsystem */
const struct device *clk =

View File

@ -218,6 +218,8 @@ struct gpio_stm32_config {
struct gpio_stm32_data {
/* gpio_driver_data needs to be first */
struct gpio_driver_data common;
/* device's owner of this data */
const struct device *dev;
/* user ISR cb */
sys_slist_t cb;
};