From patchwork Tue Apr 12 17:54:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 65652 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2060379qge; Tue, 12 Apr 2016 10:57:44 -0700 (PDT) X-Received: by 10.66.235.129 with SMTP id um1mr6377940pac.17.1460483864037; Tue, 12 Apr 2016 10:57:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si11089275pfj.116.2016.04.12.10.57.43; Tue, 12 Apr 2016 10:57:44 -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 dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757271AbcDLR53 (ORCPT + 29 others); Tue, 12 Apr 2016 13:57:29 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:36856 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966176AbcDLRzK (ORCPT ); Tue, 12 Apr 2016 13:55:10 -0400 Received: by mail-pf0-f177.google.com with SMTP id e128so17749071pfe.3 for ; Tue, 12 Apr 2016 10:55:10 -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=JkkTe7XP23WpJaP7eZ43pZNQ+P2uuHHIv47Yw0Dfoo8=; b=hX87G6Lj1UhItG+g5VgoV1q5f3YagXAIuylpEjjWng2KNoDATe3COhRAh/SCMKey9t Zt8CwPgpsHbEz/xY8S4u5DSM01UGDE9m4L8zHmu9VtxcxIb2XlXOcvtN9uv19klzA3Kw o9so6gdb2gGVnRqUA8ySaHaYlssqTqXnp0Q0o= 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=JkkTe7XP23WpJaP7eZ43pZNQ+P2uuHHIv47Yw0Dfoo8=; b=Eu7ZU7Pbb7VeP4mqtMy3d5oJ7K5fwWqP2lzBZjzOEQT4ecr6XIIn88SIStpGpOslqa xRxCOhHigQnJPm8fgzv8AC6q/e60ur06LS4H35Vca3R6dyyX/QKtNWygZUMQeUYBGtpV GAB8gIvnd+a/pvFQTvDsgE9uWn94PCvPFrsqpecH1tFmqV0wDnAJ9PUjs8c62IXhtZoZ /UrKgy+TluqZT5gAdjZAVbGlccAzCB9L3wMFmOZNJGWC83TAuTiMBh5CbbKn67r3Jxs1 RdPcCrCScMGKXlg2CATEVrx07AeZPzDIEzu8aCbw4Rhg7IsnT43nff7zFYsGlPvIZwcC SQ5Q== X-Gm-Message-State: AOPr4FXHHTZbke94u6Qm+iBFe2haCotx3xG4b+H5HyShzFXVVoABVLaqki8W5KXBfAL3CIzI X-Received: by 10.98.14.207 with SMTP id 76mr6470168pfo.1.1460483709649; Tue, 12 Apr 2016 10:55:09 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p189sm24633204pfb.51.2016.04.12.10.55.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Apr 2016 10:55:08 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org, Suzuki.Poulose@arm.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH V2 08/15] coresight: tmc: getting the right read_count on tmc_open() Date: Tue, 12 Apr 2016 11:54:45 -0600 Message-Id: <1460483692-25061-9-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460483692-25061-1-git-send-email-mathieu.poirier@linaro.org> References: <1460483692-25061-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- drivers/hwtracing/coresight/coresight-tmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.5.0 diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index ae336641518f..4d7b64f69389 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__);