dev: auto-generate device name in device_register if name is unspecified

This commit is contained in:
2023-05-11 21:19:00 +01:00
parent 802e610eed
commit 0238008986
5 changed files with 45 additions and 3 deletions

View File

@@ -37,6 +37,18 @@ static kern_status_t set_root_device(struct device *dev)
return KERN_OK;
}
static kern_status_t device_generate_name(struct device *dev)
{
switch (dev->dev_type) {
case DEV_TYPE_INPUT:
return input_device_generate_name(&dev->input);
default:
break;
}
return KERN_UNSUPPORTED;
}
kern_status_t device_init(void)
{
object_type_register(&device_type);
@@ -157,6 +169,15 @@ kern_status_t device_register(struct device *dev, struct device *parent)
kern_status_t status = KERN_OK;
if (dev->dev_name[0] == 0) {
status = device_generate_name(dev);
}
if (status != KERN_OK) {
device_unlock_irqrestore(dev, flags);
return status;
}
queue_foreach (struct device, child, &dev->dev_children, dev_childent) {
if (!strcmp(dev->dev_name, child->dev_name)) {
status = KERN_NAME_EXISTS;