Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2656273pxa; Mon, 17 Aug 2020 15:41:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoOgT748ryCLKlfiehBEZKOp0MnlwILIUYRom1MCCdVrcTBhTus4a5isaUGH3cvnzg9JAZ X-Received: by 2002:a17:906:c187:: with SMTP id g7mr17992355ejz.108.1597704069556; Mon, 17 Aug 2020 15:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704069; cv=none; d=google.com; s=arc-20160816; b=sbXQJ8Zmz2zawOvC6aLxHzPP49Ot7WJf/UBLcEMw1LDh0dhUUEj9JsWYkVFRWkTTBt AopV+afzxyxLiRQx6KaGsB8IZwub169mxB9I9H5G0Ap/eDIMQPjxb7plG6I8au59uhod G6sjoGXWcKMYx+nR6JvdnGTZTwxoVncl0NN20yVsdnOeM00OaS14a3vwn9P7EsT68pMD RCIXHfPA9uOa7sFqi3dIPyMZmA8jFlMa8p0R/ehkApeTYMxkbESVJmpQ4ht80ZgHhMAZ 8G4DtEM4ZnEYYRUyMhEbtniYOA8HK1MeS9UMzNK74KVw1M6tKvAs/Wpxr2vpO+UvIUj3 1Wsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UKNVn1ZABDuQY7wLaAeFYU4KOzMmGHSAoJD72H3Pjmg=; b=CEtNq5+W04X3gbRuvJBUebz//IXg1z+YoOG3uwXYFNp0a0h0ZKTavPcqsOHvFZ0heZ J00p5Ck6UnZIFC3MkcnZqOjMA6/4Yjptq81zg0IabC6omU2rXwsFJNAm+0kq9vxRGPf9 s1kxQDLt6fpjbwG1VieN/ndQfAYUa7qIH8x93FAhcA9sL8td50XzD+uVMx+ynow6175P 1G574f5ZsUbwF3WTGscm3mqHPbE4cpp+pYkZeu7pbMMwYEEvx5G0oB4KvWn5KKGr8UbG qsus27zBE59fu8q5SoZjqn5HOgSqBvqkLw+jLWOGSdZWHhXSKREj8zDdSdxyWsJ2s1NA tg6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HCbOWv3Q; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si12272700edh.154.2020.08.17.15.40.45; Mon, 17 Aug 2020 15:41:09 -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=@kernel.org header.s=default header.b=HCbOWv3Q; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390857AbgHQSYg (ORCPT + 99 others); Mon, 17 Aug 2020 14:24:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:50722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731046AbgHQQDJ (ORCPT ); Mon, 17 Aug 2020 12:03:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50FAC20748; Mon, 17 Aug 2020 16:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680187; bh=3PqwFuyvyWp01jmhrrMGQOLnNySxF9XPHp52ZDa19Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCbOWv3QW3xu/eP2UR56ryNMhWn9wpa+5PrN0icMFixi4Dyis78qU78Ko306q4DyQ L9PAgWsJf5OqUv8tfjpv/fA4laX27b0JJBDWVAJFbX0ZAO5ZcvSkQfjwWelRODlNPV 4pkTCU5FkLK67uxKaYPbaQxhYgjEtMbS7e2w7gY4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, jbaron@akamai.com, Jim Cromie , Sasha Levin Subject: [PATCH 5.4 086/270] dyndbg: fix a BUG_ON in ddebug_describe_flags Date: Mon, 17 Aug 2020 17:14:47 +0200 Message-Id: <20200817143800.050431684@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jim Cromie [ Upstream commit f678ce8cc3cb2ad29df75d8824c74f36398ba871 ] ddebug_describe_flags() currently fills a caller provided string buffer, after testing its size (also passed) in a BUG_ON. Fix this by replacing them with a known-big-enough string buffer wrapped in a struct, and passing that instead. Also simplify ddebug_describe_flags() flags parameter from a struct to a member in that struct, and hoist the member deref up to the caller. This makes the function reusable (soon) where flags are unpacked. Acked-by: Signed-off-by: Jim Cromie Link: https://lore.kernel.org/r/20200719231058.1586423-8-jim.cromie@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- lib/dynamic_debug.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index c60409138e136..ccf05719b1ad6 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -87,22 +87,22 @@ static struct { unsigned flag:8; char opt_char; } opt_array[] = { { _DPRINTK_FLAGS_NONE, '_' }, }; +struct flagsbuf { char buf[ARRAY_SIZE(opt_array)+1]; }; + /* format a string into buf[] which describes the _ddebug's flags */ -static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, - size_t maxlen) +static char *ddebug_describe_flags(unsigned int flags, struct flagsbuf *fb) { - char *p = buf; + char *p = fb->buf; int i; - BUG_ON(maxlen < 6); for (i = 0; i < ARRAY_SIZE(opt_array); ++i) - if (dp->flags & opt_array[i].flag) + if (flags & opt_array[i].flag) *p++ = opt_array[i].opt_char; - if (p == buf) + if (p == fb->buf) *p++ = '_'; *p = '\0'; - return buf; + return fb->buf; } #define vpr_info(fmt, ...) \ @@ -144,7 +144,7 @@ static int ddebug_change(const struct ddebug_query *query, struct ddebug_table *dt; unsigned int newflags; unsigned int nfound = 0; - char flagbuf[10]; + struct flagsbuf fbuf; /* search for matching ddebugs */ mutex_lock(&ddebug_lock); @@ -201,8 +201,7 @@ static int ddebug_change(const struct ddebug_query *query, vpr_info("changed %s:%d [%s]%s =%s\n", trim_prefix(dp->filename), dp->lineno, dt->mod_name, dp->function, - ddebug_describe_flags(dp, flagbuf, - sizeof(flagbuf))); + ddebug_describe_flags(dp->flags, &fbuf)); } } mutex_unlock(&ddebug_lock); @@ -816,7 +815,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p) { struct ddebug_iter *iter = m->private; struct _ddebug *dp = p; - char flagsbuf[10]; + struct flagsbuf flags; vpr_info("called m=%p p=%p\n", m, p); @@ -829,7 +828,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p) seq_printf(m, "%s:%u [%s]%s =%s \"", trim_prefix(dp->filename), dp->lineno, iter->table->mod_name, dp->function, - ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf))); + ddebug_describe_flags(dp->flags, &flags)); seq_escape(m, dp->format, "\t\r\n\""); seq_puts(m, "\"\n"); -- 2.25.1