Skip to content

Commit 04d9d57

Browse files
Tomasz Bursztykanashif
authored andcommitted
api/gpio: Controller may not support GPIO_INT at all
It's not an error if a driver does not implement callback related function. Let's return -ENOTSUP relevantly. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 064f5f0 commit 04d9d57

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

drivers/gpio/gpio_handlers.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ Z_SYSCALL_HANDLER(gpio_read, port, access_op, pin, value)
2929

3030
Z_SYSCALL_HANDLER(gpio_enable_callback, port, access_op, pin)
3131
{
32-
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, enable_callback));
3332
return _impl_gpio_enable_callback((struct device *)port, access_op,
3433
pin);
3534
}
3635

3736
Z_SYSCALL_HANDLER(gpio_disable_callback, port, access_op, pin)
3837
{
39-
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, disable_callback));
4038
return _impl_gpio_disable_callback((struct device *)port, access_op,
4139
pin);
4240
}
4341

4442
Z_SYSCALL_HANDLER(gpio_get_pending_int, port)
4543
{
46-
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, get_pending_int));
4744
return _impl_gpio_get_pending_int((struct device *)port);
4845
}

include/gpio.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ static inline int _impl_gpio_enable_callback(struct device *port,
169169
const struct gpio_driver_api *api =
170170
(const struct gpio_driver_api *)port->driver_api;
171171

172+
if (!api->enable_callback) {
173+
return -ENOTSUP;
174+
}
175+
172176
return api->enable_callback(port, access_op, pin);
173177
}
174178

@@ -181,6 +185,10 @@ static inline int _impl_gpio_disable_callback(struct device *port,
181185
const struct gpio_driver_api *api =
182186
(const struct gpio_driver_api *)port->driver_api;
183187

188+
if (!api->disable_callback) {
189+
return -ENOTSUP;
190+
}
191+
184192
return api->disable_callback(port, access_op, pin);
185193
}
186194
/**
@@ -260,7 +268,9 @@ static inline int gpio_add_callback(struct device *port,
260268
const struct gpio_driver_api *api =
261269
(const struct gpio_driver_api *)port->driver_api;
262270

263-
__ASSERT(callback, "Callback pointer should not be NULL");
271+
if (!api->manage_callback) {
272+
return -ENOTSUP;
273+
}
264274

265275
return api->manage_callback(port, callback, true);
266276
}
@@ -280,7 +290,9 @@ static inline int gpio_remove_callback(struct device *port,
280290
const struct gpio_driver_api *api =
281291
(const struct gpio_driver_api *)port->driver_api;
282292

283-
__ASSERT(callback, "Callback pointer should not be NULL");
293+
if (!api->manage_callback) {
294+
return -ENOTSUP;
295+
}
284296

285297
return api->manage_callback(port, callback, false);
286298
}
@@ -405,9 +417,13 @@ __syscall int gpio_get_pending_int(struct device *dev);
405417
*/
406418
static inline int _impl_gpio_get_pending_int(struct device *dev)
407419
{
408-
struct gpio_driver_api *api;
420+
const struct gpio_driver_api *api =
421+
(const struct gpio_driver_api *)dev->driver_api;
422+
423+
if (!api->get_pending_int) {
424+
return -ENOTSUP;
425+
}
409426

410-
api = (struct gpio_driver_api *)dev->driver_api;
411427
return api->get_pending_int(dev);
412428
}
413429

0 commit comments

Comments
 (0)