From patchwork Wed Jan 27 08:57:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1432129 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQffM6Tqfz9sS8 for ; Wed, 27 Jan 2021 21:16:59 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DQffM42QczDqkX for ; Wed, 27 Jan 2021 21:16:59 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 4DQfdk2yYXzDqjY for ; Wed, 27 Jan 2021 21:16:26 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id CA5DDAE8027B; Wed, 27 Jan 2021 03:58:18 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Wed, 27 Jan 2021 19:57:47 +1100 Message-Id: <20210127085752.120571-9-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210127085752.120571-1-aik@ozlabs.ru> References: <20210127085752.120571-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof 08/13] libnet: Compile with -Wextra X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" -Wextra enables a bunch of rather useful checks which this fixes. Signed-off-by: Alexey Kardashevskiy --- lib/libnet/netapps.h | 4 ++-- lib/libnet/netload.c | 4 ++-- lib/libnet/ping.c | 6 +++--- lib/libnet/pxelinux.c | 5 +++-- slof/ppc64.c | 12 +++++++++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/libnet/netapps.h b/lib/libnet/netapps.h index 6e00466de5a9..722ca7ff7ab4 100644 --- a/lib/libnet/netapps.h +++ b/lib/libnet/netapps.h @@ -18,8 +18,8 @@ struct filename_ip; -extern int netload(char *buffer, int len, char *args_fs, int alen); -extern int ping(char *args_fs, int alen); +extern int netload(char *buffer, int len, char *args_fs, unsigned alen); +extern int ping(char *args_fs, unsigned alen); extern int dhcp(char *ret_buffer, struct filename_ip *fn_ip, unsigned int retries, int flags); diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c index 2dc00f00097d..ae169f3e015d 100644 --- a/lib/libnet/netload.c +++ b/lib/libnet/netload.c @@ -528,7 +528,7 @@ static void encode_response(char *pkt_buffer, size_t size, int ip_init) } } -int netload(char *buffer, int len, char *args_fs, int alen) +int netload(char *buffer, int len, char *args_fs, unsigned alen) { int rc, filename_len; filename_ip_t fn_ip; @@ -566,7 +566,7 @@ int netload(char *buffer, int len, char *args_fs, int alen) set_timer(TICKS_SEC); while (get_timer() > 0); } - fd_device = socket(0, 0, 0, (char*) own_mac); + fd_device = socket(AF_INET, SOCK_DGRAM, 0, (char*) own_mac); if(fd_device != -2) break; if(getchar() == 27) { diff --git a/lib/libnet/ping.c b/lib/libnet/ping.c index 51db061ecaff..476c4fe44ba7 100644 --- a/lib/libnet/ping.c +++ b/lib/libnet/ping.c @@ -106,7 +106,7 @@ parse_args(const char *args, struct ping_args *ping_args) return 0; } -int ping(char *args_fs, int alen) +int ping(char *args_fs, unsigned alen) { short arp_failed = 0; filename_ip_t fn_ip; @@ -119,7 +119,7 @@ int ping(char *args_fs, int alen) memset(&ping_args, 0, sizeof(struct ping_args)); - if (alen <= 0 || alen >= sizeof(args) - 1) { + if (alen >= sizeof(args) - 1) { usage(); return -1; } @@ -137,7 +137,7 @@ int ping(char *args_fs, int alen) /* Get mac_addr from device */ printf("\n Reading MAC address from device: "); - fd_device = socket(0, 0, 0, (char *) own_mac); + fd_device = socket(AF_INET, SOCK_DGRAM, 0, (char *) own_mac); if (fd_device == -1) { printf("\nE3000: Could not read MAC address\n"); return -100; diff --git a/lib/libnet/pxelinux.c b/lib/libnet/pxelinux.c index c4ac5d5a078a..be1939f24d8b 100644 --- a/lib/libnet/pxelinux.c +++ b/lib/libnet/pxelinux.c @@ -55,7 +55,8 @@ static int pxelinux_tftp_load(filename_ip_t *fnip, void *buffer, int len, static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid, int retries, char *cfgbuf, int cfgbufsize) { - int rc, idx; + int rc; + unsigned idx; char *baseptr; /* Did we get a usable base directory via DHCP? */ @@ -77,7 +78,7 @@ static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uui ++baseptr; /* Check that we've got enough space to store "pxelinux.cfg/" * and the UUID (which is the longest file name) there */ - if (baseptr - fn_ip->filename > sizeof(fn_ip->filename) - 50) { + if (baseptr - fn_ip->filename > (int)(sizeof(fn_ip->filename) - 50)) { puts("Error: The bootfile string is too long for " "deriving the pxelinux.cfg file name from it."); return -1; diff --git a/slof/ppc64.c b/slof/ppc64.c index 83a8e82cfb42..ca6cafffc35d 100644 --- a/slof/ppc64.c +++ b/slof/ppc64.c @@ -144,6 +144,12 @@ int socket(int domain, int type, int proto, char *mac_addr) int prop_len; int fd; + if (!(domain == AF_INET || domain == AF_INET6)) + return -1; + + if (type != SOCK_DGRAM || proto != 0) + return -1; + /* search free file descriptor (and skip stdio handlers) */ for (fd = 3; fd < FILEIO_MAX; ++fd) { if (fd_array[fd].type == FILEIO_TYPE_EMPTY) { @@ -217,7 +223,7 @@ int close(int fd) */ int recv(int fd, void *buf, int len, int flags) { - if (!is_valid_fd(fd)) + if (!is_valid_fd(fd) || flags) return -1; forth_push((unsigned long)buf); @@ -237,7 +243,7 @@ int recv(int fd, void *buf, int len, int flags) */ int send(int fd, const void *buf, int len, int flags) { - if (!is_valid_fd(fd)) + if (!is_valid_fd(fd) || flags) return -1; forth_push((unsigned long)buf); @@ -258,7 +264,7 @@ int send(int fd, const void *buf, int len, int flags) ssize_t read(int fd, void *buf, size_t len) { char *ptr = (char *)buf; - int cnt = 0; + unsigned cnt = 0; char code; if (fd == 0 || fd == 2) {