Skip to content

Commit 32b4670

Browse files
committed
samples: settings: handle failures
If we cannot initialize settings subsystem, it does not make much sense to do calls into it. This leads to uninitialized variables being printed and generally makes it hard to tell whether or not the sample runs with the given config. Signed-off-by: Dmitrii Sharshakov <[email protected]>
1 parent 5945a3f commit 32b4670

File tree

1 file changed

+8
-3
lines changed
  • samples/subsys/settings/src

1 file changed

+8
-3
lines changed

samples/subsys/settings/src/main.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static void example_without_handler(void)
418418
}
419419
}
420420

421-
static void example_initialization(void)
421+
static int example_initialization(void)
422422
{
423423
int rc;
424424

@@ -450,7 +450,7 @@ static void example_initialization(void)
450450
rc = settings_subsys_init();
451451
if (rc) {
452452
printk("settings subsys initialization: fail (err %d)\n", rc);
453-
return;
453+
return rc;
454454
}
455455

456456
printk("settings subsys initialization: OK.\n");
@@ -459,10 +459,13 @@ static void example_initialization(void)
459459
if (rc) {
460460
printk("subtree <%s> handler registered: fail (err %d)\n",
461461
alpha_handler.name, rc);
462+
return rc;
462463
}
463464

464465
printk("subtree <%s> handler registered: OK\n", alpha_handler.name);
465466
printk("subtree <alpha/beta> has static handler\n");
467+
468+
return 0;
466469
}
467470

468471
static void example_delete(void)
@@ -542,7 +545,9 @@ int main(void)
542545
printk("\n*** Settings usage example ***\n\n");
543546

544547
/* settings initialization */
545-
example_initialization();
548+
if (example_initialization() != 0) {
549+
return 0;
550+
}
546551

547552
for (i = 0; i < 6; i++) {
548553
printk("\n##############\n");

0 commit comments

Comments
 (0)