From patchwork Thu Jan 30 16:11:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Adrien_Verg=C3=A9?= X-Patchwork-Id: 315402 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3021E2C014B for ; Fri, 31 Jan 2014 03:13:57 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8uEP-0000kA-5u; Thu, 30 Jan 2014 16:12:45 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8uEB-000404-7M; Thu, 30 Jan 2014 16:12:31 +0000 Received: from mail-ie0-x236.google.com ([2607:f8b0:4001:c03::236]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8uDo-0003tQ-LB for linux-arm-kernel@lists.infradead.org; Thu, 30 Jan 2014 16:12:09 +0000 Received: by mail-ie0-f182.google.com with SMTP id lx4so3512466iec.13 for ; Thu, 30 Jan 2014 08:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ibmlfazesc4MzWPrpD2R9awj6/HgfJBJL5Vmpc8K/Ms=; b=q+hyeKbSX1WKsRR52F/71WwyY/OKdHVHC8ryaBSLWgV91yMErAAaBQ4Lei0ysQhNdV kGMAmiqdbHgjvW25W3nLlmuMG+bqexsc6gIWU8gLRTtaVGCvFztopxu/RxT2hyuh6oQO c6LO1qIhhLyWVz8s7FibGK7s1dfqa5DwmUZDAk6vPmiNXf+TfzxeC+cm20c57T/N5QJN YlfY/MPGPDwLOwi1hfSmx2v4Zff4M7aBnEazmBHEfYPrczs8GZJX2fOWYpG7iy5e98Hx BZoV9l9zVV50D8qLGUEntZR/Xp0icN/2cbt1Ys5zoCkURw+q5onqnFTZfr7NCfznaTAW CThg== X-Received: by 10.50.45.33 with SMTP id j1mr34901869igm.32.1391098307443; Thu, 30 Jan 2014 08:11:47 -0800 (PST) Received: from station14.dorsal.polymtl.ca ([132.207.72.19]) by mx.google.com with ESMTPSA id a1sm21545415igo.0.2014.01.30.08.11.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jan 2014 08:11:46 -0800 (PST) From: =?UTF-8?q?Adrien=20Verg=C3=A9?= To: Russell King Subject: [PATCH V3 1/5] ARM CoreSight: ETM: Fix a memory allocation failure Date: Thu, 30 Jan 2014 11:11:06 -0500 Message-Id: <1391098270-8867-2-git-send-email-adrienverge@gmail.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391098270-8867-1-git-send-email-adrienverge@gmail.com> References: <1391098270-8867-1-git-send-email-adrienverge@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140130_111208_861608_8637427A X-CRM114-Status: GOOD ( 13.18 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (adrienverge[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Dirk Behme , Mathieu Poirier , Catalin Marinas , Randy Dunlap , Will Deacon , linux-kernel@vger.kernel.org, Michel Dagenais , Ben Dooks , Christopher Covington , =?UTF-8?q?Adrien=20Verg=C3=A9?= , Andrew Morton , linux-arm-kernel@lists.infradead.org, "zhangwei\(Jovi\)" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org When an application reads the ETB buffer too often, it can be empty. In this case, it results in a "vmalloc: allocation failure: 0 bytes", a backtrace in dmesg and a vfree on an incorrect address. This patch allocates and frees the trace buffer only when necessary. Signed-off-by: Adrien Vergé --- arch/arm/kernel/etm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm/kernel/etm.c b/arch/arm/kernel/etm.c index 8ff0ecd..5192693 100644 --- a/arch/arm/kernel/etm.c +++ b/arch/arm/kernel/etm.c @@ -275,7 +275,7 @@ static ssize_t etb_read(struct file *file, char __user *data, long length; struct tracectx *t = file->private_data; u32 first = 0; - u32 *buf; + u32 *buf = NULL; mutex_lock(&t->mutex); @@ -293,12 +293,14 @@ static ssize_t etb_read(struct file *file, char __user *data, etb_writel(t, first, ETBR_READADDR); length = min(total * 4, (int)len); - buf = vmalloc(length); + if (length != 0) + buf = vmalloc(length); dev_dbg(t->dev, "ETB buffer length: %d\n", total); dev_dbg(t->dev, "ETB status reg: %x\n", etb_readl(t, ETBR_STATUS)); - for (i = 0; i < length / 4; i++) - buf[i] = etb_readl(t, ETBR_READMEM); + if (buf) + for (i = 0; i < length / 4; i++) + buf[i] = etb_readl(t, ETBR_READMEM); /* the only way to deassert overflow bit in ETB status is this */ etb_writel(t, 1, ETBR_CTRL); @@ -311,7 +313,8 @@ static ssize_t etb_read(struct file *file, char __user *data, etb_lock(t); length -= copy_to_user(data, buf, length); - vfree(buf); + if (buf) + vfree(buf); out: mutex_unlock(&t->mutex);