Various coding style fixes checkpatch warns about. The goal is not to be 100% checkpatch compliant, but to have more consistent coding style. As this is a trivial patch serie, will land in 24 hours in klibc git, unless of course ml review hits a bugger. Checked with size(3) that the generated kinit, fstype, ipconfig and nfsmount are the same. maximilian attems (4): [klibc] ipconfig: reduce checkpatch noise [klibc] fstype: minor checkpatch fixes [klibc] nfsmount: various checkpatch fixes [klibc] kinit: checkpatch cleanup usr/kinit/devname.c | 6 +++- usr/kinit/do_mounts.c | 7 +++-- usr/kinit/do_mounts.h | 8 +++--- usr/kinit/do_mounts_md.c | 8 +++--- usr/kinit/fstype/fstype.c | 20 ++++++++++----- usr/kinit/ipconfig/dhcp_proto.c | 2 +- usr/kinit/ipconfig/main.c | 42 ++++++++++++++++----------------- usr/kinit/ipconfig/packet.c | 4 +- usr/kinit/nfsmount/dummypmap.c | 2 +- usr/kinit/nfsmount/main.c | 17 ++++++++----- usr/kinit/nfsmount/mount.c | 48 +++++++++++++++----------------------- usr/kinit/nfsmount/portmap.c | 10 ++++---- 12 files changed, 87 insertions(+), 87 deletions(-) -- 1.7.5.4
maximilian attems
2011-Jul-08 11:28 UTC
[klibc] [PATCH 1/4] ipconfig: reduce checkpatch noise
fix for better codingstyle:
ERROR: "foo * bar" should be "foo *bar"
..
ERROR: switch and case should be at the same indent
WARNING: braces {} are not necessary for single statement blocks
WARNING: labels should not be indented
..
WARNING: braces {} are not necessary for any arm of this statement
..
ERROR: do not use assignment in if condition
ERROR: space prohibited after that '&' (ctx:WxW)
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/ipconfig/dhcp_proto.c | 2 +-
usr/kinit/ipconfig/main.c | 42 ++++++++++++++++++--------------------
usr/kinit/ipconfig/packet.c | 4 +-
3 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
index 993db52..afd2eca 100644
--- a/usr/kinit/ipconfig/dhcp_proto.c
+++ b/usr/kinit/ipconfig/dhcp_proto.c
@@ -80,7 +80,7 @@ static struct iovec dhcp_request_iov[DHCP_IOV_LEN] = {
* 6 = DHCPNACK
*/
static int dhcp_parse(struct netdev *dev, struct bootp_hdr *hdr,
- uint8_t * exts, int extlen)
+ uint8_t *exts, int extlen)
{
uint8_t type = 0;
uint32_t serverid = INADDR_NONE;
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 8dc6cbe..8782ae7 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -100,19 +100,19 @@ static void configure_device(struct netdev *dev)
* Always start with a single quote ('), then leave all characters
* except ' and ! unchanged.
*/
-static void write_option(FILE* f, const char* name, const char* chr)
+static void write_option(FILE *f, const char *name, const char *chr)
{
fprintf(f, "%s='", name);
while (*chr) {
switch (*chr) {
- case '!':
- case '\'':
- fprintf(f, "'\\%c'", *chr);
- break;
- default:
- fprintf(f, "%c", *chr);
- break;
+ case '!':
+ case '\'':
+ fprintf(f, "'\\%c'", *chr);
+ break;
+ default:
+ fprintf(f, "%c", *chr);
+ break;
}
++chr;
}
@@ -341,9 +341,8 @@ static int do_pkt_recv(int pkt_fd, time_t now)
int ret = 0;
struct state *s;
- for (s = slist; s; s = s->next) {
+ for (s = slist; s; s = s->next)
ret |= process_receive_event(s, now);
- }
return ret;
}
@@ -430,7 +429,7 @@ static int loop(void)
timeout_ms -= delta_ms;
}
}
- bail:
+bail:
packet_close();
return rc;
@@ -451,13 +450,12 @@ static int add_one_dev(struct netdev *dev)
/*
* Select the state that we start from.
*/
- if (dev->caps & CAP_DHCP && dev->ip_addr == INADDR_ANY) {
+ if (dev->caps & CAP_DHCP && dev->ip_addr == INADDR_ANY)
state->restart_state = state->state = DEVST_DHCPDISC;
- } else if (dev->caps & CAP_DHCP) {
+ else if (dev->caps & CAP_DHCP)
state->restart_state = state->state = DEVST_DHCPREQ;
- } else if (dev->caps & CAP_BOOTP) {
+ else if (dev->caps & CAP_BOOTP)
state->restart_state = state->state = DEVST_BOOTP;
- }
state->next = slist;
slist = state;
@@ -465,7 +463,7 @@ static int add_one_dev(struct netdev *dev)
return 0;
}
-static void parse_addr(uint32_t * addr, const char *ip)
+static void parse_addr(uint32_t *addr, const char *ip)
{
struct in_addr in;
if (inet_aton(ip, &in) == 0) {
@@ -497,7 +495,7 @@ static unsigned int parse_proto(const char *ip)
fprintf(stderr, "%s: invalid protocol '%s'\n", progname,
ip);
longjmp(abort_buf, 1);
}
- bail:
+bail:
return caps;
}
@@ -584,11 +582,10 @@ static int parse_device(struct netdev *dev, const char
*ip)
static void bringup_device(struct netdev *dev)
{
if (netdev_up(dev) == 0) {
- if (dev->caps) {
+ if (dev->caps)
add_one_dev(dev);
- } else {
+ else
complete_device(dev);
- }
}
}
@@ -646,7 +643,7 @@ static struct netdev *add_device(const char *info)
dev->caps & CAP_BOOTP ? " BOOTP" : "",
dev->caps & CAP_RARP ? " RARP" : "");
return dev;
- bail:
+bail:
free(dev);
return NULL;
}
@@ -694,7 +691,8 @@ static int add_all_devices(struct netdev *template)
(flags & (IFF_BROADCAST | IFF_POINTOPOINT))) {
dprintf("Trying to bring up %s\n", de->d_name);
- if (!(dev = add_device(de->d_name)))
+ dev = add_device(de->d_name);
+ if (!dev)
continue;
bringup_one_dev(template, dev);
}
diff --git a/usr/kinit/ipconfig/packet.c b/usr/kinit/ipconfig/packet.c
index ea5a25d..446073a 100644
--- a/usr/kinit/ipconfig/packet.c
+++ b/usr/kinit/ipconfig/packet.c
@@ -156,7 +156,7 @@ int packet_send(struct netdev *dev, struct iovec *iov, int
iov_len)
ipudp_hdrs.ip.tot_len = htons(len);
ipudp_hdrs.ip.check = 0;
- ipudp_hdrs.ip.check = ip_checksum((uint16_t *) & ipudp_hdrs.ip,
+ ipudp_hdrs.ip.check = ip_checksum((uint16_t *) &ipudp_hdrs.ip,
ipudp_hdrs.ip.ihl);
ipudp_hdrs.udp.len = htons(len - sizeof(struct iphdr));
@@ -186,7 +186,7 @@ void packet_discard(struct netdev *dev)
* 0 = Discarded packet (non-DHCP/BOOTP traffic)
* >0 = Size of packet
*/
-int packet_recv(struct netdev* dev, struct iovec *iov, int iov_len)
+int packet_recv(struct netdev *dev, struct iovec *iov, int iov_len)
{
struct iphdr *ip, iph;
struct udphdr *udp;
--
1.7.5.4
maximilian attems
2011-Jul-08 11:28 UTC
[klibc] [PATCH 2/4] fstype: minor checkpatch fixes
ERROR: do not use assignment in if condition
..
WARNING: line over 80 characters
ERROR: space prohibited after that '-' (ctx:WxW)
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/fstype/fstype.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index 9f0f931..2e26c9a 100644
--- a/usr/kinit/fstype/fstype.c
+++ b/usr/kinit/fstype/fstype.c
@@ -133,11 +133,14 @@ static int fs_proc_check(const char *fs_name)
}
while (*cp && isspace(*cp))
cp++;
- if ((t = strchr(cp, '\n')) != NULL)
+ t = strchr(cp, '\n');
+ if (t != NULL)
*t = 0;
- if ((t = strchr(cp, '\t')) != NULL)
+ t = strchr(cp, '\t');
+ if (t != NULL)
*t = 0;
- if ((t = strchr(cp, ' ')) != NULL)
+ t = strchr(cp, ' ');
+ if (t != NULL)
*t = 0;
if (!strcmp(fs_name, cp)) {
fclose(f);
@@ -167,11 +170,13 @@ static int check_for_modules(const char *fs_name)
if (!f)
return 0;
while (fgets(buf, sizeof(buf), f)) {
- if ((cp = strchr(buf, ':')) != NULL)
+ cp = strchr(buf, ':');
+ if (cp != NULL)
*cp = 0;
else
continue;
- if ((cp = strrchr(buf, '/')) != NULL)
+ cp = strrchr(buf, '/');
+ if (cp != NULL)
cp++;
i = strlen(cp);
if (i > 3) {
@@ -318,7 +323,8 @@ static int jfs_image(const void *buf, unsigned long long
*bytes)
const struct jfs_superblock *sb = (const struct jfs_superblock *)buf;
if (!memcmp(sb->s_magic, JFS_MAGIC, 4)) {
- *bytes = __le64_to_cpu(sb->s_size) <<
__le16_to_cpu(sb->s_l2pbsize);
+ *bytes = __le64_to_cpu(sb->s_size)
+ << __le16_to_cpu(sb->s_l2pbsize);
return 1;
}
return 0;
@@ -516,7 +522,7 @@ int identify_fs(int fd, const char **fstype,
unsigned long long *bytes, off_t offset)
{
uint64_t buf[BLOCK_SIZE >> 3]; /* 64-bit worst case alignment */
- off_t cur_block = (off_t) - 1;
+ off_t cur_block = (off_t) -1;
struct imagetype *ip;
int ret;
unsigned long long dummy;
--
1.7.5.4
maximilian attems
2011-Jul-08 11:28 UTC
[klibc] [PATCH 3/4] nfsmount: various checkpatch fixes
fix:
ERROR: "foo * bar" should be "foo *bar"
ERROR: do not use assignment in if condition
..
ERROR: space required before that '!' (ctx:VxW)
ERROR: space prohibited after that '!' (ctx:VxW)
WARNING: suspect code indent for conditional statements (16, 18)
WARNING: braces {} are not necessary for single statement blocks
..
WARNING: braces {} are not necessary for any arm of this statement
..
WARNING: labels should not be indented
..
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/nfsmount/dummypmap.c | 2 +-
usr/kinit/nfsmount/main.c | 17 ++++++++-----
usr/kinit/nfsmount/mount.c | 48 +++++++++++++++------------------------
usr/kinit/nfsmount/portmap.c | 10 ++++----
4 files changed, 35 insertions(+), 42 deletions(-)
diff --git a/usr/kinit/nfsmount/dummypmap.c b/usr/kinit/nfsmount/dummypmap.c
index e5ebef9..7c5b6bc 100644
--- a/usr/kinit/nfsmount/dummypmap.c
+++ b/usr/kinit/nfsmount/dummypmap.c
@@ -71,7 +71,7 @@ static const char *protoname(uint32_t proto)
}
}
-static void * get_auth(struct rpc_auth *auth)
+static void *get_auth(struct rpc_auth *auth)
{
switch (ntohl(auth->flavor)) {
case AUTH_NULL:
diff --git a/usr/kinit/nfsmount/main.c b/usr/kinit/nfsmount/main.c
index b85901a..36b29a5 100644
--- a/usr/kinit/nfsmount/main.c
+++ b/usr/kinit/nfsmount/main.c
@@ -102,7 +102,8 @@ static void parse_opts(char *opts)
while ((cp = strsep(&opts, ",")) != NULL) {
if (*cp == '\0')
continue;
- if ((val = strchr(cp, '=')) != NULL) {
+ val = strchr(cp, '=');
+ if (val != NULL) {
struct int_opts *opts = int_opts;
*val++ = '\0';
while (opts->name && strcmp(opts->name, cp) != 0)
@@ -207,12 +208,14 @@ int nfsmount_main(int argc, char *argv[])
hostname = rem_path = argv[optind];
- if ((rem_name = strdup(rem_path)) == NULL) {
+ rem_name = strdup(rem_path);
+ if (rem_name == NULL) {
perror("strdup");
return 1;
}
- if ((rem_path = strchr(rem_path, ':')) == NULL) {
+ rem_path = strchr(rem_path, ':');
+ if (rem_path == NULL) {
fprintf(stderr, "%s: need a server\n", progname);
free(rem_name);
return 1;
@@ -235,7 +238,7 @@ int nfsmount_main(int argc, char *argv[])
check_path(path);
-#if! _KLIBC_NO_MMU
+#if !_KLIBC_NO_MMU
/* Note: uClinux can't fork(), so the spoof portmapper is not
available on uClinux. */
if (portmap_file)
@@ -255,9 +258,9 @@ int nfsmount_main(int argc, char *argv[])
/* If we set up the spoofer, tear it down now */
if (spoof_portmap) {
kill(spoof_portmap, SIGTERM);
- while (waitpid(spoof_portmap, NULL, 0) == -1 &&
- errno == EINTR)
- ;
+ while (waitpid(spoof_portmap, NULL, 0) == -1
+ && errno == EINTR)
+ ;
}
free(rem_name);
diff --git a/usr/kinit/nfsmount/mount.c b/usr/kinit/nfsmount/mount.c
index d0eca8a..e3838f4 100644
--- a/usr/kinit/nfsmount/mount.c
+++ b/usr/kinit/nfsmount/mount.c
@@ -155,7 +155,8 @@ static int mount_call(uint32_t proc, uint32_t version,
path_len = strlen(path);
call_len = sizeof(*mnt_call) + pad_len(path_len);
- if ((mnt_call = malloc(call_len)) == NULL) {
+ mnt_call = malloc(call_len);
+ if (mnt_call == NULL) {
perror("malloc");
goto bail;
}
@@ -176,9 +177,8 @@ static int mount_call(uint32_t proc, uint32_t version,
if (rpc_call(clnt, &rpc) < 0)
goto bail;
- if (proc != MNTPROC_MNT) {
+ if (proc != MNTPROC_MNT)
goto done;
- }
if (rpc.reply_len < MNT_REPLY_MINSIZE) {
fprintf(stderr, "incomplete reply: %zu < %zu\n",
@@ -198,9 +198,8 @@ bail:
ret = -1;
done:
- if (mnt_call) {
+ if (mnt_call)
free(mnt_call);
- }
return ret;
}
@@ -262,38 +261,32 @@ int nfs_mount(const char *pathname, const char *hostname,
int ret = 0;
int mountflags;
- if (get_ports(server, data) != 0) {
+ if (get_ports(server, data) != 0)
goto bail;
- }
dump_params(server, rem_path, data);
- if (data->flags & NFS_MOUNT_TCP) {
+ if (data->flags & NFS_MOUNT_TCP)
clnt = tcp_client(server, mount_port, CLI_RESVPORT);
- } else {
+ else
clnt = udp_client(server, mount_port, CLI_RESVPORT);
- }
- if (clnt == NULL) {
+ if (clnt == NULL)
goto bail;
- }
- if (data->flags & NFS_MOUNT_VER3) {
+ if (data->flags & NFS_MOUNT_VER3)
ret = mount_v3(rem_path, data, clnt);
- } else {
+ else
ret = mount_v2(rem_path, data, clnt);
- }
- if (ret == -1) {
+ if (ret == -1)
goto bail;
- }
mounted = 1;
- if (data->flags & NFS_MOUNT_TCP) {
+ if (data->flags & NFS_MOUNT_TCP)
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- } else {
+ else
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
- }
if (sock == -1) {
perror("socket");
@@ -333,25 +326,22 @@ int nfs_mount(const char *pathname, const char *hostname,
goto done;
- bail:
+bail:
if (mounted) {
- if (data->flags & NFS_MOUNT_VER3) {
+ if (data->flags & NFS_MOUNT_VER3)
umount_v3(path, clnt);
- } else {
+ else
umount_v2(path, clnt);
- }
}
ret = -1;
- done:
- if (clnt) {
+done:
+ if (clnt)
client_free(clnt);
- }
- if (sock != -1) {
+ if (sock != -1)
close(sock);
- }
return ret;
}
diff --git a/usr/kinit/nfsmount/portmap.c b/usr/kinit/nfsmount/portmap.c
index ff79d04..0a3e2d0 100644
--- a/usr/kinit/nfsmount/portmap.c
+++ b/usr/kinit/nfsmount/portmap.c
@@ -35,10 +35,11 @@ uint32_t portmap(uint32_t server, uint32_t program, uint32_t
version, uint32_t p
struct rpc rpc;
uint32_t port = 0;
- if ((clnt = tcp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
- if ((clnt = udp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
+ clnt = tcp_client(server, RPC_PMAP_PORT, 0);
+ if (clnt == NULL) {
+ clnt = udp_client(server, RPC_PMAP_PORT, 0);
+ if (clnt == NULL)
goto bail;
- }
}
call.program = htonl(program);
@@ -65,9 +66,8 @@ bail:
dprintf("Port for %d/%d[%s]: %d\n", program, version,
proto == IPPROTO_TCP ? "tcp" : "udp", port);
- if (clnt) {
+ if (clnt)
client_free(clnt);
- }
return port;
}
--
1.7.5.4
fix:
ERROR: do not use assignment in if condition
..
WARNING: line over 80 characters
..
WARNING: labels should not be indented
..
ERROR: space required after that ',' (ctx:VxV)
..
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/devname.c | 6 ++++--
usr/kinit/do_mounts.c | 7 ++++---
usr/kinit/do_mounts.h | 8 ++++----
usr/kinit/do_mounts_md.c | 8 ++++----
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/usr/kinit/devname.c b/usr/kinit/devname.c
index 03f360e..c327e3b 100644
--- a/usr/kinit/devname.c
+++ b/usr/kinit/devname.c
@@ -25,7 +25,8 @@ static int scansysdir(char *namebuf, char *sysdir, dev_t dev)
char *ep;
ssize_t rd;
- if (!(dir = opendir(sysdir)))
+ dir = opendir(sysdir);
+ if (!dir)
return 0;
*dirtailptr++ = '/';
@@ -46,7 +47,8 @@ static int scansysdir(char *namebuf, char *sysdir, dev_t dev)
systail = strchr(sysdir, '\0');
strcpy(systail, "/dev");
- if (!(sysdev = fopen(sysdir, "r")))
+ sysdev = fopen(sysdir, "r");
+ if (!sysdev)
continue;
/* Abusing the namebuf as temporary storage here. */
diff --git a/usr/kinit/do_mounts.c b/usr/kinit/do_mounts.c
index 6384042..3ffac91 100644
--- a/usr/kinit/do_mounts.c
+++ b/usr/kinit/do_mounts.c
@@ -78,7 +78,8 @@ const char *mount_block(const char *source, const char
*target,
if (!p)
break;
*p++ = '\0';
- if (*type != '\t') /* We can't mount a block device as a
"nodev" fs */
+ /* We can't mount a block device as a "nodev" fs */
+ if (*type != '\t')
continue;
type++;
@@ -116,7 +117,7 @@ mount_block_root(int argc, char *argv[], dev_t root_dev,
&& (rp = mount_block("/dev/root", "/root",
NULL, flags, data)))
goto ok;
- bad:
+bad:
if (errno != EINVAL) {
/*
* Allow the user to distinguish between failed open
@@ -131,7 +132,7 @@ mount_block_root(int argc, char *argv[], dev_t root_dev,
return -ESRCH;
}
- ok:
+ok:
printf("%s: Mounted root (%s filesystem)%s.\n",
progname, rp, (flags & MS_RDONLY) ? " readonly" :
"");
return 0;
diff --git a/usr/kinit/do_mounts.h b/usr/kinit/do_mounts.h
index c309289..99bc6a6 100644
--- a/usr/kinit/do_mounts.h
+++ b/usr/kinit/do_mounts.h
@@ -9,12 +9,12 @@
#include <sys/sysmacros.h>
#include <sys/stat.h>
-#define Root_RAM0 __makedev(1,0)
+#define Root_RAM0 __makedev(1, 0)
/* These device numbers are only used internally */
-#define Root_NFS __makedev(0,255)
-#define Root_MTD __makedev(0,254)
-#define Root_MULTI __makedev(0,253)
+#define Root_NFS __makedev(0, 255)
+#define Root_MTD __makedev(0, 254)
+#define Root_MULTI __makedev(0, 253)
int create_dev(const char *name, dev_t dev);
diff --git a/usr/kinit/do_mounts_md.c b/usr/kinit/do_mounts_md.c
index 7c6ed8d..f446620 100644
--- a/usr/kinit/do_mounts_md.c
+++ b/usr/kinit/do_mounts_md.c
@@ -204,7 +204,7 @@ static int md_setup(char *str)
}
fprintf(stderr, "md: Will configure md%s%d (%s) from %s, below.\n",
- partitioned?"_d":"", minor_num, pername, str);
+ partitioned ? "_d" : "", minor_num, pername, str);
md_setup_args[ent].device_names = str;
md_setup_args[ent].partitioned = partitioned;
md_setup_args[ent].minor = minor_num;
@@ -330,9 +330,9 @@ static void md_setup_drive(void)
dev_minor);
else {
/* reread the partition table.
- * I (neilb) and not sure why this is needed, but I cannot
- * boot a kernel with devfs compiled in from partitioned md
- * array without it
+ * I (neilb) and not sure why this is needed, but I
+ * cannot boot a kernel with devfs compiled in from
+ * partitioned md array without it
*/
close(fd);
fd = open(name, 0, 0);
--
1.7.5.4