From 2672f5eb94c2a8bd417ff00013f03602798273d4 Mon Sep 17 00:00:00 2001 From: Zeng Heng Date: Mon, 15 Aug 2022 11:26:06 +0800 Subject: [PATCH] checkpatch --- boot/Makefile | 2 - boot/sign.py | 2 - checkpatch.sh | 20 +++++---- fs/fs.c | 2 +- fs/test.c | 2 +- include/boot/mmu.h | 8 ++-- include/mmu.h | 4 +- net/input.c | 7 ++-- net/output.c | 6 +-- net/serv.c | 43 +++++++++---------- net/testinput.c | 96 ++++++++++++++++++++++--------------------- net/testoutput.c | 48 +++++++++++----------- net/testthread.c | 2 +- net/timer.c | 2 +- scripts/checkpatch.pl | 36 +++++++++------- user/httpd.c | 3 +- 16 files changed, 146 insertions(+), 137 deletions(-) diff --git a/boot/Makefile b/boot/Makefile index 9c3c612..82330fa 100755 --- a/boot/Makefile +++ b/boot/Makefile @@ -1,6 +1,4 @@ # -# boot/Makefile -# # Copyright (C) 2018 Henry.Zeng # # This program is free software; you can redistribute it and/or modify diff --git a/boot/sign.py b/boot/sign.py index f7f0eb6..7374fc8 100755 --- a/boot/sign.py +++ b/boot/sign.py @@ -1,6 +1,4 @@ # -# boot/sign.py -# # Copyright (C) 2018 Henry.Zeng # # This program is free software; you can redistribute it and/or modify diff --git a/checkpatch.sh b/checkpatch.sh index 66c868a..b5edab7 100755 --- a/checkpatch.sh +++ b/checkpatch.sh @@ -1,9 +1,13 @@ -./scripts/checkpatch.pl -f -q --no-tree include/*.[cSh] \ - include/*/*.[cSh] \ - include/arch/*/*.[cSh] \ - boot/*.[cSh] \ - kernel/*.[cSh] \ - lib/*.[cSh] \ - user/*.[cSh] - fs/*.[cSh] \ +./scripts/checkpatch.pl -f -q --no-tree include/*.h \ + include/*/*.h \ + include/arch/i386/*.h \ + boot/* \ + kernel/* \ + lib/* \ + user/* \ + fs/* \ + +./scripts/checkpatch.pl -f -q --no-tree Makefile \ + +./scripts/checkpatch.pl -f -q --no-tree net/Makefile \ net/*.[cSh] \ diff --git a/fs/fs.c b/fs/fs.c index 628cae8..33dace1 100755 --- a/fs/fs.c +++ b/fs/fs.c @@ -1,7 +1,7 @@ #include #include -#define BLKNO2ADDR(x) (void *)(DISKMAP + x * BLKSIZE) +#define BLKNO2ADDR(x) ((void *)(DISKMAP + x * BLKSIZE)) // -------------------------------------------------------------- // Super block diff --git a/fs/test.c b/fs/test.c index 99e4f65..63c270e 100644 --- a/fs/test.c +++ b/fs/test.c @@ -41,7 +41,7 @@ fs_test(void) panic("file_get_block returned wrong data"); cprintf("file_get_block is good\n"); - *(volatile char*)blk = *(volatile char*)blk; + *(volatile char *)blk = *(volatile char *)blk; assert((uvpt[PGNUM(blk)] & PTE_D)); file_flush(f); assert(!(uvpt[PGNUM(blk)] & PTE_D)); diff --git a/include/boot/mmu.h b/include/boot/mmu.h index 3b47d50..29657d0 100755 --- a/include/boot/mmu.h +++ b/include/boot/mmu.h @@ -76,7 +76,7 @@ struct segdesc { // Normal segment #define SEG(type, base, lim, dpl) \ - (struct segdesc) { \ + ((struct segdesc) { \ ((lim) >> 12) & 0xffff, \ (uint)(base) & 0xffff, \ ((uint)(base) >> 16) & 0xff, \ @@ -90,9 +90,9 @@ struct segdesc { 1, \ 1, \ (uint)(base) >> 24, \ - } + }) #define SEG16(type, base, lim, dpl) \ - (struct segdesc) { \ + ((struct segdesc) { \ (lim) & 0xffff, \ (uint)(base) & 0xffff, \ ((uint)(base) >> 16) & 0xff, \ @@ -106,7 +106,7 @@ struct segdesc { 1, \ 0, \ (uint)(base) >> 24, \ - } + }) #endif #define DPL_USER 0x3 // User DPL diff --git a/include/mmu.h b/include/mmu.h index bcd30af..d8bc5b3 100755 --- a/include/mmu.h +++ b/include/mmu.h @@ -194,7 +194,7 @@ struct Segdesc { } #define SEG16(type, base, lim, dpl) \ - (struct Segdesc) { \ + ((struct Segdesc) { \ (lim) & 0xffff, \ (base) & 0xffff, \ ((base) >> 16) & 0xff, \ @@ -208,7 +208,7 @@ struct Segdesc { 1, \ 0, \ (unsigned int) (base) >> 24, \ - } + }) #endif /* !__ASSEMBLER__ */ diff --git a/net/input.c b/net/input.c index 81d42ef..c36929c 100755 --- a/net/input.c +++ b/net/input.c @@ -32,10 +32,9 @@ input(envid_t ns_envid) if (ret == -E_IPC_NOT_RECV) sys_yield(); else - panic("input: sys_ipc_try_send failed\n"); + panic("%s: sys_ipc_try_send failed\n", __func__); } else { - /* - * Actually we don't need to unmap nsipcbuf, + /* Actually we don't need to unmap nsipcbuf, * because it will be remapped in next routine. */ sys_page_unmap(0, &nsipcbuf); @@ -43,4 +42,4 @@ input(envid_t ns_envid) } } } -} \ No newline at end of file +} diff --git a/net/output.c b/net/output.c index 33d33de..2a2a24f 100755 --- a/net/output.c +++ b/net/output.c @@ -9,13 +9,13 @@ output(envid_t ns_envid) int ret; while (1) { - // - read a packet from the network server + // - read a packet from the network server ret = sys_ipc_recv(&nsipcbuf); if (ret) continue; if (thisenv->env_ipc_from != ns_envid || - thisenv->env_ipc_value != NSREQ_OUTPUT) + thisenv->env_ipc_value != NSREQ_OUTPUT) continue; // - send the packet to the device driver @@ -23,4 +23,4 @@ output(envid_t ns_envid) if (ret) panic("Output ENV fail to transmit packets"); } -} \ No newline at end of file +} diff --git a/net/serv.c b/net/serv.c index ae3e550..0b3739f 100755 --- a/net/serv.c +++ b/net/serv.c @@ -16,7 +16,7 @@ #define debug 0 -int errno = 0; +int errno; struct timer_thread { uint32_t msec; @@ -52,18 +52,17 @@ tcpip_init_done(void *arg) static void lwip_init(struct netif *nif, void *if_state, - uint32_t init_addr, uint32_t init_mask, uint32_t init_gw) + uint32_t init_addr, uint32_t init_mask, uint32_t init_gw) { struct ip_addr ipaddr, netmask, gateway; + ipaddr.addr = init_addr; netmask.addr = init_mask; gateway.addr = init_gw; - if (0 == netif_add(nif, &ipaddr, &netmask, &gateway, - if_state, - jif_init, - ip_input)) - panic("lwip_init: error in netif_add\n"); + if (netif_add(nif, &ipaddr, &netmask, &gateway, + if_state, jif_init, ip_input) == 0) + panic("%s: error in netif_add\n", __func__); netif_set_default(nif); netif_set_up(nif); @@ -105,6 +104,7 @@ serve_init(uint32_t ipaddr, uint32_t netmask, uint32_t gw) lwip_core_lock(); uint32_t done = 0; + tcpip_init(&tcpip_init_done, &done); lwip_core_unlock(); thread_wait(&done, 0, (uint32_t)~0); @@ -117,8 +117,8 @@ serve_init(uint32_t ipaddr, uint32_t netmask, uint32_t gw) start_timer(&t_tcps, &tcp_slowtmr, "tcp s timer", TCP_SLOW_INTERVAL); struct in_addr ia = {ipaddr}; - cprintf("ns: %02x:%02x:%02x:%02x:%02x:%02x" - " bound to static IP %s\n", + + cprintf("ns: %02x:%02x:%02x:%02x:%02x:%02x bound to static IP %s\n", nif.hwaddr[0], nif.hwaddr[1], nif.hwaddr[2], nif.hwaddr[3], nif.hwaddr[4], nif.hwaddr[5], inet_ntoa(ia)); @@ -153,6 +153,7 @@ static void put_buffer(void *va) { int i = ((uint32_t)va - REQVA) / PGSIZE; + buse[i] = 0; } @@ -162,8 +163,7 @@ process_timer(envid_t envid) uint32_t start, now, to; if (envid != timer_envid) { - cprintf("NS: received timer interrupt from envid %x" - " not timer env\n", envid); + cprintf("NS: received timer interrupt from envid %x not timer env\n", envid); return; } @@ -171,7 +171,7 @@ process_timer(envid_t envid) thread_yield(); now = sys_time_msec(); - to = TIMER_INTERVAL - (now -start); + to = TIMER_INTERVAL - (now - start); ipc_send(envid, to, NULL, 0); } @@ -217,7 +217,7 @@ serve_thread(uint32_t a) // Note that we read the request fields before we // overwrite it with the response data. r = lwip_recv(req->recv.req_s, req->recvRet.ret_buf, - req->recv.req_len, req->recv.req_flags); + req->recv.req_len, req->recv.req_flags); break; case NSREQ_SEND: @@ -243,6 +243,7 @@ serve_thread(uint32_t a) if (r < 0) { char buf[100]; + snprintf(buf, sizeof(buf), "ns req type %d", args->reqno); perror(buf); } @@ -292,6 +293,7 @@ serve(void) // Since some lwIP socket calls will block, create a thread and // process the rest of the request in the thread. struct st_args *args = malloc(sizeof(struct st_args)); + if (!args) panic("could not allocate thread args structure"); @@ -302,7 +304,6 @@ serve(void) thread_create(NULL, "serve_thread", serve_thread, (uint32_t)args); thread_yield(); // let the thread created run } - } static void @@ -321,9 +322,9 @@ umain(int argc, char **argv) // fork off the timer thread which will send us periodic messages timer_envid = fork(); - if (timer_envid < 0) + if (timer_envid < 0) { panic("error forking"); - else if (timer_envid == 0) { + } else if (timer_envid == 0) { /* as the timer of thread scheduler */ timer(ns_envid, TIMER_INTERVAL); return; @@ -331,18 +332,18 @@ umain(int argc, char **argv) // fork off the input thread which will poll the NIC driver for input packets input_envid = fork(); - if (input_envid < 0) + if (input_envid < 0) { panic("error forking"); - else if (input_envid == 0) { + } else if (input_envid == 0) { input(ns_envid); return; } // fork off the output thread that will send the packets to the NIC driver output_envid = fork(); - if (output_envid < 0) + if (output_envid < 0) { panic("error forking"); - else if (output_envid == 0) { + } else if (output_envid == 0) { output(ns_envid); return; } @@ -353,4 +354,4 @@ umain(int argc, char **argv) thread_create(NULL, "main", tmain, 0); thread_yield(); // never coming here! -} \ No newline at end of file +} diff --git a/net/testinput.c b/net/testinput.c index 592580c..0cdac17 100644 --- a/net/testinput.c +++ b/net/testinput.c @@ -8,27 +8,28 @@ static struct jif_pkt *pkt = (struct jif_pkt *)REQVA; static void announce(void) { - // We need to pre-announce our IP so we don't have to deal + // We need to pre-announce our IP so we don't have to deal // with ARP requests. Ideally, we would use gratuitous ARP // for this, but QEMU's ARP implementation is dumb and only // listens for very specific ARP requests, such as requests // for the gateway IP. - uint8_t mac[6] = {0x52, 0x54, 0x00, 0x12, 0x34, 0x56}; - uint32_t myip = inet_addr(IP); - uint32_t gwip = inet_addr(DEFAULT); - int ret; + uint8_t mac[6] = {0x52, 0x54, 0x00, 0x12, 0x34, 0x56}; + uint32_t myip = inet_addr(IP); + uint32_t gwip = inet_addr(DEFAULT); + int ret; - ret = sys_page_alloc(0, pkt, PTE_W); - if (ret < 0) + ret = sys_page_alloc(0, pkt, PTE_W); + if (ret < 0) panic("sys_page_map: %e", ret); - struct etharp_hdr *arp = (struct etharp_hdr *)pkt->jp_data; - pkt->jp_len = sizeof(*arp); + struct etharp_hdr *arp = (struct etharp_hdr *)pkt->jp_data; - memset(arp->ethhdr.dest.addr, 0xFF, ETHARP_HWADDR_LEN); - memcpy(arp->ethhdr.src.addr, mac, ETHARP_HWADDR_LEN); - arp->ethhdr.type = htons(ETHTYPE_ARP); + pkt->jp_len = sizeof(*arp); + + memset(arp->ethhdr.dest.addr, 0xFF, ETHARP_HWADDR_LEN); + memcpy(arp->ethhdr.src.addr, mac, ETHARP_HWADDR_LEN); + arp->ethhdr.type = htons(ETHTYPE_ARP); arp->hwtype = htons(1); // Ethernet arp->proto = htons(ETHTYPE_IP); arp->_hwlen_protolen = htons((ETHARP_HWADDR_LEN << 8) | 4); @@ -38,8 +39,8 @@ announce(void) memset(arp->dhwaddr.addr, 0x00, ETHARP_HWADDR_LEN); memcpy(arp->dipaddr.addrw, &gwip, 4); - ipc_send(output_envid, NSREQ_OUTPUT, pkt, PTE_W); - sys_page_unmap(0, pkt); + ipc_send(output_envid, NSREQ_OUTPUT, pkt, PTE_W); + sys_page_unmap(0, pkt); } static void @@ -49,10 +50,11 @@ hexdump(const char *prefix, const void *data, int len) char buf[80]; char *end = buf + sizeof(buf); char *out = NULL; + for (i = 0; i < len; i++) { if (i % 16 == 0) out = buf + snprintf(buf, end - buf, - "%s%04x ", prefix, i); + "%s%04x ", prefix, i); out += snprintf(out, end - out, "%02x", ((uint8_t *)data)[i]); if (i % 16 == 15 || i == len - 1) cprintf("%.*s\n", out - buf, buf); @@ -66,48 +68,48 @@ hexdump(const char *prefix, const void *data, int len) void umain(int argc, char **argv) { - envid_t ns_envid = sys_getenvid(); - int first = 1; + envid_t ns_envid = sys_getenvid(); + int first = 1; - output_envid = fork(); - if (output_envid < 0) + output_envid = fork(); + if (output_envid < 0) { panic("error forking"); - else if (output_envid == 0) { - output(ns_envid); - return; - } + } else if (output_envid == 0) { + output(ns_envid); + return; + } - input_envid = fork(); - if (input_envid < 0) + input_envid = fork(); + if (input_envid < 0) { panic("error forking"); - else if (input_envid == 0) { - input(ns_envid); - return; - } + } else if (input_envid == 0) { + input(ns_envid); + return; + } - /* Address Resolution Protocol */ + /* Address Resolution Protocol */ cprintf("Sending ARP announcement...\n"); - announce(); + announce(); - while (1) { - envid_t whom; - int perm; - int ret = ipc_recv(&whom, pkt, &perm); + while (1) { + envid_t whom; + int perm; + int ret = ipc_recv(&whom, pkt, &perm); - if (ret < 0) + if (ret < 0) panic("ipc_recv: %e", ret); - if (whom != input_envid) - panic("IPC from unexpected environment %08x", whom); - if (ret != NSREQ_INPUT) - panic("Unexpected IPC %d", ret); + if (whom != input_envid) + panic("IPC from unexpected environment %08x", whom); + if (ret != NSREQ_INPUT) + panic("Unexpected IPC %d", ret); - hexdump("input: ", pkt->jp_data, pkt->jp_len); - cprintf("\n"); + hexdump("input: ", pkt->jp_data, pkt->jp_len); + cprintf("\n"); // Only indicate that we're waiting for packets once // we've received the ARP reply - if (first) - cprintf("Waiting for packets...\n"); - first = 0; - } -} \ No newline at end of file + if (first) + cprintf("Waiting for packets...\n"); + first = 0; + } +} diff --git a/net/testoutput.c b/net/testoutput.c index af5c6bf..0d39a27 100644 --- a/net/testoutput.c +++ b/net/testoutput.c @@ -10,31 +10,31 @@ static struct jif_pkt *pkt = (struct jif_pkt *)REQVA; void umain(int argc, char **argv) { - envid_t ns_envid = sys_getenvid(); - int i, ret; + envid_t ns_envid = sys_getenvid(); + int i, ret; - output_envid = fork(); - if (output_envid < 0) - panic("error forking"); - else if (output_envid == 0) { - output(ns_envid); - return; - } + output_envid = fork(); + if (output_envid < 0) { + panic("error forking"); + } else if (output_envid == 0) { + output(ns_envid); + return; + } - for (i = 0; i < TESTOUTPUT_COUNT; i++) { - ret = sys_page_alloc(0, pkt, PTE_W); - if (ret < 0) - panic("sys_page_alloc: %e", ret); + for (i = 0; i < TESTOUTPUT_COUNT; i++) { + ret = sys_page_alloc(0, pkt, PTE_W); + if (ret < 0) + panic("sys_page_alloc: %e", ret); - pkt->jp_len = snprintf(pkt->jp_data, - MAX_JIF_LEN, - "Packet %02d", i); - cprintf("Transmitting packet %d\n", i); - ipc_send(output_envid, NSREQ_OUTPUT, pkt, PTE_W); - sys_page_unmap(0, pkt); - } + pkt->jp_len = snprintf(pkt->jp_data, + MAX_JIF_LEN, + "Packet %02d", i); + cprintf("Transmitting packet %d\n", i); + ipc_send(output_envid, NSREQ_OUTPUT, pkt, PTE_W); + sys_page_unmap(0, pkt); + } - // Spin for a while, just in case IPC's or packets need to be flushed - for (i = 0; i < TESTOUTPUT_COUNT * 2; i++) - sys_yield(); -} \ No newline at end of file + // Spin for a while, just in case IPC's or packets need to be flushed + for (i = 0; i < TESTOUTPUT_COUNT * 2; i++) + sys_yield(); +} diff --git a/net/testthread.c b/net/testthread.c index 9faaed6..b235b46 100644 --- a/net/testthread.c +++ b/net/testthread.c @@ -15,4 +15,4 @@ umain(int argc, char **argv) thread_create(NULL, "main", tmain, 0); thread_yield(); /* never return */ -} \ No newline at end of file +} diff --git a/net/timer.c b/net/timer.c index 3d0e820..202c6ad 100644 --- a/net/timer.c +++ b/net/timer.c @@ -35,4 +35,4 @@ timer(envid_t envid, uint32_t initial_to) break; } } -} \ No newline at end of file +} diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9aaec39..2d162c7 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -56,7 +56,7 @@ my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; -my $max_line_length = 100; +my $max_line_length = 150; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; @@ -3634,6 +3634,7 @@ sub process { if ($comment !~ /^$/ && $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) { + # close warning # WARN("SPDX_LICENSE_TAG", # "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) { @@ -3842,12 +3843,13 @@ sub process { if ($newindent ne $goodtabindent && $newindent ne $goodspaceindent) { - if (CHK("PARENTHESIS_ALIGNMENT", - "Alignment should match open parenthesis\n" . $hereprev) && - $fix && $line =~ /^\+/) { - $fixed[$fixlinenr] =~ - s/^\+[ \t]*/\+$goodtabindent/; - } + # close check + # if (CHK("PARENTHESIS_ALIGNMENT", + # "Alignment should match open parenthesis\n" . $hereprev) && + # $fix && $line =~ /^\+/) { + # $fixed[$fixlinenr] =~ + # s/^\+[ \t]*/\+$goodtabindent/; + # } } } } @@ -4635,6 +4637,7 @@ sub process { $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && $line !~ /\b$typeTypedefs\b/ && $line !~ /\b__bitwise\b/) { + # close warning # WARN("NEW_TYPEDEFS", # "do not add new typedefs\n" . $herecurr); } @@ -5555,6 +5558,7 @@ sub process { my $fixed_assign_in_if = 0; if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { + # close error # if (ERROR("ASSIGN_IN_IF", # "do not use assignment in if condition\n" . $herecurr) && # $fix && $perl_version_ok) { @@ -5601,6 +5605,7 @@ sub process { $stat_real = "[...]\n$stat_real"; } + # close error # if (ERROR("TRAILING_STATEMENTS", # "trailing statements should be on next line\n" . $herecurr . $stat_real) && # !$fixed_assign_in_if && @@ -5733,8 +5738,9 @@ sub process { } if (!defined $camelcase{$word}) { $camelcase{$word} = 1; - CHK("CAMELCASE", - "Avoid CamelCase: <$word>\n" . $herecurr); + # close check + # CHK("CAMELCASE", + # "Avoid CamelCase: <$word>\n" . $herecurr); } } } @@ -6116,6 +6122,7 @@ sub process { # no volatiles please my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { + # close warning # WARN("VOLATILE", # "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr); } @@ -6682,11 +6689,12 @@ sub process { $kernel_type = 's' if ($type =~ /^_*[si]/); $type =~ /(\d+)/; $kernel_type .= $1; - if (CHK("PREFER_KERNEL_TYPES", - "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/; - } + # close check + # if (CHK("PREFER_KERNEL_TYPES", + # "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) && + # $fix) { + # $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/; + # } } } diff --git a/user/httpd.c b/user/httpd.c index 8333727..dc0c49b 100644 --- a/user/httpd.c +++ b/user/httpd.c @@ -112,8 +112,7 @@ send_error(struct http_request *req, int code) r = snprintf(buf, sizeof(buf), "HTTP/" HTTP_VERSION " %d %s\r\n" "Server: jhttpd/" VERSION "\r\n" - "Connection: close " - "Content-type: text/html\r\n" + "Connection: close Content-type: text/html\r\n" "\r\n" "

%d - %s

\r\n", e->code, e->msg, e->code, e->msg);