Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5817052ybc; Wed, 27 Nov 2019 09:52:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxZh6KAUBh8WYuKW+7AGP2MnYG13BKF9/jPPYygrV1erfXIcrdW0aFH8ldlZqdHFOHoN4Ir X-Received: by 2002:a17:906:7251:: with SMTP id n17mr50923745ejk.329.1574877179708; Wed, 27 Nov 2019 09:52:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574877179; cv=none; d=google.com; s=arc-20160816; b=VRVm0e81YoBs5y4SAi5EB3PZep3pbQXmZhMjmbuONwFEdWGpZPIlLSrigB2HMdjSKM rrhyjA+JRY9jPP44MQeQ2/zgwDtwY74907PR+BZdNy6RBytou+ihfcPRnWQdTjEMvB7Z wfBKbBosdBbvwgcEcHurWskBcSmDOL+j8hr/KvCrtcKT+lMlYFuNu1PNrC0XtSlfolBH gv65zwTQ6EvpwUfmIBaz/6e8SmDYAArmJEe8MWhNY7RmzMcqR3xtS1tStxSRahaqIkcL uqqqrEXYuMO7YWL6Jpkt4xM3O2YxmdhaJSxmUymhKHgJrsMxpuj9IvCD1mHGDPgJGdoE wXGA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=JBvCUJLGzPXX0Pn9enxN3cNtWBdwerBLUit9nHVW5Gk=; b=sjIUkmTpUh9NTlftaOgsqSQFzK+kVMwCRd0Kfip6QjnMjGV3aIyRmVtkX326TGGO9N ANtEVx3Z7iJOYXQ/9m0tE3C5CBL/3YN9RW/ng25c/QQk1OeXobsEAqDGSq+4ehgOfp6M JWDKFRAp2p/w44EkSgxE4KhBYlq/e8rpHAtJzINJqhmzA7xQP/0wTUAOI4TF7SXxe16p C1aflyyPzGgUaendWvw34BXx4NAErzW4Ea9hIb0dApI2gXJ9SD3md9GwtZiuERjL4TE9 oZCdzjbq6WnIDATc6ecXaq7/hLB7uEOfMqhdbo4Ht8Ri+xSeB5CvHPbuJmo8WSvtejLT wpFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kyGVp04Q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dd9si12812568edb.226.2019.11.27.09.52.36; Wed, 27 Nov 2019 09:52:59 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kyGVp04Q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbfK0RvD (ORCPT + 99 others); Wed, 27 Nov 2019 12:51:03 -0500 Received: from mail-il1-f193.google.com ([209.85.166.193]:35832 "EHLO mail-il1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbfK0RvC (ORCPT ); Wed, 27 Nov 2019 12:51:02 -0500 Received: by mail-il1-f193.google.com with SMTP id g12so12325615ild.2 for ; Wed, 27 Nov 2019 09:51:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JBvCUJLGzPXX0Pn9enxN3cNtWBdwerBLUit9nHVW5Gk=; b=kyGVp04QChNhrcDytyBm+e8HM7yIeAysxnAW7WR701jqbTnJC+psbtgEmE9dQROAmC CWiHA8wGuDXbZwJGABZ5UMBWMwFBDfBRjKQ4yb5HtQRb3Q96a0TozWUm8AfQ0xjZZ9Xh YLiyKw5GmU3Xi3QZls6EAQIaSw+5NPYDDkhfgCZ2SCbkTDD+7MyQIv8RH+Kz0FKIXYYs umd0bj6hddy79+84ge7xGVGM7E7cb/m6GswBA+pa9lMo9OWibOlwEp5SnSx7j2yitH24 io5nt1AFCTHsJZf5+xHnU8YJ1lAKZetcs+OAT/ssr+hGYXMhp0SRMTwlg3INj3T+8zmz 5bzw== 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:mime-version :content-transfer-encoding; bh=JBvCUJLGzPXX0Pn9enxN3cNtWBdwerBLUit9nHVW5Gk=; b=TutOMPYNJSTj49hRZb65YtqYkyArcFRwdCBpZ7UVARRzbMdtXAjZXBqQZCgxbW6Ql4 WzDYYaaLKGr3ZX+XWMXoJcAKUA8wCBa/BBZN4D7XLzX6Ebmod7Ayw2YtbaBwNoeUuJ2x TMQwfLtvuU0NW9jKGlNJ4XJOdYdqK7eoVDGkVJJ/OHhv4d2xaoFd/7PMRBmoTv51p683 zirQSWWNV8t/8TJHmunJ9Ek0gd+6AD/CV9XON5fxYuT5y1WW3E7ANJs9v5NdX143THdF b9JJxqzwdBxmJI/W8fapkpQxpCnDZXPFay5CxjmJE+GavSCRY5gZTMIsIkMzDxsNmfLs 8+WQ== X-Gm-Message-State: APjAAAWSMaWXfT7v/PK2Hx7TA36222ksL3tCHHbYrIi0hWMPneZl2wue b/ZjCpijprr7DlgCB/AYC0U= X-Received: by 2002:a92:5b86:: with SMTP id c6mr44156249ilg.135.1574877061578; Wed, 27 Nov 2019 09:51:01 -0800 (PST) Received: from localhost.localdomain (c-24-9-77-57.hsd1.co.comcast.net. [24.9.77.57]) by smtp.googlemail.com with ESMTPSA id e15sm669445ioe.18.2019.11.27.09.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 09:51:00 -0800 (PST) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org Cc: linux@rasmusvillemoes.dk, greg@kroah.com, Jim Cromie Subject: [PATCH 06/16] dyndbg: fix a BUG_ON in ddebug_describe_flags Date: Wed, 27 Nov 2019 10:50:58 -0700 Message-Id: <20191127175058.1351461-1-jim.cromie@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ddebug_describe_flags currently fills a caller provided string buffer, after testing its size (also passed) in a BUG_ON. Fix this with a struct containing a known-big-enough string buffer, and passing it instead. Signed-off-by: Jim Cromie --- 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 b5fb0aa0fbc3..0e4783e11755 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -62,6 +62,8 @@ struct ddebug_iter { unsigned int idx; }; +struct flagsbuf { char buf[12]; }; /* big enough to hold all the flags */ + static DEFINE_MUTEX(ddebug_lock); static LIST_HEAD(ddebug_tables); static int verbose; @@ -88,21 +90,19 @@ static struct { unsigned flag:8; char opt_char; } opt_array[] = { }; /* 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 vnpr_info(lvl, fmt, ...) \ @@ -148,7 +148,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 flags; /* search for matching ddebugs */ mutex_lock(&ddebug_lock); @@ -205,8 +205,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, &flags)); } } mutex_unlock(&ddebug_lock); @@ -820,7 +819,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; v9pr_info("called m=%p p=%p\n", m, p); @@ -833,7 +832,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.23.0