From patchwork Fri Apr 22 17:14:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 66483 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp839981qge; Fri, 22 Apr 2016 10:16:50 -0700 (PDT) X-Received: by 10.98.22.129 with SMTP id 123mr28699968pfw.74.1461345410807; Fri, 22 Apr 2016 10:16:50 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id s11si8590676pal.172.2016.04.22.10.16.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 10:16:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ategJ-0004k9-F8; Fri, 22 Apr 2016 17:15:51 +0000 Received: from mail-ig0-x230.google.com ([2607:f8b0:4001:c05::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atefQ-0001Lc-Rt for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 17:14:57 +0000 Received: by mail-ig0-x230.google.com with SMTP id bi2so19184453igb.0 for ; Fri, 22 Apr 2016 10:14:35 -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=dI6I9f6oB/MpBrk/oC2FqwM0mYwubj6+7khylR2YSm0=; b=DH7KhOlaGzKDDCmvaz0yMqTZTlF8bnHiF3dde5N3sGTYqgSNQiq4/cncfeqUbBUhRC 2Ay+PBPA9+IYC/TiRrncg2fymdGa2fL/7UR0+4055BtG04GgALWNs3U4Gw/wg41CMVZ0 8BG3ojF1gg5SfJ8fnGEH2RKXI7z6fJNgDH/zQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dI6I9f6oB/MpBrk/oC2FqwM0mYwubj6+7khylR2YSm0=; b=fXByWzJEIZJG2Jrk5lNshbZiMhhvZusNsZAuNDa6Dd5qpY4nWTTT4yx5cqX2aKlKqp FPj+R8lw3/k3cZ9w+L5TpFHgCYKph02c3AEs4jmoqatpMar/Mj+uS3syDFPIA340PiHK kvvdr+/tQVcyNJZ7SpYXaVj7fcqpNP6+3rFm4iCVYowO/0VW9PeoAKlFTn/xq9iQduoy ZGXvn0p2So3Hw+Mpxk72dqwJ/Ha4eCJk6kmDPfy3YKvJY+lCWkIfh0YrXO1nBXauJLDm DUK0EQiztqZlYDpYXMJ2cDrBAB60I9qkMCGqAWLC+DYA2jaC3un4JjgdgcS5MsjobvkS P2mQ== X-Gm-Message-State: AOPr4FV0mvxcEIHicI8q/v3RCl665sm0qTGIKY192RL2XhSY4yglnUgR5lHFmsoCzjmrizTH X-Received: by 10.50.67.36 with SMTP id k4mr5891057igt.89.1461345275373; Fri, 22 Apr 2016 10:14:35 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id vg8sm1975886igb.15.2016.04.22.10.14.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Apr 2016 10:14:34 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org, Suzuki.Poulose@arm.com Subject: [PATCH V3 10/18] coresight: tmc: getting the right read_count on tmc_open() Date: Fri, 22 Apr 2016 11:14:07 -0600 Message-Id: <1461345255-11758-11-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1461345255-11758-1-git-send-email-mathieu.poirier@linaro.org> References: <1461345255-11758-1-git-send-email-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160422_101457_124166_76AF3809 X-CRM114-Status: GOOD ( 11.15 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:4001:c05:0:0:0:230 listed in] [list.dnswl.org] -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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org In function tmc_open(), if tmc_read_prepare() fails variable drvdata->read_count is not decremented, causing unwanted access to drvdata->buf and very likely, a crash dump. By moving the incrementation to a place where we know things are stable this kind of situation is avoided. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-tmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index e8e12a9b917a..55806352b1f1 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -121,13 +121,14 @@ static int tmc_open(struct inode *inode, struct file *file) struct tmc_drvdata, miscdev); int ret = 0; - if (drvdata->read_count++) + if (drvdata->read_count) goto out; ret = tmc_read_prepare(drvdata); if (ret) return ret; out: + drvdata->read_count++; nonseekable_open(inode, file); dev_dbg(drvdata->dev, "%s: successfully opened\n", __func__);