From patchwork Tue Apr 11 09:10:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 97225 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1716799qgd; Tue, 11 Apr 2017 02:10:57 -0700 (PDT) X-Received: by 10.84.195.1 with SMTP id i1mr73357742pld.175.1491901857096; Tue, 11 Apr 2017 02:10:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71si16261583pge.184.2017.04.11.02.10.56; Tue, 11 Apr 2017 02:10:57 -0700 (PDT) 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=@linaro.org; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754323AbdDKJKv (ORCPT + 23 others); Tue, 11 Apr 2017 05:10:51 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33603 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754177AbdDKJKq (ORCPT ); Tue, 11 Apr 2017 05:10:46 -0400 Received: by mail-pg0-f49.google.com with SMTP id x125so119555980pgb.0 for ; Tue, 11 Apr 2017 02:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nnuTnHvCV/hHKFP6FEqE4sO9EAhQpGt/MWLr6z+Wlac=; b=g7zC4FemzOdD65xQRJq9bRFFsFdfpx28ITCszytd3W+2JzTAk8XADVl+fK+f5A5soW Hj+OKwGJKGcj03OyUT11zYBSqqfgFivSthGdQ2eLWMqysOM64nNTB6Fuiqii3G/Cmqas zsjNz9k7q/uW5bmjhnqGiO3pZoFhF/U1TszDg= 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:in-reply-to :references; bh=nnuTnHvCV/hHKFP6FEqE4sO9EAhQpGt/MWLr6z+Wlac=; b=RzYpJiyIkR+FDMWvH5w4jd0KNT0y9fOyxJ06UGsr5MFwfIBeN09Ls+pf2yIQqk3DIW T48yeDbLhQPbaSlaxaeCec0+IlM6Ue6UxIlUS/FKNQBeBCvzWmKJE1LPAQtumgmUHGkr doAYbgiAJtK+wMYXEEoEOX01ZOv8WGJWV9PGmG8uOIraq4gH/wXFCKrAP2avslzfom9Q XycoAGs/sI+8xbdlRoXYEJOvHbpM7NYLaKBXH1kB3eqXyEpI5LfgSH8zDL80dhfamVjn 6PVdBNsrx+vyDMg2YsVuQEGfSso80cVhWPMfCDzVTMfo6odBV+9s8lQcKZBX8byc2ji1 ESDQ== X-Gm-Message-State: AFeK/H2xbMG6qkbtWq9UnZ5WjyW5GdTaDxRydXwJlLPWvcnobNQ7o2jiBWNXBPKdp5ywYG9x X-Received: by 10.98.89.70 with SMTP id n67mr58796594pfb.224.1491901845427; Tue, 11 Apr 2017 02:10:45 -0700 (PDT) Received: from localhost.localdomain (li1563-109.members.linode.com. [139.162.83.109]) by smtp.gmail.com with ESMTPSA id r77sm8196394pfe.105.2017.04.11.02.10.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 02:10:44 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan , Mike Leach , Suzuki K Poulose Subject: [PATCH RFC 1/4] coresight: tmc: check dump buffer is overflow Date: Tue, 11 Apr 2017 17:10:26 +0800 Message-Id: <1491901829-18477-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491901829-18477-1-git-send-email-leo.yan@linaro.org> References: <1491901829-18477-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the code dumping ETB buffer is terminated when read back value 0xFFFF_FFFF. This is not safe and introduce infinite looping for some cases, e.g. when reset the CPU and read out ETB RAM. Cc: Mathieu Poirier Cc: Mike Leach Cc: Suzuki K Poulose Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-tmc-etf.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 3a1c181..6150dac 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -54,6 +54,13 @@ static void tmc_etb_dump_hw(struct tmc_drvdata *drvdata) read_data = readl_relaxed(drvdata->base + TMC_RRD); if (read_data == 0xFFFFFFFF) return; + + /* Check if allocated buffer is overflow */ + if (drvdata->len >= drvdata->size) { + dev_info(drvdata->dev, "TMC dump overflow!\n"); + return; + } + memcpy(bufp, &read_data, 4); bufp += 4; drvdata->len += 4;