Commit 9fe30535 authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by Anas Nashif
Browse files

susbsys: settings: fix coverity issues



API settings_subsys_init call was changed so that it returns
error (so returns int instead of void).
Prototype of storage helper function export_func for
settings_handler::h_export was changed so that it returns error
(so returns int instead of void).
Fixed few other error handling issues by ignoring return
values.

Tests were aligned to above patches.

Signed-off-by: default avatarAndrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
parent de223cce
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ struct settings_handler {
	char *(*h_get)(int argc, char **argv, char *val, int val_len_max);
	int (*h_set)(int argc, char **argv, char *val);
	int (*h_commit)(void);
	int (*h_export)(void (*export_func)(char *name, char *val),
	int (*h_export)(int (*export_func)(const char *name, char *val),
			enum settings_export_tgt tgt);
};

@@ -111,8 +111,10 @@ struct settings_handler {
 * Can be called at application startup.
 * In case the backend is NFFS Remember to call it after FS was mounted.
 * For FCB backend it can be called without such a restriction.
 *
 * @return 0 on success, non-zero on failure.
 */
void settings_subsys_init(void);
int settings_subsys_init(void);

/**
 * Register a handler for settings items.
+3 −3
Original line number Diff line number Diff line
@@ -204,7 +204,8 @@ static void settings_fcb_compress(struct settings_fcb *cf)
		if (rc) {
			continue;
		}
		fcb_append_finish(&cf->cf_fcb, &loc2.loc);
		rc = fcb_append_finish(&cf->cf_fcb, &loc2.loc);
		__ASSERT(rc == 0, "Failed to finish fcb_append.\n");
	}
	rc = fcb_rotate(&cf->cf_fcb);

@@ -233,8 +234,7 @@ static int settings_fcb_append(struct settings_fcb *cf, char *buf, int len)
	if (rc) {
		return -EINVAL;
	}
	fcb_append_finish(&cf->cf_fcb, &loc);
	return 0;
	return fcb_append_finish(&cf->cf_fcb, &loc);
}

static int settings_fcb_save(struct settings_store *cs, const char *name,
+5 −4
Original line number Diff line number Diff line
@@ -95,18 +95,19 @@ static void settings_init_fcb(void)

#endif

void settings_subsys_init(void)
int settings_subsys_init(void)
{
	settings_init();

#ifdef CONFIG_SETTINGS_FS
	settings_init_fs();
	settings_init_fs(); /* func rises kernel panic once error */

	/*
	 * Must be called after root FS has been initialized.
	 */
	fs_mkdir(CONFIG_SETTINGS_FS_DIR);
	return fs_mkdir(CONFIG_SETTINGS_FS_DIR);
#elif defined(CONFIG_SETTINGS_FCB)
	settings_init_fcb();
	settings_init_fcb(); /* func rises kernel panic once error */
	return 0;
#endif
}
+5 −11
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <stddef.h>
#include <sys/types.h>
#include <errno.h>
#include <misc/__assert.h>

#include "settings/settings.h"
#include "settings_priv.h"
@@ -45,7 +46,9 @@ void settings_dst_register(struct settings_store *cs)

static void settings_load_cb(char *name, char *val, void *cb_arg)
{
	settings_set_value(name, val);
	int rc = settings_set_value(name, val);
	__ASSERT(rc == 0, "set-value operation failure\n");
	(void)rc;
}

int settings_load(void)
@@ -114,15 +117,6 @@ int settings_save_one(const char *name, char *value)
	return cs->cs_itf->csi_save(cs, name, value);
}

/*
 * Walk through all registered subsystems, and ask them to export their
 * config variables. Persist these settings.
 */
static void settings_store_one(char *name, char *value)
{
	settings_save_one(name, value);
}

int settings_save(void)
{
	struct settings_store *cs;
@@ -142,7 +136,7 @@ int settings_save(void)

	SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
		if (ch->h_export) {
			rc2 = ch->h_export(settings_store_one,
			rc2 = ch->h_export(settings_save_one,
					   SETTINGS_EXPORT_PERSIST);
			if (!rc) {
				rc = rc2;
+10 −10
Original line number Diff line number Diff line
@@ -25,17 +25,17 @@ int c2_var_count = 1;
char *c1_handle_get(int argc, char **argv, char *val, int val_len_max);
int c1_handle_set(int argc, char **argv, char *val);
int c1_handle_commit(void);
int c1_handle_export(void (*cb)(char *name, char *value),
int c1_handle_export(int (*cb)(const char *name, char *value),
			enum settings_export_tgt tgt);

char *c2_handle_get(int argc, char **argv, char *val, int val_len_max);
int c2_handle_set(int argc, char **argv, char *val);
int c2_handle_export(void (*cb)(char *name, char *value),
int c2_handle_export(int (*cb)(const char *name, char *value),
		     enum settings_export_tgt tgt);

char *c3_handle_get(int argc, char **argv, char *val, int val_len_max);
int c3_handle_set(int argc, char **argv, char *val);
int c3_handle_export(void (*cb)(char *name, char *value),
int c3_handle_export(int (*cb)(const char *name, char *value),
		     enum settings_export_tgt tgt);

struct settings_handler c_test_handlers[] = {
@@ -112,7 +112,7 @@ int c1_handle_commit(void)
	return 0;
}

int c1_handle_export(void (*cb)(char *name, char *value),
int c1_handle_export(int (*cb)(const char *name, char *value),
			enum settings_export_tgt tgt)
{
	char value[32];
@@ -122,10 +122,10 @@ int c1_handle_export(void (*cb)(char *name, char *value),
	}

	settings_str_from_value(SETTINGS_INT8, &val8, value, sizeof(value));
	cb("myfoo/mybar", value);
	(void)cb("myfoo/mybar", value);

	settings_str_from_value(SETTINGS_INT64, &val64, value, sizeof(value));
	cb("myfoo/mybar64", value);
	(void)cb("myfoo/mybar64", value);

	return 0;
}
@@ -258,7 +258,7 @@ int c2_handle_set(int argc, char **argv, char *val)
	return -ENOENT;
}

int c2_handle_export(void (*cb)(char *name, char *value),
int c2_handle_export(int (*cb)(const char *name, char *value),
		     enum settings_export_tgt tgt)
{
	int i;
@@ -266,7 +266,7 @@ int c2_handle_export(void (*cb)(char *name, char *value),

	for (i = 0; i < c2_var_count; i++) {
		snprintf(name, sizeof(name), "2nd/string%d", i);
		cb(name, val_string[i]);
		(void)cb(name, val_string[i]);
	}

	return 0;
@@ -297,13 +297,13 @@ int c3_handle_set(int argc, char **argv, char *val)
	return -ENOENT;
}

int c3_handle_export(void (*cb)(char *name, char *value),
int c3_handle_export(int (*cb)(const char *name, char *value),
		     enum settings_export_tgt tgt)
{
	char value[32];

	settings_str_from_value(SETTINGS_INT32, &val32, value, sizeof(value));
	cb("3/v", value);
	(void)cb("3/v", value);

	return 0;
}
Loading