env: clean cmd_nvedit.c checkpatch and code style

Cleanup the cmd_nvedit.c checkpatch warnings, errors and coding style.
There are 10 wanrings left about the simple_strtoul() function:
 WARNING: simple_strtoul is obsolete, use kstrtoul instead
 #359: FILE: cmd_nvedit.c:359:
 +		load_addr = simple_strtoul(argv[2], NULL, 16);

 ...

 total: 0 errors, 10 warnings, 1043 lines checked

Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
This commit is contained in:
Igor Grinberg 2011-11-07 01:13:59 +00:00 committed by Stefano Babic
parent 994bc671cf
commit d09b1787a4
3 changed files with 53 additions and 52 deletions

View file

@ -165,7 +165,8 @@ int do_env_print (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#ifdef CONFIG_CMD_GREPENV
static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
ENTRY *match;
unsigned char matched[env_htab.size / 8];
@ -178,7 +179,7 @@ static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
while (arg <= argc) {
idx = 0;
while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
while (idx = hstrstr_r(argv[arg], idx, &match, &env_htab)) {
if (!(matched[idx / 8] & (1 << (idx & 7)))) {
puts(match->key);
puts("=");
@ -199,8 +200,7 @@ static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
* Set a new environment variable,
* or replace or delete an existing one.
*/
int _do_env_set (int flag, int argc, char * const argv[])
int _do_env_set(int flag, int argc, char * const argv[])
{
bd_t *bd = gd->bd;
int i, len;
@ -211,7 +211,8 @@ int _do_env_set (int flag, int argc, char * const argv[])
name = argv[1];
if (strchr(name, '=')) {
printf("## Error: illegal character '=' in variable name \"%s\"\n", name);
printf("## Error: illegal character '=' in variable name"
"\"%s\"\n", name);
return 1;
}
@ -259,12 +260,12 @@ int _do_env_set (int flag, int argc, char * const argv[])
*/
if (ep) { /* variable exists */
#ifndef CONFIG_ENV_OVERWRITE
if ((strcmp(name, "serial#") == 0) ||
((strcmp(name, "ethaddr") == 0)
if (strcmp(name, "serial#") == 0 ||
(strcmp(name, "ethaddr") == 0
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
&& (strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0)
&& strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
) ) {
)) {
printf("Can't overwrite \"%s\"\n", name);
return 1;
}
@ -284,8 +285,8 @@ int _do_env_set (int flag, int argc, char * const argv[])
baudrate);
return 1;
}
printf ("## Switch baudrate to %d bps and press ENTER ...\n",
baudrate);
printf("## Switch baudrate to %d bps and"
"press ENTER ...\n", baudrate);
udelay(50000);
gd->baudrate = baudrate;
#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
@ -294,15 +295,13 @@ int _do_env_set (int flag, int argc, char * const argv[])
serial_setbrg();
udelay(50000);
for (;;) {
if (getc() == '\r')
break;
}
while (getc() != '\r')
;
}
}
/* Delete only ? */
if ((argc < 3) || argv[2] == NULL) {
if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, &env_htab);
return !rc;
}
@ -323,13 +322,13 @@ int _do_env_set (int flag, int argc, char * const argv[])
while ((*s++ = *v++) != '\0')
;
*(s-1) = ' ';
*(s - 1) = ' ';
}
if (s != value)
*--s = '\0';
e.key = name;
e.data = value;
e.key = name;
e.data = value;
hsearch_r(e, ENTER, &ep, &env_htab);
free(value);
if (!ep) {
@ -342,7 +341,6 @@ int _do_env_set (int flag, int argc, char * const argv[])
* Some variables should be updated when the corresponding
* entry in the environment is changed
*/
if (strcmp(name, "ipaddr") == 0) {
char *s = argv[2]; /* always use only one arg */
char *e;
@ -351,8 +349,9 @@ int _do_env_set (int flag, int argc, char * const argv[])
for (addr = 0, i = 0; i < 4; ++i) {
ulong val = s ? simple_strtoul(s, &e, 10) : 0;
addr <<= 8;
addr |= (val & 0xFF);
if (s) s = (*e) ? e+1 : e;
addr |= val & 0xFF;
if (s)
s = *e ? e + 1 : e;
}
bd->bi_ip_addr = htonl(addr);
return 0;
@ -373,7 +372,7 @@ int setenv(const char *varname, const char *varvalue)
{
const char * const argv[4] = { "setenv", varname, varvalue, NULL };
if ((varvalue == NULL) || (varvalue[0] == '\0'))
if (varvalue == NULL || varvalue[0] == '\0')
return _do_env_set(0, 2, (char * const *)argv);
else
return _do_env_set(0, 3, (char * const *)argv);
@ -452,9 +451,10 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (pos)
message[pos++] = ' ';
strcpy(message+pos, argv[i]);
strcpy(message + pos, argv[i]);
pos += strlen(argv[i]);
}
message[pos] = '\0';
size = simple_strtoul(argv[argc - 1], NULL, 10);
break;
@ -515,20 +515,19 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
*/
char *getenv(const char *name)
{
if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
ENTRY e, *ep;
WATCHDOG_RESET();
e.key = name;
e.data = NULL;
e.key = name;
e.data = NULL;
hsearch_r(e, FIND, &ep, &env_htab);
return ep ? ep->data : NULL;
}
/* restricted capabilities before import */
if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
return (char *)(gd->env_buf);
@ -542,7 +541,7 @@ int getenv_f(const char *name, char *buf, unsigned len)
{
int i, nxt;
for (i = 0; env_get_char(i) != '\0'; i = nxt+1) {
for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
int val, n;
for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
@ -556,7 +555,8 @@ int getenv_f(const char *name, char *buf, unsigned len)
/* found; copy out */
for (n = 0; n < len; ++n, ++buf) {
if ((*buf = env_get_char(val++)) == '\0')
*buf = env_get_char(val++);
if (*buf == '\0')
return n;
}
@ -568,6 +568,7 @@ int getenv_f(const char *name, char *buf, unsigned len)
return n;
}
return -1;
}
@ -592,11 +593,8 @@ ulong getenv_ulong(const char *name, int base, ulong default_val)
}
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
extern char *env_name_spec;
printf("Saving Environment to %s...\n", env_name_spec);
return saveenv() ? 1 : 0;
@ -607,7 +605,6 @@ U_BOOT_CMD(
"save environment variables to persistent storage",
""
);
#endif
@ -616,29 +613,32 @@ U_BOOT_CMD(
*
* s1 is either a simple 'name', or a 'name=value' pair.
* i2 is the environment index for a 'name2=value2' pair.
* If the names match, return the index for the value2, else NULL.
* If the names match, return the index for the value2, else -1.
*/
int envmatch(uchar *s1, int i2)
{
while (*s1 == env_get_char(i2++))
if (*s1++ == '=')
return i2;
if (*s1 == '\0' && env_get_char(i2-1) == '=')
return i2;
return -1;
}
static int do_env_default(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_env_default(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
if ((argc != 2) || (strcmp(argv[1], "-f") != 0))
if (argc != 2 || strcmp(argv[1], "-f") != 0)
return cmd_usage(cmdtp);
set_default_env("## Resetting to default environment\n");
return 0;
}
static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
printf("Not implemented yet\n");
return 0;
@ -690,7 +690,8 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
*
* => env import -d -t ${backup_addr}
*/
static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_env_export(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
char buf[32];
char *addr, *cmd, *res;
@ -749,8 +750,7 @@ NXTARG: ;
if (sep) { /* export as text file */
len = hexport_r(&env_htab, sep, &addr, size, argc, argv);
if (len < 0) {
error("Cannot export environment: errno = %d\n",
errno);
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
sprintf(buf, "%zX", (size_t)len);
@ -768,13 +768,12 @@ NXTARG: ;
len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, argc, argv);
if (len < 0) {
error("Cannot export environment: errno = %d\n",
errno);
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
if (chk) {
envp->crc = crc32(0, envp->data, ENV_SIZE);
envp->crc = crc32(0, envp->data, ENV_SIZE);
#ifdef CONFIG_ENV_ADDR_REDUND
envp->flags = ACTIVE_FLAG;
#endif
@ -785,8 +784,7 @@ NXTARG: ;
return 0;
sep_err:
printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
cmd);
printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
return 1;
}
#endif
@ -804,7 +802,8 @@ sep_err:
* size: length of input data; if missing, proper '\0'
* termination is mandatory
*/
static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_env_import(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
char *cmd, *addr;
char sep = '\n';
@ -902,10 +901,6 @@ sep_err:
}
#endif
#if defined(CONFIG_CMD_RUN)
extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
#endif
/*
* New command line interface: "env" command with subcommands
*/

View file

@ -64,6 +64,9 @@ typedef struct cmd_tbl_s cmd_tbl_t;
extern cmd_tbl_t __u_boot_cmd_start;
extern cmd_tbl_t __u_boot_cmd_end;
#if defined(CONFIG_CMD_RUN)
extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
#endif
/* common/command.c */
int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int

View file

@ -143,6 +143,9 @@ extern unsigned long nand_env_oob_offset;
# define ENV_HEADER_SIZE (sizeof(uint32_t))
#endif
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
extern char *env_name_spec;
#endif
#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)