From patchwork Sat Jul 5 20:02:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 4488841 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7DBC8BEEAA for ; Sat, 5 Jul 2014 20:02:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B76620251 for ; Sat, 5 Jul 2014 20:02:29 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id B1D292024F for ; Sat, 5 Jul 2014 20:02:27 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 10D6F265550; Sat, 5 Jul 2014 22:02:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id F309526553F; Sat, 5 Jul 2014 22:02:14 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1330A265540; Sat, 5 Jul 2014 22:02:14 +0200 (CEST) Received: from smtprelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by alsa0.perex.cz (Postfix) with ESMTP id ECAFF26553B for ; Sat, 5 Jul 2014 22:02:05 +0200 (CEST) Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 576BF26919C; Sat, 5 Jul 2014 20:02:04 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: power05_4c2a6361c6a4d X-Filterd-Recvd-Size: 2346 Received: from [192.168.1.162] (pool-71-103-235-196.lsanca.fios.verizon.net [71.103.235.196]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Sat, 5 Jul 2014 20:02:03 +0000 (UTC) Message-ID: <1404590522.6384.62.camel@joe-AO725> From: Joe Perches To: Takashi Iwai Date: Sat, 05 Jul 2014 13:02:02 -0700 X-Mailer: Evolution 3.10.4-0ubuntu1 Mime-Version: 1.0 Cc: alsa-devel@alsa-project.org, LKML Subject: [alsa-devel] [PATCH] ALSA: hda - Fix and neaten print_nid_path/debug_badness X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP print_nid_path has a possible buffer overflow if struct nid_path.path values are > 256. Avoid this and neaten the output to remove the leading ':' Neaten debug_badness to always verify arguments. Signed-off-by: Joe Perches --- sound/pci/hda/hda_generic.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 589e47c..b293583 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -350,16 +350,16 @@ static void print_nid_path(struct hda_codec *codec, const char *pfx, struct nid_path *path) { char buf[40]; + char *pos = buf; int i; + *pos = 0; + for (i = 0; i < path->depth; i++) + pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x", + pos != buf ? ":" : "", + path->path[i]); - buf[0] = 0; - for (i = 0; i < path->depth; i++) { - char tmp[4]; - sprintf(tmp, ":%02x", path->path[i]); - strlcat(buf, tmp, sizeof(buf)); - } - codec_dbg(codec, "%s path: depth=%d %s\n", pfx, path->depth, buf); + codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf); } /* called recursively */ @@ -1700,9 +1700,11 @@ static int fill_and_eval_dacs(struct hda_codec *codec, #define DEBUG_BADNESS #ifdef DEBUG_BADNESS -#define debug_badness(fmt, args...) codec_dbg(codec, fmt, ##args) +#define debug_badness(fmt, ...) \ + codec_dbg(codec, fmt, ##__VA_ARGS__) #else -#define debug_badness(...) +#define debug_badness(fmt, ...) \ + do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0) #endif #ifdef DEBUG_BADNESS