From: Husain Alshehhi <[email protected]>
Signed-off-by: Husain Alshehhi <[email protected]>
---
usr/gen_init_cpio.c | 177 +++++++++++++++++++++++---------------------
1 file changed, 91 insertions(+), 86 deletions(-)
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 0e2c8a5838b1..a419086f94f0 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -39,7 +39,7 @@ static void push_string(const char *name)
offset += name_len;
}
-static void push_pad (void)
+static void push_pad(void)
{
while (offset & 3) {
putchar(0);
@@ -77,20 +77,20 @@ static void cpio_trailer(void)
sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
- 0, /* ino */
- 0, /* mode */
- (long) 0, /* uid */
- (long) 0, /* gid */
- 1, /* nlink */
- (long) 0, /* mtime */
- 0, /* filesize */
- 0, /* major */
- 0, /* minor */
- 0, /* rmajor */
- 0, /* rminor */
- (unsigned)strlen(name)+1, /* namesize */
- 0); /* chksum */
+ "070701", /* magic */
+ 0, /* ino */
+ 0, /* mode */
+ 0L, /* uid */
+ 0L, /* gid */
+ 1, /* nlink */
+ 0L, /* mtime */
+ 0, /* filesize */
+ 0, /* major */
+ 0, /* minor */
+ 0, /* rmajor */
+ 0, /* rminor */
+ (unsigned int)strlen(name)+1, /* namesize */
+ 0); /* chksum */
push_hdr(s);
push_rest(name);
@@ -107,22 +107,22 @@ static int cpio_mkslink(const char *name, const char *target,
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
- ino++, /* ino */
- S_IFLNK | mode, /* mode */
- (long) uid, /* uid */
- (long) gid, /* gid */
- 1, /* nlink */
- (long) default_mtime, /* mtime */
- (unsigned)strlen(target)+1, /* filesize */
- 3, /* major */
- 1, /* minor */
- 0, /* rmajor */
- 0, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
- 0); /* chksum */
+ "070701", /* magic */
+ ino++, /* ino */
+ S_IFLNK | mode, /* mode */
+ (long) uid, /* uid */
+ (long) gid, /* gid */
+ 1, /* nlink */
+ (long) default_mtime, /* mtime */
+ (unsigned int)strlen(target)+1, /* filesize */
+ 3, /* major */
+ 1, /* minor */
+ 0, /* rmajor */
+ 0, /* rminor */
+ (unsigned int)strlen(name) + 1, /* namesize */
+ 0); /* chksum */
push_hdr(s);
push_string(name);
push_pad();
@@ -140,7 +140,7 @@ static int cpio_mkslink_line(const char *line)
int gid;
int rc = -1;
- if (5 != sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) "s %o %d %d", name, target, &mode, &uid, &gid)) {
+ if (sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) "s %o %d %d", name, target, &mode, &uid, &gid) != 5) {
fprintf(stderr, "Unrecognized dir format '%s'", line);
goto fail;
}
@@ -156,22 +156,22 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
- ino++, /* ino */
- mode, /* mode */
- (long) uid, /* uid */
- (long) gid, /* gid */
- 2, /* nlink */
- (long) default_mtime, /* mtime */
- 0, /* filesize */
- 3, /* major */
- 1, /* minor */
- 0, /* rmajor */
- 0, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
- 0); /* chksum */
+ "070701", /* magic */
+ ino++, /* ino */
+ mode, /* mode */
+ (long) uid, /* uid */
+ (long) gid, /* gid */
+ 2, /* nlink */
+ (long) default_mtime, /* mtime */
+ 0, /* filesize */
+ 3, /* major */
+ 1, /* minor */
+ 0, /* rmajor */
+ 0, /* rminor */
+ (unsigned int)strlen(name) + 1, /* namesize */
+ 0); /* chksum */
push_hdr(s);
push_rest(name);
return 0;
@@ -211,7 +211,7 @@ static int cpio_mkgeneric_line(const char *line, enum generic_types gt)
int gid;
int rc = -1;
- if (4 != sscanf(line, "%" str(PATH_MAX) "s %o %d %d", name, &mode, &uid, &gid)) {
+ if (sscanf(line, "%" str(PATH_MAX) "s %o %d %d", name, &mode, &uid, &gid) != 4) {
fprintf(stderr, "Unrecognized %s format '%s'",
line, generic_type_table[gt].type);
goto fail;
@@ -250,22 +250,22 @@ static int cpio_mknod(const char *name, unsigned int mode,
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
- ino++, /* ino */
- mode, /* mode */
- (long) uid, /* uid */
- (long) gid, /* gid */
- 1, /* nlink */
- (long) default_mtime, /* mtime */
- 0, /* filesize */
- 3, /* major */
- 1, /* minor */
- maj, /* rmajor */
- min, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
- 0); /* chksum */
+ "070701", /* magic */
+ ino++, /* ino */
+ mode, /* mode */
+ (long) uid, /* uid */
+ (long) gid, /* gid */
+ 1, /* nlink */
+ (long) default_mtime, /* mtime */
+ 0, /* filesize */
+ 3, /* major */
+ 1, /* minor */
+ maj, /* rmajor */
+ min, /* rminor */
+ (unsigned int)strlen(name) + 1, /* namesize */
+ 0); /* chksum */
push_hdr(s);
push_rest(name);
return 0;
@@ -282,8 +282,8 @@ static int cpio_mknod_line(const char *line)
unsigned int min;
int rc = -1;
- if (7 != sscanf(line, "%" str(PATH_MAX) "s %o %d %d %c %u %u",
- name, &mode, &uid, &gid, &dev_type, &maj, &min)) {
+ if (sscanf(line, "%" str(PATH_MAX) "s %o %d %d %c %u %u",
+ name, &mode, &uid, &gid, &dev_type, &maj, &min) != 7) {
fprintf(stderr, "Unrecognized nod format '%s'", line);
goto fail;
}
@@ -308,9 +308,9 @@ static int cpio_mkfile(const char *name, const char *location,
mode |= S_IFREG;
- file = open (location, O_RDONLY);
+ file = open(location, O_RDONLY);
if (file < 0) {
- fprintf (stderr, "File %s could not be opened for reading\n", location);
+ fprintf(stderr, "File %s could not be opened for reading\n", location);
goto error;
}
@@ -328,25 +328,26 @@ static int cpio_mkfile(const char *name, const char *location,
filebuf = malloc(buf.st_size);
if (!filebuf) {
- fprintf (stderr, "out of memory\n");
+ fprintf(stderr, "out of memory\n");
goto error;
}
- retval = read (file, filebuf, buf.st_size);
+ retval = read(file, filebuf, buf.st_size);
if (retval < 0) {
- fprintf (stderr, "Can not read %s file\n", location);
+ fprintf(stderr, "Can not read %s file\n", location);
goto error;
}
size = 0;
for (i = 1; i <= nlinks; i++) {
/* data goes on last link */
- if (i == nlinks) size = buf.st_size;
+ if (i == nlinks)
+ size = buf.st_size;
if (name[0] == '/')
name++;
namesize = strlen(name) + 1;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08lX%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino, /* ino */
@@ -379,10 +380,12 @@ static int cpio_mkfile(const char *name, const char *location,
}
ino++;
rc = 0;
-
+
error:
- if (filebuf) free(filebuf);
- if (file >= 0) close(file);
+ if (filebuf)
+ free(filebuf);
+ if (file >= 0)
+ close(file);
return rc;
}
@@ -395,7 +398,7 @@ static char *cpio_replace_env(char *new_location)
(end = strchr(start + 2, '}'))) {
*start = *end = 0;
var = getenv(start + 2);
- snprintf(expanded, sizeof expanded, "%s%s%s",
+ snprintf(expanded, sizeof(expanded), "%s%s%s",
new_location, var ? var : "", end + 1);
strcpy(new_location, expanded);
}
@@ -415,9 +418,9 @@ static int cpio_mkfile_line(const char *line)
int end = 0, dname_len = 0;
int rc = -1;
- if (5 > sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX)
- "s %o %d %d %n",
- name, location, &mode, &uid, &gid, &end)) {
+ if (sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX)
+ "s %o %d %d %n",
+ name, location, &mode, &uid, &gid, &end) < 5) {
fprintf(stderr, "Unrecognized file format '%s'", line);
goto fail;
}
@@ -427,7 +430,7 @@ static int cpio_mkfile_line(const char *line)
dname = malloc(strlen(line));
if (!dname) {
- fprintf (stderr, "out of memory (%d)\n", dname_len);
+ fprintf(stderr, "out of memory (%d)\n", dname_len);
goto fail;
}
@@ -449,9 +452,10 @@ static int cpio_mkfile_line(const char *line)
dname = name;
}
rc = cpio_mkfile(dname, cpio_replace_env(location),
- mode, uid, gid, nlinks);
+ mode, uid, gid, nlinks);
fail:
- if (dname_len) free(dname);
+ if (dname_len)
+ free(dname);
return rc;
}
@@ -524,7 +528,7 @@ static const struct file_handler file_handler_table[] = {
#define LINE_SIZE (2 * PATH_MAX + 50)
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
FILE *cpio_list;
char line[LINE_SIZE];
@@ -592,7 +596,7 @@ int main (int argc, char *argv[])
continue;
}
- if (! (type = strtok(line, " \t"))) {
+ if (!(type = strtok(line, " \t"))) {
fprintf(stderr,
"ERROR: incorrect format, could not locate file type line %d: '%s'\n",
line_nr, line);
@@ -610,7 +614,7 @@ int main (int argc, char *argv[])
continue;
}
- if (! (args = strtok(NULL, "\n"))) {
+ if (!(args = strtok(NULL, "\n"))) {
fprintf(stderr,
"ERROR: incorrect format, newline required line %d: '%s'\n",
line_nr, line);
@@ -619,7 +623,8 @@ int main (int argc, char *argv[])
for (type_idx = 0; file_handler_table[type_idx].type; type_idx++) {
int rc;
- if (! strcmp(line, file_handler_table[type_idx].type)) {
+
+ if (!strcmp(line, file_handler_table[type_idx].type)) {
if ((rc = file_handler_table[type_idx].handler(args))) {
ec = rc;
fprintf(stderr, " line %d\n", line_nr);
@@ -628,7 +633,7 @@ int main (int argc, char *argv[])
}
}
- if (NULL == file_handler_table[type_idx].type) {
+ if (file_handler_table[type_idx].type == NULL) {
fprintf(stderr, "unknown file type line %d: '%s'\n",
line_nr, line);
}
--
2.25.1
This is my first Patch to the linux kernel. I am not sure whether
details on how this patch is tested should be included in the commit
message or not. Nevertheless, here are the details.
Original:
/home/husain/src/linux/scripts/checkpatch.pl --file --terse --emacs /home/husain/src/linux/usr/gen_init_cpio.c
/home/husain/src/linux/usr/gen_init_cpio.c:42: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:76: WARNING: const array should probably be static const
/home/husain/src/linux/usr/gen_init_cpio.c:79: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:83: WARNING: Unnecessary typecast of c90 int constant - '(long) 0' could be '0L'
/home/husain/src/linux/usr/gen_init_cpio.c:84: WARNING: Unnecessary typecast of c90 int constant - '(long) 0' could be '0L'
/home/husain/src/linux/usr/gen_init_cpio.c:86: WARNING: Unnecessary typecast of c90 int constant - '(long) 0' could be '0L'
/home/husain/src/linux/usr/gen_init_cpio.c:92: WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
/home/husain/src/linux/usr/gen_init_cpio.c:110: ERROR: space required after that ',' (ctx:VxV)
/home/husain/src/linux/usr/gen_init_cpio.c:111: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:119: WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
/home/husain/src/linux/usr/gen_init_cpio.c:124: WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
/home/husain/src/linux/usr/gen_init_cpio.c:143: WARNING: Comparisons should place the constant on the right side of the test
/home/husain/src/linux/usr/gen_init_cpio.c:159: ERROR: space required after that ',' (ctx:VxV)
/home/husain/src/linux/usr/gen_init_cpio.c:160: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:173: WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
/home/husain/src/linux/usr/gen_init_cpio.c:214: WARNING: Comparisons should place the constant on the right side of the test
/home/husain/src/linux/usr/gen_init_cpio.c:253: ERROR: space required after that ',' (ctx:VxV)
/home/husain/src/linux/usr/gen_init_cpio.c:254: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:267: WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
/home/husain/src/linux/usr/gen_init_cpio.c:285: WARNING: Comparisons should place the constant on the right side of the test
/home/husain/src/linux/usr/gen_init_cpio.c:311: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:313: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:331: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:335: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:337: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:344: ERROR: trailing statements should be on next line
/home/husain/src/linux/usr/gen_init_cpio.c:349: ERROR: space required after that ',' (ctx:VxV)
/home/husain/src/linux/usr/gen_init_cpio.c:350: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:382: ERROR: trailing whitespace
/home/husain/src/linux/usr/gen_init_cpio.c:384: ERROR: trailing statements should be on next line
/home/husain/src/linux/usr/gen_init_cpio.c:385: ERROR: trailing statements should be on next line
/home/husain/src/linux/usr/gen_init_cpio.c:398: WARNING: sizeof expanded should be sizeof(expanded)
/home/husain/src/linux/usr/gen_init_cpio.c:418: WARNING: Comparisons should place the constant on the right side of the test
/home/husain/src/linux/usr/gen_init_cpio.c:430: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:452: ERROR: code indent should use tabs where possible
/home/husain/src/linux/usr/gen_init_cpio.c:454: ERROR: trailing statements should be on next line
/home/husain/src/linux/usr/gen_init_cpio.c:527: WARNING: space prohibited between function name and open parenthesis '('
/home/husain/src/linux/usr/gen_init_cpio.c:577: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:595: ERROR: space prohibited after that '!' (ctx:BxW)
/home/husain/src/linux/usr/gen_init_cpio.c:595: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:613: ERROR: space prohibited after that '!' (ctx:BxW)
/home/husain/src/linux/usr/gen_init_cpio.c:613: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:622: WARNING: Missing a blank line after declarations
/home/husain/src/linux/usr/gen_init_cpio.c:622: ERROR: space prohibited after that '!' (ctx:BxW)
/home/husain/src/linux/usr/gen_init_cpio.c:623: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:631: WARNING: Comparisons should place the constant on the right side of the test
total: 17 errors, 29 warnings, 640 lines checked
After applying the change:
/home/husain/src/linux/scripts/checkpatch.pl --file --terse --emacs /home/husain/src/linux/usr/gen_init_cpio.c
/home/husain/src/linux/usr/gen_init_cpio.c:76: WARNING: const array should probably be static const
/home/husain/src/linux/usr/gen_init_cpio.c:79: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:111: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:160: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:254: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:351: WARNING: quoted string split across lines
/home/husain/src/linux/usr/gen_init_cpio.c:581: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:599: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:617: ERROR: do not use assignment in if condition
/home/husain/src/linux/usr/gen_init_cpio.c:628: ERROR: do not use assignment in if condition
total: 4 errors, 6 warnings, 645 lines checked