lib: utils: Improve fdt_serial_init

A final check of all DT nodes does not necessarily find a match, so
SBI_ENODEV needs to be returned. Optimize removal of current_driver.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Xiang W
2023-05-22 13:18:07 +08:00
committed by Anup Patel
parent 8b99a7f7d8
commit 264d0be1fd

View File

@@ -17,13 +17,6 @@
extern struct fdt_serial *fdt_serial_drivers[]; extern struct fdt_serial *fdt_serial_drivers[];
extern unsigned long fdt_serial_drivers_size; extern unsigned long fdt_serial_drivers_size;
static struct fdt_serial dummy = {
.match_table = NULL,
.init = NULL,
};
static struct fdt_serial *current_driver = &dummy;
int fdt_serial_init(void) int fdt_serial_init(void)
{ {
const void *prop; const void *prop;
@@ -57,20 +50,15 @@ int fdt_serial_init(void)
if (!match) if (!match)
continue; continue;
if (drv->init) { /* drv->init must not be NULL */
if (drv->init == NULL)
return SBI_EFAIL;
rc = drv->init(fdt, noff, match); rc = drv->init(fdt, noff, match);
if (rc == SBI_ENODEV) if (rc == SBI_ENODEV)
continue; continue;
if (rc)
return rc; return rc;
} }
current_driver = drv;
break;
}
/* Check if we found desired driver */
if (current_driver != &dummy)
goto done;
/* Lastly check all DT nodes */ /* Lastly check all DT nodes */
for (pos = 0; pos < fdt_serial_drivers_size; pos++) { for (pos = 0; pos < fdt_serial_drivers_size; pos++) {
@@ -80,17 +68,15 @@ int fdt_serial_init(void)
if (noff < 0) if (noff < 0)
continue; continue;
if (drv->init) { /* drv->init must not be NULL */
if (drv->init == NULL)
return SBI_EFAIL;
rc = drv->init(fdt, noff, match); rc = drv->init(fdt, noff, match);
if (rc == SBI_ENODEV) if (rc == SBI_ENODEV)
continue; continue;
if (rc)
return rc; return rc;
} }
current_driver = drv;
break;
}
done: return SBI_ENODEV;
return 0;
} }