treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / mips / fw / lib / cmdline.c
blob6ecda64ad18423f5e27e22cf9ccf8786a5062cac
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 */
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/string.h>
12 #include <asm/addrspace.h>
13 #include <asm/fw/fw.h>
15 int fw_argc;
16 int *_fw_argv;
17 int *_fw_envp;
19 void __init fw_init_cmdline(void)
21 int i;
23 /* Validate command line parameters. */
24 if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
25 fw_argc = 0;
26 _fw_argv = NULL;
27 } else {
28 fw_argc = (fw_arg0 & 0x0000ffff);
29 _fw_argv = (int *)fw_arg1;
32 /* Validate environment pointer. */
33 if (fw_arg2 < CKSEG0)
34 _fw_envp = NULL;
35 else
36 _fw_envp = (int *)fw_arg2;
38 for (i = 1; i < fw_argc; i++) {
39 strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
40 if (i < (fw_argc - 1))
41 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
45 char * __init fw_getcmdline(void)
47 return &(arcs_cmdline[0]);
50 char *fw_getenv(char *envname)
52 char *result = NULL;
54 if (_fw_envp != NULL) {
56 * Return a pointer to the given environment variable.
57 * YAMON uses "name", "value" pairs, while U-Boot uses
58 * "name=value".
60 int i, yamon, index = 0;
62 yamon = (strchr(fw_envp(index), '=') == NULL);
63 i = strlen(envname);
65 while (fw_envp(index)) {
66 if (strncmp(envname, fw_envp(index), i) == 0) {
67 if (yamon) {
68 result = fw_envp(index + 1);
69 break;
70 } else if (fw_envp(index)[i] == '=') {
71 result = fw_envp(index) + i + 1;
72 break;
76 /* Increment array index. */
77 if (yamon)
78 index += 2;
79 else
80 index += 1;
84 return result;
87 unsigned long fw_getenvl(char *envname)
89 unsigned long envl = 0UL;
90 char *str;
91 int tmp;
93 str = fw_getenv(envname);
94 if (str) {
95 tmp = kstrtoul(str, 0, &envl);
96 if (tmp)
97 envl = 0;
100 return envl;