From patchwork Wed Sep 16 19:17:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11780633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E60059D for ; Wed, 16 Sep 2020 19:20:06 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 048902075E for ; Wed, 16 Sep 2020 19:20:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NwQ6UlSI"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="k1qCnGcV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 048902075E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aCYHn7CwqLc38gtVq/HQ1CkuMZ+m8Wam1BRuj43ss3w=; b=NwQ6UlSIrC5UkgvV4h8Cj1+Xv uqpUI8rOZoacr9Bg+Jrc5Rxzek5N36tUxLCiKRJepbd9IK9ZZoFARnzdCFl+Kt3ddPImmqsooNLIY nOydlgYSeMJlHMgZ5blGe8lkVr0boTCi0zmMlAjuTExWLUUQt8/NP/kggJe4mcdlHrVFejc21xKQq voP6QZJgv2nPJZhD3VR5KZ9fwx1wDvl6gXg0UvKg7ePv2NrbFPOqlPy2M7QDeWhg7W9cfLRIfHVQ/ cDBjpT/TULWDKXThpLeG6C3MA8JCe6UjFfFtLL/b1tArovCD5ODf4E6JQ5/dLwyC32+glruvowZTP J7Ym/EgIA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIcy3-0005yB-RA; Wed, 16 Sep 2020 19:19:47 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIcwH-0005Ao-Ph for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2020 19:18:01 +0000 Received: by mail-pg1-x541.google.com with SMTP id s65so4483612pgb.0 for ; Wed, 16 Sep 2020 12:17:57 -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 :mime-version:content-transfer-encoding; bh=Oe49LMKwv41Q/rKpDAMKCy8PmysOJZGeIA2wNQPMFDo=; b=k1qCnGcV5ydKrYSZmb7z6t2rf8NDhB199Q+CTrqhlDFZH1YPgkXkqdcpHFUUMmFZB2 nhHFszfE//oADI2Sw4apMJE43ezjbPXDFOSqMKV1tVsDWi21ugWht5ff3u12bcaMI+6/ gKwT/4ikJcrErNs8nJDnc/0BGa1jVMx5GqFC5UCkfiMj/OTRXgkyY0erUNFP2t6Ful5I G46dXB435jwkzFyT7iIb/wnTkDJHrtgI3kNHCmCl8lgAplNoM+u4lgjCX7WrMk8LgJYp CSkJ3xoPSXG5ph1DGvftMQa6B/pQ4TFw5+sxZz/tDOGsJ89AT1CbFS3M1cGBoWJez54+ iqSg== 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:mime-version:content-transfer-encoding; bh=Oe49LMKwv41Q/rKpDAMKCy8PmysOJZGeIA2wNQPMFDo=; b=rQBqnji3Qk3YWZ+lY9+ObfWNTUML+6HFiTLzN3SIngBpEdvaT5l2QJp4tryYqbZhV3 UX832r5s02h9epUXru2fi/slzcGX8rdDQvbtUzWPWg9Hp+AFM+JCYVJQaVXa2m1Y05PA trEI9KE+ohjgx/pOHXVTfGmfBnd0kLIN8xL7EBBHzoKn/dLBRFnZCAi1QEfWXYlj0YSX pmeMeFjAoQ5sPPvSy5EusF97/yoBorCmwDvxtWUwSA9coSFq/vWPDh6A/pIormlMfW1h 44K3CAutUeNnn81UmeEbupSXEqJAhpIARZRuPavCta/cvQbhEgBju780Z2uFvVvlUUlF EPFg== X-Gm-Message-State: AOAM533XYehttSoC8xpUromFVW+SLWxJDQhO3v6VG+VMV2HXCywrDThJ qFOgEWLw16XssFQp3pVMa9wzKA== X-Google-Smtp-Source: ABdhPJz4/2EA/zzbsQeVkyxz0UVvQIol29EhFlEroXCYa/7jZJoZG06NJLqej/NQ51x9sw2Vhfh2Ig== X-Received: by 2002:a63:3643:: with SMTP id d64mr2586988pga.207.1600283875709; Wed, 16 Sep 2020 12:17:55 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b2sm11373688pfp.3.2020.09.16.12.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 12:17:55 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Subject: [PATCH 15/16] coresight: etm4x: Fix mis-usage of nr_resource in sysfs interface Date: Wed, 16 Sep 2020 13:17:36 -0600 Message-Id: <20200916191737.4001561-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200916191737.4001561-1-mathieu.poirier@linaro.org> References: <20200916191737.4001561-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200916_151757_896140_5F5E5337 X-CRM114-Status: GOOD ( 15.44 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jonathan Zhou The member @nr_resource represents how many resource selector pairs, and the pair 0 is always implemented and reserved. So let's multiply by 2 when resetting the selector configuration. And also update the validation of the input @idx. Cc: Mathieu Poirier Cc: Suzuki K Poulose Cc: Mike Leach Cc: Shaokun Zhang Cc: lizixian@hisilicon.com Cc: stable@vger.kernel.org Signed-off-by: Jonathan Zhou [Fixed typographical error in changelog, added stable] Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index a588cd6de01c..989ce7b8ade7 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -236,7 +236,7 @@ static ssize_t reset_store(struct device *dev, } config->res_idx = 0x0; - for (i = 0; i < drvdata->nr_resource; i++) + for (i = 2; i < 2 * drvdata->nr_resource; i++) config->res_ctrl[i] = 0x0; config->ss_idx = 0x0; @@ -1663,8 +1663,11 @@ static ssize_t res_idx_store(struct device *dev, if (kstrtoul(buf, 16, &val)) return -EINVAL; - /* Resource selector pair 0 is always implemented and reserved */ - if ((val == 0) || (val >= drvdata->nr_resource)) + /* + * Resource selector pair 0 is always implemented and reserved, + * namely an idx with 0 and 1 is illegal. + */ + if ((val < 2) || (val >= 2 * drvdata->nr_resource)) return -EINVAL; /*