[PATCH 0/4] Correct some small errors in API

16 views
Skip to first unread message

Andreas J. Reichel

unread,
Nov 14, 2017, 8:24:20 AM11/14/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

Correct some mistakes, the last coverity scan found.

bg_setenv: Set default uservar type to ASCII string so that users
can print the variables they created with the tool per default.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>

Andreas Reichel (4):
env: Fix error handling in open_config_file
env: Fix return of close_config_file
tools: api: Use correct neg ret vals for globalstate
tools: Add ASCII STRING to default type for user vars

env/env_api.c | 6 +++---
env/env_config_file.c | 5 +++++
tools/bg_setenv.c | 5 +++--
3 files changed, 11 insertions(+), 5 deletions(-)

--
2.15.0

Andreas J. Reichel

unread,
Nov 14, 2017, 8:24:21 AM11/14/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

Currently, all user variables set by the tool are ASCII
strings. To be able to print them, the correct data type
needs to be stored.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
tools/bg_setenv.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 746d474..ca126b8 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -212,7 +212,8 @@ static error_t set_uservars(char *arg)
if (value == NULL) {
return journal_add_action(ENV_TASK_DEL, key, 0, NULL, 0);
}
- return journal_add_action(ENV_TASK_SET, key, USERVAR_TYPE_DEFAULT,
+ return journal_add_action(ENV_TASK_SET, key, USERVAR_TYPE_DEFAULT |
+ USERVAR_TYPE_STRING_ASCII,
(uint8_t *)value, strlen(value) + 1);
}

--
2.15.0

Andreas J. Reichel

unread,
Nov 14, 2017, 8:24:21 AM11/14/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

Make negative return values in environment setters consistent.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
env/env_api.c | 6 +++---
tools/bg_setenv.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/env/env_api.c b/env/env_api.c
index bd034af..ea55bad 100644
--- a/env/env_api.c
+++ b/env/env_api.c
@@ -171,7 +171,7 @@ int ebg_env_setglobalstate(ebgenv_t *e, uint16_t ustate)
int res;

if (ustate > USTATE_FAILED) {
- return EINVAL;
+ return -EINVAL;
}
(void)snprintf(buffer, sizeof(buffer), "%d", ustate);
res = bgenv_set((BGENV *)e->bgenv, "ustate", 0, buffer,
@@ -190,10 +190,10 @@ int ebg_env_setglobalstate(ebgenv_t *e, uint16_t ustate)
env->data->ustate = ustate;
if (!bgenv_write(env)) {
(void)bgenv_close(env);
- return EIO;
+ return -EIO;
}
if (!bgenv_close(env)) {
- return EIO;
+ return -EIO;
}
}
return 0;
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index bc65c51..746d474 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -146,7 +146,7 @@ static void journal_process_action(BGENV *env, struct env_action *action)
if ((ret = ebg_env_setglobalstate(&e, ustate)) != 0) {
fprintf(stderr,
"Error setting global state: %s.",
- strerror(ret));
+ strerror(-ret));
}
return;
}
--
2.15.0

Andreas J. Reichel

unread,
Nov 14, 2017, 8:24:21 AM11/14/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

If close_config_file gets an invalid parameter, return EINVAL.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
env/env_config_file.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/env/env_config_file.c b/env/env_config_file.c
index 83feab8..b101074 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -44,6 +44,7 @@ int close_config_file(FILE *config_file_handle)
{
return fclose(config_file_handle);
}
+ return EINVAL;
}

bool probe_config_file(CONFIG_PART *cfgpart)
--
2.15.0

Andreas J. Reichel

unread,
Nov 14, 2017, 8:24:21 AM11/14/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

Check pointers before using them.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
env/env_config_file.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/env/env_config_file.c b/env/env_config_file.c
index 3a802f2..83feab8 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -19,6 +19,10 @@
FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
{
char *configfilepath;
+ if (!cfgpart)
+ return NULL;
+ if (!cfgpart->mountpoint)
+ return NULL;
configfilepath = (char *)malloc(strlen(FAT_ENV_FILENAME) +
strlen(cfgpart->mountpoint) + 2);
if (!configfilepath) {
--
2.15.0

Jan Kiszka

unread,
Nov 15, 2017, 1:19:00 AM11/15/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
Applied, but I reformatted this to make it consistent and more compact.

if (!cfgpart || !cfgpart->mountpoint) {
return NULL;
}

Jan

Jan Kiszka

unread,
Nov 15, 2017, 1:19:42 AM11/15/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
On 2017-11-14 14:22, [ext] Andreas J. Reichel wrote:
You also need to update the testcases, no?

Jan

--
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

Jan Kiszka

unread,
Nov 15, 2017, 1:20:24 AM11/15/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
On 2017-11-14 14:22, [ext] Andreas J. Reichel wrote:
Applied, thanks.

Jan Kiszka

unread,
Nov 15, 2017, 1:27:48 AM11/15/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
On 2017-11-14 14:22, [ext] Andreas J. Reichel wrote:
Thanks, applied.

Jan Kiszka

unread,
Nov 15, 2017, 2:06:31 AM11/15/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
I've done that for you.

Jan
Reply all
Reply to author
Forward
0 new messages