From d04e1ebf4ec2805b78b10c4db5d3020f63e098e4 Mon Sep 17 00:00:00 2001 From: liaoao Date: Thu, 11 Jan 2024 17:01:56 +0800 Subject: [PATCH] coresight: return -EEXIST when register a device which has been registered Signed-off-by: liaoao --- drivers/coresight/coresight_core.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/coresight/coresight_core.c b/drivers/coresight/coresight_core.c index 56e056af0e..9b113123b9 100644 --- a/drivers/coresight/coresight_core.c +++ b/drivers/coresight/coresight_core.c @@ -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;