| 207 | } |
| 208 | |
| 209 | error_t device_construct_add(struct Device* device, const char* compatible) { |
| 210 | struct Driver* driver = driver_find_compatible(compatible); |
| 211 | if (driver == nullptr) { |
| 212 | LOG_E(TAG, "Can't find driver '%s' for device '%s'", compatible, device->name); |
| 213 | return ERROR_RESOURCE; |
| 214 | } |
| 215 | |
| 216 | error_t error = device_construct(device); |
| 217 | if (error != ERROR_NONE) { |
| 218 | LOG_E(TAG, "Failed to construct device %s: %s", device->name, error_to_string(error)); |
| 219 | goto on_construct_error; |
| 220 | } |
| 221 | |
| 222 | device_set_driver(device, driver); |
| 223 | |
| 224 | error = device_add(device); |
| 225 | if (error != ERROR_NONE) { |
| 226 | LOG_E(TAG, "Failed to add device %s: %s", device->name, error_to_string(error)); |
| 227 | goto on_add_error; |
| 228 | } |
| 229 | |
| 230 | return ERROR_NONE; |
| 231 | |
| 232 | on_add_error: |
| 233 | device_destruct(device); |
| 234 | on_construct_error: |
| 235 | return error; |
| 236 | } |
| 237 | |
| 238 | error_t device_construct_add_start(struct Device* device, const char* compatible) { |
| 239 | error_t error = device_construct_add(device, compatible); |
no test coverage detected