Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp458459ybm; Fri, 29 May 2020 04:29:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn7D7AJAp6N4K3iN21auDlSrKLu9qYwakPFmxOL/FZ27qZ2bbq0cHTUa7/idzp6eeaO+o/ X-Received: by 2002:aa7:d312:: with SMTP id p18mr7836152edq.88.1590751771177; Fri, 29 May 2020 04:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590751771; cv=none; d=google.com; s=arc-20160816; b=eU9Pw9hqsdfuZSUYtrm37pRwVvIldXUpj8b3C0c7gJ6hGm1VPttxynAOFQdvKHpj9h wfOOw5xf2Cz9ofk73R3bv+cGCwImU4htCp0Q9sqthXG5yUbphUHX83loIPuJjIifDlYL TmE1pFUqMZIP34Zi+m9tZbiBTR8FROVkSu0uZWBwf7zPYxap+TwWgeNa6VJHAmPaCADj 5JwZcLqwZr2h9+yi3d13S0woVklIoQ+6p8oSCvpdVeN4XtgiXF/SJGj61QRAxdpVNCci dn9Y4kqANr30cXd12OuG2qfJumywvyiyqEjqYByqXHrgIBIFCXBc5Jj+BcT1WAgpxA2g 4nPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6ctBq+QFlLwI1QYopIw19U7dJqDOQ/tbZAKxzZCAns8=; b=d6EJlYPsn6ZN4Fc7ZxeKPP6fOZHMxen8mv+Zzcb299pUpDp+d0ok0qzrT0lAU+pT5p aS6HkFaTnneDPCzUb5FYOpHJPcZSZ8U0DuQhQUjowso9jZGN8G600BfBnHAqpHBJ7PdH 8noRk98Sfbiij1vdqpFFUuV5U/7VTKd2F1PR3Jc76siG064T+adtkHWVYMY12D6vA2pd Y8Vhw25zJENFr7NugtA3adgflhpla+EAHLLPyA1cGZ2YF3Asyq/USSjWMqWSYO3Hmpkv htCfn28X3X/YEwXvcPJdKApiHdCiBMJk/xcI+N4haip36vdtjz7qA1aBy0P2prW/SNgS bu6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kzySAK8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si5495963eju.448.2020.05.29.04.29.08; Fri, 29 May 2020 04:29:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kzySAK8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgE2L10 (ORCPT + 99 others); Fri, 29 May 2020 07:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgE2L1Z (ORCPT ); Fri, 29 May 2020 07:27:25 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 112F2C03E969 for ; Fri, 29 May 2020 04:27:24 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id f21so1352689pgg.12 for ; Fri, 29 May 2020 04:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6ctBq+QFlLwI1QYopIw19U7dJqDOQ/tbZAKxzZCAns8=; b=kzySAK8hODG2cYbJPTRthw/g8bz7SqzCixHZT8y2YFZkKrIJ6GBecBhOjAVtkZJM6Q 112LqTSB86oh909HxSy7h2MQhm6ErbCF+VDmFqoFL5VsBuDuvMkxYrBRXJ/lJGyl1uxs NzCOwup3zZTYr0jEOGxwm45QIb0w/P0AYqRSJINqDfTD3/pn7hLt+S5Y09ykeiAoX0Ko gDPZNDFCOZMnYg/do+73Tt9GUggw4SNAUdIr7ql9H/1yLWnuqBb2tPPzTzljekmXMDPu Tl32j7DhBWMHOcNIXDm81RCftktTygtIhWvy9MaBIGfbZdE+n7wLD2qSCqBYpcza3zKO NvvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6ctBq+QFlLwI1QYopIw19U7dJqDOQ/tbZAKxzZCAns8=; b=qNLitlzkiB6RJVdVaNY+mK3+9sVRAWjnZRWaWk+hVvAD+6LGBq/uZY1dhHJQs6JVl7 rG0heAD8H4nMjUCVby/v1+bxZfeupN0YcYPI29HLUG3M1JtfsfkxQ2imP97cer8vzcLS YOlxWC5KUV9taVz5Ut3BmVHPN4guenqGdY0m7AJ3+QBpIDFemBxgmKX/816DRz/jbqNP MVufVMuWCNxgbnQfYs4qZmL26EaTXfi1zZ6GLuJVHFbP4axXxrEt3MlDEIVAZ0g92SdG WM90FR1ROiLO++N6nS0QDMexYLWzVs1eD1aK9Wrsk5Cn/TW+YSPUmM+nHT7xJgNn8h0a jdzQ== X-Gm-Message-State: AOAM531AHRM1aguGHxBWmV1lpjsLxqgingWaT9D0pfXtVTaGmW8TCdeP OdTMBSoxqSEhWs0smMrsI0l6gg== X-Received: by 2002:a63:33c6:: with SMTP id z189mr8093582pgz.426.1590751643548; Fri, 29 May 2020 04:27:23 -0700 (PDT) Received: from localhost.localdomain ([117.252.66.248]) by smtp.gmail.com with ESMTPSA id w190sm7016741pfw.35.2020.05.29.04.27.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 May 2020 04:27:22 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: kgdb-bugreport@lists.sourceforge.net, jason.wessel@windriver.com, dianders@chromium.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, gregkh@linuxfoundation.org, jslaby@suse.com, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH v4 1/4] kdb: Re-factor kdb_printf() message write code Date: Fri, 29 May 2020 16:56:44 +0530 Message-Id: <1590751607-29676-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590751607-29676-1-git-send-email-sumit.garg@linaro.org> References: <1590751607-29676-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Re-factor kdb_printf() message write code in order to avoid duplication of code and thereby increase readability. Signed-off-by: Sumit Garg --- kernel/debug/kdb/kdb_io.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 924bc92..e46f33e 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -542,6 +542,33 @@ static int kdb_search_string(char *searched, char *searchfor) return 0; } +static void kdb_io_write(char *cp, int len) +{ + if (len == 0) + return; + + while (len--) { + dbg_io_ops->write_char(*cp); + cp++; + } +} + +static void kdb_msg_write(char *msg, int msg_len) +{ + struct console *c; + + if (msg_len == 0) + return; + + if (dbg_io_ops && !dbg_io_ops->is_console) + kdb_io_write(msg, msg_len); + + for_each_console(c) { + c->write(c, msg, msg_len); + touch_nmi_watchdog(); + } +} + int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) { int diag; @@ -553,7 +580,6 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) int this_cpu, old_cpu; char *cp, *cp2, *cphold = NULL, replaced_byte = ' '; char *moreprompt = "more> "; - struct console *c; unsigned long uninitialized_var(flags); /* Serialize kdb_printf if multiple cpus try to write at once. @@ -687,22 +713,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) */ retlen = strlen(kdb_buffer); cp = (char *) printk_skip_headers(kdb_buffer); - if (!dbg_kdb_mode && kgdb_connected) { + if (!dbg_kdb_mode && kgdb_connected) gdbstub_msg_write(cp, retlen - (cp - kdb_buffer)); - } else { - if (dbg_io_ops && !dbg_io_ops->is_console) { - len = retlen - (cp - kdb_buffer); - cp2 = cp; - while (len--) { - dbg_io_ops->write_char(*cp2); - cp2++; - } - } - for_each_console(c) { - c->write(c, cp, retlen - (cp - kdb_buffer)); - touch_nmi_watchdog(); - } - } + else + kdb_msg_write(cp, retlen - (cp - kdb_buffer)); + if (logging) { saved_loglevel = console_loglevel; console_loglevel = CONSOLE_LOGLEVEL_SILENT; @@ -751,19 +766,7 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) moreprompt = "more> "; kdb_input_flush(); - - if (dbg_io_ops && !dbg_io_ops->is_console) { - len = strlen(moreprompt); - cp = moreprompt; - while (len--) { - dbg_io_ops->write_char(*cp); - cp++; - } - } - for_each_console(c) { - c->write(c, moreprompt, strlen(moreprompt)); - touch_nmi_watchdog(); - } + kdb_msg_write(moreprompt, strlen(moreprompt)); if (logging) printk("%s", moreprompt); -- 2.7.4