coresight: return -EEXIST when register a device which has been registered

Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit is contained in:
liaoao 2024-01-11 17:01:56 +08:00 committed by Xiang Xiao
parent 6f770fb4b1
commit d04e1ebf4e
1 changed files with 29 additions and 0 deletions

View File

@ -661,6 +661,29 @@ err:
return ret;
}
/****************************************************************************
* Name: coresight_find_dev
****************************************************************************/
static FAR struct coresight_dev_s *coresight_find_dev(FAR const char *name)
{
FAR struct coresight_dev_s *tempdev;
irqstate_t flags;
flags = enter_critical_section();
list_for_every_entry(&g_csdev_list, tempdev, struct coresight_dev_s, node)
{
if (strcmp(tempdev->name, name) == 0)
{
leave_critical_section(flags);
return tempdev;
}
}
leave_critical_section(flags);
return NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -687,6 +710,12 @@ int coresight_register(FAR struct coresight_dev_s *csdev,
irqstate_t flags;
int i;
if (coresight_find_dev(desc->name) != NULL)
{
cserr("device has been registered!\n");
return -EEXIST;
}
csdev->name = desc->name;
csdev->addr = desc->addr;
csdev->type = desc->type;