kernel: check retval of driver init
If initialization fails, zero the API struct so that device_get_binding() can't fetch it, and do not mark the driver object as initialized to user mode. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
2d2a0452b9
commit
a68120de6d
2 changed files with 10 additions and 8 deletions
|
@ -105,12 +105,6 @@ static int i2c_gpio_init(struct device *dev)
|
|||
|
||||
i2c_bitbang_init(&context->bitbang, &io_fns, context);
|
||||
|
||||
/*
|
||||
* Set driver_api at very end of init so if we return early with error
|
||||
* then the device can't be found later by device_get_binding. This is
|
||||
* important because driver framework ignores errors from init
|
||||
* functions.
|
||||
*/
|
||||
dev->driver_api = &api;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -50,10 +50,18 @@ void _sys_device_do_config_level(s32_t level)
|
|||
|
||||
for (info = config_levels[level]; info < config_levels[level+1];
|
||||
info++) {
|
||||
int retval;
|
||||
struct device_config *device_conf = info->config;
|
||||
|
||||
(void)device_conf->init(info);
|
||||
_k_object_init(info);
|
||||
retval = device_conf->init(info);
|
||||
if (retval != 0) {
|
||||
/* Initialization failed. Clear the API struct so that
|
||||
* device_get_binding() will not succeed for it.
|
||||
*/
|
||||
info->driver_api = NULL;
|
||||
} else {
|
||||
_k_object_init(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue