gen_idt: Fix issues found by checkpatch

Change-Id: Ib486d8453c16c093dd188cd9e84c1eb2282ab746
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2015-10-05 16:07:10 -04:00 committed by Anas Nashif
commit ad76795063

View file

@ -77,40 +77,40 @@
#endif #endif
static void get_exec_name(char *pathname); static void get_exec_name(char *pathname);
static void usage(const int len); static void usage(int len);
static void get_options(int argc, char *argv[]); static void get_options(int argc, char *argv[]);
static void open_files(void); static void open_files(void);
static void close_files(void); static void close_files(void);
static void genIdt(void); static void genIdt(void);
static void clean_exit(const int exit_code); static void clean_exit(int exit_code);
typedef struct s_isrList { struct s_isrList {
void *fnc; void *fnc;
unsigned int dpl; unsigned int dpl;
} ISR_LIST; };
static ISR_LIST idt[256]; static struct s_isrList idt[256];
enum { enum {
IFILE=0, /* input file */ IFILE = 0, /* input file */
OFILE, /* output file */ OFILE, /* output file */
NUSERFILES, /* number of user-provided file names */ NUSERFILES, /* number of user-provided file names */
EXECFILE=NUSERFILES, /* for name of executable */ EXECFILE = NUSERFILES, /* for name of executable */
NFILES /* total number of files open */ NFILES /* total number of files open */
}; };
enum { SHORT_USAGE, LONG_USAGE }; enum { SHORT_USAGE, LONG_USAGE };
static int fds[NUSERFILES] = {-1, -1}; static int fds[NUSERFILES] = {-1, -1};
static char *filenames[NFILES]; static char *filenames[NFILES];
static unsigned int numVecs = (unsigned int)-1; static unsigned int numVecs = (unsigned int)-1;
static struct version version = {KERNEL_VERSION, 1, 1, 0}; static struct version version = {KERNEL_VERSION, 1, 1, 1};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
get_exec_name(argv[0]); get_exec_name(argv[0]);
get_options(argc, argv); /* may exit */ get_options(argc, argv); /* may exit */
open_files(); /* may exit */ open_files(); /* may exit */
genIdt(); genIdt(); /* may exit */
close_files(); close_files();
return 0; return 0;
} }
@ -121,7 +121,7 @@ static void get_options(int argc, char *argv[])
int ii, opt; int ii, opt;
while ((opt = getopt(argc, argv, "hi:o:n:v")) != -1) { while ((opt = getopt(argc, argv, "hi:o:n:v")) != -1) {
switch(opt) { switch (opt) {
case 'i': case 'i':
filenames[IFILE] = optarg; filenames[IFILE] = optarg;
break; break;
@ -164,7 +164,7 @@ static void get_options(int argc, char *argv[])
static void get_exec_name(char *pathname) static void get_exec_name(char *pathname)
{ {
int end = strlen(pathname)-1; int end = strlen(pathname) - 1;
while (end != -1) { while (end != -1) {
#if defined(WINDOWS) /* Might have both slashes in path */ #if defined(WINDOWS) /* Might have both slashes in path */
@ -173,7 +173,7 @@ static void get_exec_name(char *pathname)
if (pathname[end] == '/') if (pathname[end] == '/')
#endif #endif
{ {
if (0 == end || pathname[end-1] != '\\') { if (0 == end || pathname[end - 1] != '\\') {
++end; ++end;
break; break;
} }
@ -187,13 +187,16 @@ static void open_files(void)
{ {
int ii; int ii;
fds[IFILE] = open(filenames[IFILE], O_RDONLY|O_BINARY); fds[IFILE] = open(filenames[IFILE], O_RDONLY | O_BINARY);
fds[OFILE] = open(filenames[OFILE], O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, fds[OFILE] = open(filenames[OFILE], O_WRONLY | O_CREAT |
S_IWUSR|S_IRUSR); O_TRUNC | O_BINARY,
S_IWUSR | S_IRUSR);
for (ii = 0; ii < NUSERFILES; ii++) { for (ii = 0; ii < NUSERFILES; ii++) {
int invalid = fds[ii] == -1; int invalid = fds[ii] == -1;
if (invalid) { if (invalid) {
char *invalid = filenames[ii]; char *invalid = filenames[ii];
fprintf(stderr, "invalid file %s\n", invalid); fprintf(stderr, "invalid file %s\n", invalid);
for (--ii; ii >= 0; ii--) { for (--ii; ii >= 0; ii--) {
close(fds[ii]); close(fds[ii]);
@ -246,8 +249,10 @@ static void genIdt(void)
PRINTF("There are %d ISR(s)\n", size); PRINTF("There are %d ISR(s)\n", size);
if (size > numVecs) { if (size > numVecs) {
fprintf(stderr, "Too many ISRs found. Got %u. Expected less than %u." fprintf(stderr,
" Malformed input file?\n", size, numVecs); "Too many ISRs found. Got %u. Expected less than %u.\n"
"Malformed input file?\n",
size, numVecs);
clean_exit(-1); clean_exit(-1);
} }
@ -290,7 +295,8 @@ static void genIdt(void)
return; return;
readError: readError:
fprintf(stderr, "Error occurred while reading input file. Aborting...\n"); fprintf(stderr,
"Error occurred while reading input file. Aborting...\n");
clean_exit(-1); clean_exit(-1);
} }
@ -303,13 +309,13 @@ static void close_files(void)
} }
} }
static void clean_exit(const int exit_code) static void clean_exit(int exit_code)
{ {
close_files(); close_files();
exit(exit_code); exit(exit_code);
} }
static void usage(const int len) static void usage(int len)
{ {
fprintf(stderr, "\n%s -i <input file> -n <n>\n", filenames[EXECFILE]); fprintf(stderr, "\n%s -i <input file> -n <n>\n", filenames[EXECFILE]);