From patchwork Sun Aug 11 09:34:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 818472 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BC4338DCC for ; Sun, 11 Aug 2024 09:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723368863; cv=none; b=JrQGKLwGyQi36p2amS/eAjc/K8NijsXgkz3p06+TRvTIe1unPczR7ph6CozMipiEcheIszOgNSq6EnPbsBxUih78UTekh3kxUwZi6oy15qS5Co/ims1jeBDaWCLPrbEbSw+2f70OBysg6DLPzRLtd710FUsGpm2Zf0h5I4r9BFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723368863; c=relaxed/simple; bh=RDuB4dXmqqaeSKOMqyW3t15SDsSeAaEDgl/nUP6Iudw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HNqngyJP1fWcT6+LdpVejt3xd+w3rk11Gmg+196TaoHUsMFMb3xpqhdwIm6C6udA2+wtJ20R9r97LcXhxv33t5I4L+GwrxOZL4Cd7hd4NpRMfRVyHQ1jPWLGIW0z2QfqMFRD/7kR+ne/j+b/pLGuHe26Lq9P/HPWDJsKDvvufA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=KgayrXM2; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="KgayrXM2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=k1; bh=Dc4xm7NCpCxCxI 3EkPd67guzmM5JZuO7F9CsXvrb1+w=; b=KgayrXM2ntrDnd3gZMjN+qYc4Md4Bp YCLzTOCq5VDeKOgVZJR78Wj7yzFFw945nLbsedTY4hlJlEy7dPjF3xCrVPjxGG0g 291YyEuUhQCibMYPrBuIMgr1cQkL2gBfpyfEBLRnKUWLDLclrVIFXvI9rR+Fs+Hh l9PkwC58whUkUhItyWtP+AxoLXAIgBDY3rp83vWK41RoGYVMvmuXcJ67i1+2JerF FXAYgm75OpdnR7DxmDmDOvdyOhmoMral+gaadRBBVdEFhjkCMUNVLq17WV5en4VO A5jBbIZzpj1307pT/Uwkz4WBsU8+eN0sxZtzNUY0occIBkwrkpBQwjVw== Received: (qmail 1059940 invoked from network); 11 Aug 2024 11:34:15 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 11:34:15 +0200 X-UD-Smtp-Session: l3s3148p1@WQRyFGUfNKEujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang Subject: [PATCH i2c-tools 1/2] i2cget: printing help is not an error Date: Sun, 11 Aug 2024 11:34:10 +0200 Message-ID: <20240811093411.5694-1-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The check distinguishing the 'h' and '?' parameters is dead code. Found by cppcheck: i2cget.c:193:4: warning: Statements following noreturn function 'help()' will never be executed. [unreachableCode] Add a parameter to help saying how it should exit. Remove a forward declaration while here. Signed-off-by: Wolfram Sang --- tools/i2cget.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/i2cget.c b/tools/i2cget.c index b28ab38..17d78bf 100644 --- a/tools/i2cget.c +++ b/tools/i2cget.c @@ -31,9 +31,7 @@ #include "util.h" #include "../version.h" -static void help(void) __attribute__ ((noreturn)); - -static void help(void) +static void __attribute__ ((noreturn)) help(int status) { fprintf(stderr, "Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE [LENGTH]]]\n" @@ -48,7 +46,7 @@ static void help(void) " Append p for SMBus PEC\n" " LENGTH is the I2C block data length (between 1 and %d, default %d)\n", I2C_SMBUS_BLOCK_MAX, I2C_SMBUS_BLOCK_MAX); - exit(1); + exit(status); } static int check_funcs(int file, int size, int daddress, int pec) @@ -189,8 +187,7 @@ int main(int argc, char *argv[]) case 'a': all_addrs = 1; break; case 'h': case '?': - help(); - exit(opt == '?'); + help(opt == '?'); } } @@ -200,22 +197,22 @@ int main(int argc, char *argv[]) } if (argc < optind + 2) - help(); + help(1); i2cbus = lookup_i2c_bus(argv[optind]); if (i2cbus < 0) - help(); + help(1); address = parse_i2c_address(argv[optind+1], all_addrs); if (address < 0) - help(); + help(1); if (argc > optind + 2) { size = I2C_SMBUS_BYTE_DATA; daddress = strtol(argv[optind+2], &end, 0); if (*end || daddress < 0 || daddress > 0xff) { fprintf(stderr, "Error: Data address invalid!\n"); - help(); + help(1); } } else { size = I2C_SMBUS_BYTE; @@ -231,24 +228,24 @@ int main(int argc, char *argv[]) case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; default: fprintf(stderr, "Error: Invalid mode!\n"); - help(); + help(1); } pec = argv[optind+3][1] == 'p'; if (size == I2C_SMBUS_I2C_BLOCK_DATA && pec) { fprintf(stderr, "Error: PEC not supported for I2C block data!\n"); - help(); + help(1); } } if (argc > optind + 4) { if (size != I2C_SMBUS_I2C_BLOCK_DATA) { fprintf(stderr, "Error: Length only valid for I2C block data!\n"); - help(); + help(1); } length = strtol(argv[optind+4], &end, 0); if (*end || length < 1 || length > I2C_SMBUS_BLOCK_MAX) { fprintf(stderr, "Error: Length invalid!\n"); - help(); + help(1); } } else { length = I2C_SMBUS_BLOCK_MAX; From patchwork Sun Aug 11 09:34:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 819255 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51D2038DDB for ; Sun, 11 Aug 2024 09:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723368863; cv=none; b=psBfKnsQJx9T8Vt9ElpQUJoV3/SHZvaahFAn+Lj4pVa9o2SkaLbo214ViRAvnVG8pKNH/4Hs7aZJOgFLLiIvMrbLlJwWdeGGcWbQ2WkaM42Vi8C/0Uv/pg2+Ogl6uI3uYbInbPOOwON8T+TBs/BkfXcrwWoQtBY4bz7rhHQLvy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723368863; c=relaxed/simple; bh=OcWYjyydcaukSic+5wAY9aVUnMeR7YkxmIXgaV/Cz5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TkaOBqli8WFI/BGcwMfYYM4a4AtiqIGxZgl1Ee1qgfCXoGsxMVNngRaz4qBWL0LJy8IKVDK9vLYNwEB011cwOAT2yXX1XmFD4kJ74eaFUjpabImnYPMQdQW9vUj1G2g1lygL1ncqZvwuSLLL4okM7/FbTQn0XCaRR6dOafjSg3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=lzP3AHsc; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="lzP3AHsc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=6Q7oz2LEBWcUqEA9+04R40fqXOxnh1ud7T8qewq+mfM=; b=lzP3AH scz0rAsA/Y6XabrkRDFtcBO9tHkgZQS6uBVrqZVHysmi3iF75i9yT6pA9l7OuYpn E7lSos2u5bv1KgUOLl1836vrK9Z74X/KWSSd0vHQkZLyBcbxKPffheP4BeVlvWQH GT924Bpw8KsDL3ItiECapP1oXMT/HXQIEBoYdQ8nQC/5oK45bHdxbqOve8zj7Xs5 b3Y3NJOseKotFeJJMNdFQ9iqm+s82MhplnGk85wfqKaQEv/0SVjUQO3lO0FPyVAt 9/XBi8tVjPpQe+pUUrsKfRGEH0gPku+rj7QU+KJXlNryAAu+qSerQucNGTNmDL4D 7YSL/sZMfX16D5EQ== Received: (qmail 1059959 invoked from network); 11 Aug 2024 11:34:16 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 11 Aug 2024 11:34:16 +0200 X-UD-Smtp-Session: l3s3148p1@Cjt7FGUfRKEujnvj From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang Subject: [PATCH i2c-tools 2/2] i2cset: printing help is not an error Date: Sun, 11 Aug 2024 11:34:11 +0200 Message-ID: <20240811093411.5694-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240811093411.5694-1-wsa+renesas@sang-engineering.com> References: <20240811093411.5694-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The check distinguishing the 'h' and '?' parameters is dead code. Found by cppcheck: i2cset.c:177:4: warning: Statements following noreturn function 'help()' will never be executed. [unreachableCode] Add a parameter to help saying how it should exit. Remove a forward declaration while here. Signed-off-by: Wolfram Sang --- tools/i2cset.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tools/i2cset.c b/tools/i2cset.c index dd4fdc2..aaf7faf 100644 --- a/tools/i2cset.c +++ b/tools/i2cset.c @@ -28,9 +28,7 @@ #include "util.h" #include "../version.h" -static void help(void) __attribute__ ((noreturn)); - -static void help(void) +static void __attribute__ ((noreturn)) help(int status) { fprintf(stderr, "Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]\n" @@ -43,7 +41,7 @@ static void help(void) " i (I2C block data)\n" " s (SMBus block data)\n" " Append p for SMBus PEC\n"); - exit(1); + exit(status); } static int check_funcs(int file, int size, int pec) @@ -173,8 +171,7 @@ int main(int argc, char *argv[]) case 'a': all_addrs = 1; break; case 'h': case '?': - help(); - exit(opt == '?'); + help(opt == '?'); } } @@ -184,20 +181,20 @@ int main(int argc, char *argv[]) } if (argc < optind + 3) - help(); + help(1); i2cbus = lookup_i2c_bus(argv[optind]); if (i2cbus < 0) - help(); + help(1); address = parse_i2c_address(argv[optind+1], all_addrs); if (address < 0) - help(); + help(1); daddress = strtol(argv[optind+2], &end, 0); if (*end || daddress < 0 || daddress > 0xff) { fprintf(stderr, "Error: Data address invalid!\n"); - help(); + help(1); } /* check for command/mode */ @@ -218,7 +215,7 @@ int main(int argc, char *argv[]) if (strlen(argv[argc-1]) > 2 || (strlen(argv[argc-1]) == 2 && argv[argc-1][1] != 'p')) { fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]); - help(); + help(1); } switch (argv[argc-1][0]) { case 'b': size = I2C_SMBUS_BYTE_DATA; break; @@ -227,25 +224,25 @@ int main(int argc, char *argv[]) case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; default: fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]); - help(); + help(1); } pec = argv[argc-1][1] == 'p'; if (size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) { if (pec && size == I2C_SMBUS_I2C_BLOCK_DATA) { fprintf(stderr, "Error: PEC not supported for I2C block writes!\n"); - help(); + help(1); } if (maskp) { fprintf(stderr, "Error: Mask not supported for block writes!\n"); - help(); + help(1); } if (argc > (int)sizeof(block) + optind + 4) { fprintf(stderr, "Error: Too many arguments!\n"); - help(); + help(1); } } else if (argc != optind + 5) { fprintf(stderr, "Error: Too many arguments!\n"); - help(); + help(1); } } @@ -262,12 +259,12 @@ int main(int argc, char *argv[]) value = strtol(argv[optind+3], &end, 0); if (*end || value < 0) { fprintf(stderr, "Error: Data value invalid!\n"); - help(); + help(1); } if ((size == I2C_SMBUS_BYTE_DATA && value > 0xff) || (size == I2C_SMBUS_WORD_DATA && value > 0xffff)) { fprintf(stderr, "Error: Data value out of range!\n"); - help(); + help(1); } break; case I2C_SMBUS_BLOCK_DATA: @@ -276,11 +273,11 @@ int main(int argc, char *argv[]) value = strtol(argv[optind + len + 3], &end, 0); if (*end || value < 0) { fprintf(stderr, "Error: Data value invalid!\n"); - help(); + help(1); } if (value > 0xff) { fprintf(stderr, "Error: Data value out of range!\n"); - help(); + help(1); } block[len] = value; } @@ -295,12 +292,12 @@ int main(int argc, char *argv[]) vmask = strtol(maskp, &end, 0); if (*end || vmask == 0) { fprintf(stderr, "Error: Data value mask invalid!\n"); - help(); + help(1); } if (((size == I2C_SMBUS_BYTE || size == I2C_SMBUS_BYTE_DATA) && vmask > 0xff) || vmask > 0xffff) { fprintf(stderr, "Error: Data value mask out of range!\n"); - help(); + help(1); } }