Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp2471895ooa; Thu, 16 Aug 2018 12:18:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxIWubMu20QE1ibhgQq5NNFVgRMwsXjkZAcx3rM+aGdq0PCsDsYKHH4+5BcKsSfj6dRGLRt X-Received: by 2002:a62:20f:: with SMTP id 15-v6mr33769798pfc.100.1534447124749; Thu, 16 Aug 2018 12:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534447124; cv=none; d=google.com; s=arc-20160816; b=vgwFhHbJAIdqpmttOvHQScdrYZrFb+NO8/IZno4e75x1lT5ImF5CqmpfvVBrMEyg01 8/8VodwFsbswAQg6V/QyGejj+Rl6INVFjAGRXmWZsDVD33KSfnx8YHlRnTPzuUnnVQ7Q sCs7vSSc/Hw1T/VyEye0O5MDsoknnmnvMnQQFYHTSLN8yoe/eUmo0LeF9Ikk9Is8MuEm Fh8offlxcDKiemnpC1AtwW2jWet7VZ5K85zPvxWeSF6P7YSD8Q/Et/C/Uk/qFGgWl5rP s3zeieBlGrOYDHD8ZFmkbYVgLD++RZyn89exM6P+kwLvULy47KTuWl3dgsVkl0EN8V8E T2xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=kM7QlUEIdePYHGsI2GxZnQ/9giDcfJ9gkrJOLY5IyKw=; b=F4FOQa2IYktP6mUyTyfKnynVJiyP0nvDCQkG1KhGnv44XUUDZozlnlff9BGWIgDF7U tA6JoIENxjFJKoGzvjkx4lNsoCTFuXGkcucbrFNWKhr/XP2tFkdxPTvlbi7m2oxFeklA ZWvBpZC9O0c2DhHtWdtzHWnO723VzwhvsJdLQ6OiFg/xNSqIvP/Hk/HJLAr9GlMhaYjj WFeUfwW+Aa8nZReeksztVUnrcnvwWxas3mchU+yvPfvdGn7Qq0g2fMnn/BquMjRiqEhF SUku0scYMWENoZ8mDH/uSjia1j3+UbdVEgWYnN4ro2iC2wBvbFp6XQir13Kka53/SFYz In+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23-v6si118813pgj.354.2018.08.16.12.18.29; Thu, 16 Aug 2018 12:18:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389491AbeHPRBN (ORCPT + 99 others); Thu, 16 Aug 2018 13:01:13 -0400 Received: from gateway31.websitewelcome.com ([192.185.143.31]:22694 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387574AbeHPRBN (ORCPT ); Thu, 16 Aug 2018 13:01:13 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id EF67119A2 for ; Thu, 16 Aug 2018 09:02:24 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id qIqOfqfn3PvAdqIqmfqPou; Thu, 16 Aug 2018 09:02:23 -0500 X-Authority-Reason: nr=8 Received: from [189.250.72.226] (port=48026 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fqIqM-000Qr8-QP; Thu, 16 Aug 2018 09:01:42 -0500 Date: Thu, 16 Aug 2018 09:01:41 -0500 From: "Gustavo A. R. Silva" To: Jason Wessel , Daniel Thompson Cc: kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v2] kdb: kdb_main: refactor code in kdb_md_line Message-ID: <20180816140141.GA28913@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.72.226 X-Source-L: No X-Exim-ID: 1fqIqM-000Qr8-QP X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.72.226]:48026 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 4 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace the whole switch statement with a for loop. This makes the code much clear and easy to read. This also addresses the following Coverity warnings: Addresses-Coverity-ID: 115090 ("Missing break in switch") Addresses-Coverity-ID: 115091 ("Missing break in switch") Addresses-Coverity-ID: 114700 ("Missing break in switch") Suggested-by: Daniel Thompson Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Add new variable j and use it for the for loop. kernel/debug/kdb/kdb_main.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 2ddfce8..a9ad288 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -1493,6 +1493,7 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr, char cbuf[32]; char *c = cbuf; int i; + int j; unsigned long word; memset(cbuf, '\0', sizeof(cbuf)); @@ -1538,25 +1539,9 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr, wc.word = word; #define printable_char(c) \ ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; }) - switch (bytesperword) { - case 8: + for (j = 0; j < bytesperword; j++) *c++ = printable_char(*cp++); - *c++ = printable_char(*cp++); - *c++ = printable_char(*cp++); - *c++ = printable_char(*cp++); - addr += 4; - case 4: - *c++ = printable_char(*cp++); - *c++ = printable_char(*cp++); - addr += 2; - case 2: - *c++ = printable_char(*cp++); - addr++; - case 1: - *c++ = printable_char(*cp++); - addr++; - break; - } + addr += bytesperword; #undef printable_char } } -- 2.7.4