Skip to content

Commit dab67c3

Browse files
de-nordicjhedberg
authored andcommitted
settings: settings_register static table does not need mutex
It is not needed to protect static table of handlers, with mutex, as there is no possibility that there will be anything added to the table at runtime. Signed-off-by: Dominik Ermel <[email protected]>
1 parent efc5fe0 commit dab67c3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

subsys/settings/src/settings.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ void settings_init(void)
3838
#if defined(CONFIG_SETTINGS_DYNAMIC_HANDLERS)
3939
int settings_register(struct settings_handler *handler)
4040
{
41-
int rc;
42-
43-
k_mutex_lock(&settings_lock, K_FOREVER);
41+
int rc = 0;
4442

4543
Z_STRUCT_SECTION_FOREACH(settings_handler_static, ch) {
4644
if (strcmp(handler->name, ch->name) == 0) {
47-
rc = -EEXIST;
48-
goto end;
45+
return -EEXIST;
4946
}
5047
}
5148

49+
k_mutex_lock(&settings_lock, K_FOREVER);
50+
5251
struct settings_handler *ch;
5352
SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
5453
if (strcmp(handler->name, ch->name) == 0) {
@@ -57,7 +56,7 @@ int settings_register(struct settings_handler *handler)
5756
}
5857
}
5958
sys_slist_append(&settings_handlers, &handler->node);
60-
rc = 0;
59+
6160
end:
6261
k_mutex_unlock(&settings_lock);
6362
return rc;

0 commit comments

Comments
 (0)