From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 280A6C433E2 for ; Thu, 3 Sep 2020 17:24:35 +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 DC28F20716 for ; Thu, 3 Sep 2020 17:24:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1ZUBfQ8z"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ARNpr17r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC28F20716 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+linux-arm-kernel=archiver.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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OXt2WjUcHXUTYZsNmLfIbUtc4UX/T8sjXqRm7LtYpUg=; b=1ZUBfQ8z52+swreEWpdQOQv8l 92xm6BJIO57960NQmXtRZCzyelkr/yTyNe2Va+Im5OrjRkbrcdJFlt+UZvYvaqYG11QSwJGrxHTTB WSzW9kz8srA4c0BDHNz2Z9MYsSNQ8JlgvG08SUG+Z/JLi8rNZh57P6o2dN/aRI+E7SOOitU/phmF6 0InL0BQSGDL3vGnGyBwx2O80pigbZmntGo32yFmdfP4FPN4SC6N0hhT2U2odYL0K6ThUSC580EuQn FljAzHEGYq/IqvBPFX9EBmKie6ImQgz0NaS4TAMIHv2aGIi5ZIDw9k9aHjdaY458bC5HR0qwsQU3g ldA4xm44w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDswl-0001bQ-Ok; Thu, 03 Sep 2020 17:22:51 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDswj-0001an-C2 for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 17:22:50 +0000 Received: by mail-pg1-x543.google.com with SMTP id w186so2659765pgb.8 for ; Thu, 03 Sep 2020 10:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oH9bG2LzZYIUIlt0WTtaa8D6pgGt/aLB6riSA0Eu3JM=; b=ARNpr17rmGAOqTIAhFjWAFjYiSE+KHTwha0M4CsIj8Qhssmi7ht/uBYIZF9F/1r8e9 grarJNrO081eb53t/HKKO9JqsU1wU1HRZWeVHU0CtQpJM1eBO+9mFkE2hfBTlSjXe3kb LE61S3GRtENVCXLNw3BNfwx3etGcGCehI/NbhXpkNfol8doOxBM8Chk2/ss+1swg/xuz fru+wUoi4pZEsN7C7LMBOFoiuz0kAfAFDjpGD65M3q5JozDlzgXQVKFDXHEGKQHHTZTO TOOol5bpy6fBMaScCbiYpmzlPpPN7ZjKbPSyLBV4e1NDzI0q+YAhn9EjybeA2hOch1PK /wKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oH9bG2LzZYIUIlt0WTtaa8D6pgGt/aLB6riSA0Eu3JM=; b=mn7UHtn/D8+c9ouymdRUsX+nhxkrMV82/WAf+hb2OnZ8xgmBRAJwoOj0ZaikTnA+Qp F1rNY2b/LseOBC1prBq8oXNM5fxXa/cMWycUIfmq5Q6e2RiB5MytrX6valVREyeNAXCs KDsa1sjvfW5IVznJ41xbflxtd/XmYfY7Uo2ULDSEwahvqPYUKDbIBkQD92uhJ45EuGdu IJjri6YoOzZyvUwhbNwsd2wKQM3Ajw8TDYLaOcvuqh9D7bP0JKILazUC9ec8zVtE8hjm N1U9s4CYaF1VXYIYuMvYWh2ZdwhxOfh66U4hNk7Uq9hz9MGebG9D/c8nC1KzvIG+81bD DUrw== X-Gm-Message-State: AOAM5303jEEjKdixKPglg3rsRCTWcGK/J/S1M4AfdYjuwYO//w5WLV2X ne+ES9c4iBiVoQ9g9rlnFlfDSA== X-Google-Smtp-Source: ABdhPJyWlQ0O0wgYk+RdhRoq5zF4vBWk/8tx16nYKS6hOirWIzeAnsVEuoZO0Lxg/NC2Apdm+AjGyA== X-Received: by 2002:a63:5952:: with SMTP id j18mr3917467pgm.317.1599153765338; Thu, 03 Sep 2020 10:22:45 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id hg16sm3048066pjb.37.2020.09.03.10.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 10:22:44 -0700 (PDT) Date: Thu, 3 Sep 2020 11:22:43 -0600 From: Mathieu Poirier To: Jonathan Zhou Subject: Re: [PATCH] coresight: etm4x: fix mis-usage of nr_resource in sysfs interface Message-ID: <20200903172243.GB312784@xps15> References: <1599033176-39808-1-git-send-email-jonathan.zhouwen@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1599033176-39808-1-git-send-email-jonathan.zhouwen@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_132249_446228_561F885D X-CRM114-Status: GOOD ( 24.97 ) 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: Shaokun Zhang , lizixian@hisilicon.com, Mike Leach , linux-arm-kernel@lists.infradead.org, Suzuki K Poulose Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 02, 2020 at 03:52:56PM +0800, Jonathan Zhou wrote: > 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 displaying the implemented resource seletors > and resetting the seletor 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 > Signed-off-by: Jonathan Zhou > --- > drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c > index b673e738bc9a..635b93d20efa 100644 > --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c > +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c > @@ -143,8 +143,10 @@ static ssize_t nr_resource_show(struct device *dev, > { > unsigned long val; > struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); > - > - val = drvdata->nr_resource; > + /* @nr_resource represents how many resource selector pairs, > + * hence multiply by 2. Your comment said it correctly, @nr_resource present the number of _pairs_. As such the code is correct and there is no need to multiply by 2. > + */ > + val = 2 * drvdata->nr_resource; > return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); > } > static DEVICE_ATTR_RO(nr_resource); > @@ -236,7 +238,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; This hunk is correct - please send a patch for it. > > config->ss_idx = 0x0; > @@ -1663,8 +1665,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 == 0) || (val == 1) || (val >= 2 * drvdata->nr_resource)) > return -EINVAL; The index, i.e ->res_idx, represent pairs an not individual resource. Thanks, Mathieu > > /* > -- > 1.9.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel