Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp807683ybm; Wed, 27 May 2020 08:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVbNu+4YYL21I1K+ixYcmBvKSQhnMKXrZBwNjCfLzrxZSLnH8Y0d3wc2h6ZldOqR2jqFYi X-Received: by 2002:a05:6402:30b2:: with SMTP id df18mr23759255edb.323.1590593383398; Wed, 27 May 2020 08:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590593383; cv=none; d=google.com; s=arc-20160816; b=qGIgAr1ShMvuzWdnSRk4GQHGj5WZrps9yjoPklq/116Y+DSMQeGWQM53iCLMCpc0NP +xmjJriEUCgtZ+7nN71lY9jfxsjOHDaeYSP/K3gqIwZfHUOWKGjEghr6zBteDenKXOIo TqOgVjNmxmeUI2oargkJ53LhCgEn8oU8ksW//hC0o8aijmlV4QdHOdj/qTs4hk68C2ir 7fK9lIPrpyKKccfq4CPzic2uiH5+q/fYnsSn/kES2UrLsdf3odPkNpXNMUMjAHdn3GoO +ckDS9WHJPOkjdmd7DnGg1MOcj2Ay/rW7/H6kkl2KNYgPi7omsfk4hdS7M09IMUOt2HC dsrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ieXuEPyp84YB4GCGexw/j3cGASehKyzX4KKOE2VbBQw=; b=VaULEEwLlV960WETc45XuUO0dxcI1931aLQ5Kzu9+4WfX+M68Jlft2+zNUwvmjEvdA LrYg3YR00iC+5QXZAawaAgXW/wY9aadjxpvVZfhUIOpiGU2l5nudYajhnzPXsbT8hijr JQnpR9PxY2J/RZ4HAQroTyv1TjPXR1eYuAYge2Itd3UOLmOxFrN1hNzPrspcdBFW1Lna AlvWXRy+bZqJothL+scqllovTCvUE4LS70QgVmf269sxbM6G91MX7GiOf70Gq50Fqtrv cgF++Upsrcw7H3qmjO/kgGxNeL7ZBf2TCmVLtO3xXIdC7KZO8XzT3djGx5owGA+nu7Ri Y23w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IiOtfTb5; 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 os22si2151760ejb.620.2020.05.27.08.29.19; Wed, 27 May 2020 08:29:43 -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=IiOtfTb5; 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 S1729567AbgE0I3O (ORCPT + 99 others); Wed, 27 May 2020 04:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729497AbgE0I3O (ORCPT ); Wed, 27 May 2020 04:29:14 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB641C061A0F for ; Wed, 27 May 2020 01:29:13 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x6so9492065wrm.13 for ; Wed, 27 May 2020 01:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ieXuEPyp84YB4GCGexw/j3cGASehKyzX4KKOE2VbBQw=; b=IiOtfTb5HALp4h7n/CPvhJgyDwm8hS5bTwq2E+SrwdVZ72vGOW8yYwTLWfNrzyXILt N/XR79Zp+D7888hHIB3T9s7iR+qtCGadav3UPlHMxaDj61jeVDgAn6qUCbjtxvc+0imP TuhnHNKszTK3JTFYcyjJ5u7XnYwztI0owFyQUapUBfYkkZPIwzpkcxxVCCUku7MtrtNA nSok9J3eqMAOJlK3KuV2OYRJJJnl3gCfcCwXGNxrOAGIQNVy4GNXJ4gD3cldG7OjURVx U+AWgtZ3QoclVp2Ed8uqgKWolA2YmmMkcdXH1UQf6jXZ0JkG0xFsTsPdovOXiMh2zST8 yIFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ieXuEPyp84YB4GCGexw/j3cGASehKyzX4KKOE2VbBQw=; b=cPlQwsuX0u2ArVzgqjBgkyR7or/mqn3puf5jfE+qb2koxKKGobWrqV3mDDO3fsqQ2N nsyDFy23UZ/TpHoMIPYwG2/2kwRn//DixpgWID7TJrWt001onHoq+X4o8B9unBYhz5we IM1/dSl0UWU2oXyKMK1V1OmZ2BN7dLbp1uGDV65Mg0jmVuCCMT9dVZhkJCY0bMAC1Jdj BjDG0PD5prQc8/Pyhsy9ijwI1+z8KoFVvPn2CeN6rN2Fntunxd4iKG+k4aM+H1cd3jFy 63vNf3qSfcq4E/n5IIZiz5g+atxd5BVA4Q05jM+85qjPXvd+p0B8uMrrKV6IrJx812mv C8Tw== X-Gm-Message-State: AOAM530NH0MvdU2XAYqMFjJC0W/3Cz4kPwqtmivMX4YW93is049nNf/W Vl0eHabmrVGtwmlqCswnzNyQfg== X-Received: by 2002:adf:dc50:: with SMTP id m16mr23880325wrj.329.1590568152559; Wed, 27 May 2020 01:29:12 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id h7sm2159191wml.24.2020.05.27.01.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 01:29:11 -0700 (PDT) Date: Wed, 27 May 2020 09:29:07 +0100 From: Daniel Thompson To: Sumit Garg Cc: kgdb-bugreport@lists.sourceforge.net, jason.wessel@windriver.com, dianders@chromium.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/4] kdb: Re-factor kdb_printf() message write code Message-ID: <20200527082907.wfvdsekmyzbpu3tu@holly.lan> References: <1590560759-21453-1-git-send-email-sumit.garg@linaro.org> <1590560759-21453-2-git-send-email-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1590560759-21453-2-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 On Wed, May 27, 2020 at 11:55:56AM +0530, Sumit Garg wrote: > 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..f6b4d47 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, void (*io_put_char)(u8 ch)) Don't use a function pointer here. Just pick it up from dbg_io_ops as usual. > +{ > + if (len <= 0) > + return; How can len ever be negative? > + > + while (len--) { > + io_put_char(*cp); > + cp++; > + } > +} > + > +static void kdb_msg_write(char *msg, int msg_len) > +{ > + struct console *c; > + > + if (msg_len <= 0) > + return; How can msg_len ever be negative? > + > + if (dbg_io_ops && !dbg_io_ops->is_console) > + kdb_io_write(msg, msg_len, dbg_io_ops->write_char); > + > + 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 >