[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211206032840.531625-1-husain@alshehhi.io>
Date: Mon, 06 Dec 2021 03:28:54 +0000
From: husain@...hehhi.io
To: masahiroy@...nel.org
Cc: linux-kernel@...r.kernel.org, trivial@...nel.org,
Husain Alshehhi <husain@...hehhi.io>
Subject: [PATCH] Fix styling issues reported by checkpatch in usr/gen_init_cpio.c
From: Husain Alshehhi <husain@...hehhi.io>
Signed-off-by: Husain Alshehhi <husain@...hehhi.io>
---
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
Powered by blists - more mailing lists