From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB47C301475 for ; Mon, 1 Dec 2025 10:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764584730; cv=none; b=OMiK7UDaC/8dnrynTeLAJOkm0HQeuZIJlEyudVl48FHyDKtHKlquDhBmcavq9cwkvEiWhsrZQt4b6AFSYZlHlFC9H2n+UiU7RTxbewxeZQzeJ2xAOepHE/Lg4KpWjHgY7nC7h7/DAuNZm/3uuNONMYzs+cUXXd7QFwkJOfnNJ00= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764584730; c=relaxed/simple; bh=82O3xznoxCLEfWqOgjs3vgvkB/cevrQD2ffzopciyKI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PjY3F18KXtbY1G1MNyA/DR7GNnHvr8TlLqBC57dQKzCKTnxYdOAAduF0T7FY5owS5C7owPiuF+1b1G7aPyDOXrPGGyjmNre7IObW51rRGqevtejMLBFJ6OKT5nZlfKpS75vnBm4pj+x0UM+swMDKK2WUE7crThvUpna8xw5hfOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TePn2ziu; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TePn2ziu" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4779a4fc95aso32187745e9.1 for ; Mon, 01 Dec 2025 02:25:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764584727; x=1765189527; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AOnEw3BZnfclp4gqXFuh5EU5EE3a2Dn8SHSXTdmn3IQ=; b=TePn2ziu1MLWBQtlU3NbUl1cr4Q613Q7VX2koGDN3fwgosjo4pcCemd9Wp2eAf2ZG2 7cpYZILkYGjgzQhfkK8mzOFMD+63Hj1+qxovHKsqxQGLSRCJuf0CmSDf7VINJlxOI1eb u9WvMYRAHTUQ69jJYv4VwZ0tRslQ+SWQk8vr3c7EqZlPobyaCO3bJVx4xuk3vLvzya4M /oVsi9xRj+YP5J9asp7CfNgNX7dXlLR0+nZsyaqXdbeYFDZ7ZiQdHDr9ONeW+A6ZWg2M 9In9Tw9xCjtgGyLAeymW/+UbHX8yeAeWSezh8X0fSSeQT3usmimJ+aeQwjKNyVSteE+r QV7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764584727; x=1765189527; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AOnEw3BZnfclp4gqXFuh5EU5EE3a2Dn8SHSXTdmn3IQ=; b=iHnVw7qGP5UwzXrW4lEjTAW09YgeXG85xNBc8vyPRfS5sZOXoxn2lvqIVLQ9idpQLE rHninQnlbnJTUkRNnWacVMTxdkwjAMKB0zkUQiszTbl0r+cHuBH9ptZGSXnZLHhw26ce ERDG6/JNPbI7rDjP5VhkBGo1S+T00QkPFoWFEs4Ih3rx5Br8QtY+xSkiUF+cOiQgUHx4 bUEjfrhG6hcCCjQZql9BaEvfqCcyAfP34VEHSPcPisCoZFcQTRk7yTDiCvh0heIkBhSy AqHxeJyFvWsieczC87yGdsJEaYFRNYzBH0+4dGJMwyzwBWYzpaMeXr6xigvL2gkmPhPe QUbA== X-Forwarded-Encrypted: i=1; AJvYcCVKCdD+ZavAq+NPpZzgnmEBBHUIFiUFMebWaVNCJQztZ3QyZMZdr92QraNy82EwarVWoPrqc89MJJSczxA=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5GGKCMJyeWPQ/uDVMLBzvrJ2xpSqPXjkMY+8vwRMMYa1uyCw/ YlAcgK/SDhUB/1mqiFcJi3+/va/K2+GoQAER4W/VKlxzm3jrXL7TvwoH1bV9EwWMpPYVcuwvv/o hhLqr X-Gm-Gg: ASbGncswO2TWfIZAacomY+2Ow1LmO8CMiA2pirL4PU+duOuYvzILlHBYVyileyXWk/O nkslgN3mwTCJNuOzj89k+QXP1cSC+nbG8jGI6X0b1iR0e0mjOWT23d5xRqoCfaHKzePVdAAyBYZ E97YA9lDTDtDADuu3s4ya14MHEvqdL8xh9KkiTnSgoekEtHfdC8YgG8K0vSpJaKgiU3Mns2oQE5 EgWaOjLA70QA7MXzUdIXCNHz47SI3LfZ5BUeWtI9I9I/y1YKoLOovAf0JgjEVzcKwVlidv3H9fi 2iJNi1n1cvD/ukkzOamOfyHOVHy3HL2oO5H4ZBy93PJ8fUWU387z/YQGp49/fvNy7x/1C7uQcg8 Uk9gzuK4TQDlFrlolCawUnmILWvDk5IAMnBgugOKxbDbhz58mvK3bPhb/Dvste34Vax1GEcqJaT Adfa9TnLuuyoJzd96Z X-Google-Smtp-Source: AGHT+IGqN47TqQgE3W2/IvK3HzwKJr3Fu8oiKkh2wb31imC8aKtsl+rRxsn5mYsKl7E7agf7UAaT6A== X-Received: by 2002:a05:600c:4eca:b0:46f:a2ba:581f with SMTP id 5b1f17b1804b1-477c0540a68mr422574995e9.16.1764584726968; Mon, 01 Dec 2025 02:25:26 -0800 (PST) Received: from [192.168.1.3] ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-479040b3092sm153686955e9.1.2025.12.01.02.25.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Dec 2025 02:25:26 -0800 (PST) Message-ID: Date: Mon, 1 Dec 2025 10:25:25 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] coresight: etm3x: Fix cntr_val_show() to match cntr_val_store() behavior To: Kuan-Wei Chiu , suzuki.poulose@arm.com Cc: mike.leach@linaro.org, alexander.shishkin@linux.intel.com, gregkh@linuxfoundation.org, mathieu.poirier@linaro.org, leo.yan@arm.com, Al.Grant@arm.com, jserv@ccns.ncku.edu.tw, marscheng@google.com, ericchancf@google.com, milesjiang@google.com, nickpan@google.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20251201095228.1905489-1-visitorckw@gmail.com> Content-Language: en-US From: James Clark In-Reply-To: <20251201095228.1905489-1-visitorckw@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 01/12/2025 9:52 am, Kuan-Wei Chiu wrote: > The cntr_val_show() function was intended to print the values of all > counters using a loop. However, due to a buffer overwrite issue with > sprintf(), it effectively only displayed the value of the last counter. > > The companion function, cntr_val_store(), allows users to modify a > specific counter selected by 'cntr_idx'. To maintain consistency > between read and write operations and to align with the ETM4x driver > behavior, modify cntr_val_show() to report only the value of the > currently selected counter. > > This change removes the loop and the "counter %d:" prefix, printing > only the hexadecimal value. It also adopts sysfs_emit() for standard > sysfs output formatting. > > Fixes: a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver") > Signed-off-by: Kuan-Wei Chiu > --- > Build test only. > > Changes in v2: > - Redesigned the fix to match cntr_val_store() logic (display only the > currently selected counter) instead of attempting to list all > counters. > - Removed the loop and the "counter %d:" prefix. > - Switched from sprintf() to sysfs_emit(). > - Refactored control flow to use a single return point. > > v1: https://lore.kernel.org/lkml/20251121002350.1166758-1-visitorckw@gmail.com/ > > .../hwtracing/coresight/coresight-etm3x-sysfs.c | 15 ++++----------- > 1 file changed, 4 insertions(+), 11 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > index 762109307b86..a6a650331196 100644 > --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > @@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event); > static ssize_t cntr_val_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > - int i, ret = 0; > u32 val; > struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); > struct etm_config *config = &drvdata->config; > > if (!coresight_get_mode(drvdata->csdev)) { > spin_lock(&drvdata->spinlock); > - for (i = 0; i < drvdata->nr_cntr; i++) > - ret += sprintf(buf, "counter %d: %x\n", > - i, config->cntr_val[i]); > + val = config->cntr_val[config->cntr_idx]; > spin_unlock(&drvdata->spinlock); > - return ret; > - } > - > - for (i = 0; i < drvdata->nr_cntr; i++) { > - val = etm_readl(drvdata, ETMCNTVRn(i)); > - ret += sprintf(buf, "counter %d: %x\n", i, val); > + } else { > + val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx)); > } > > - return ret; > + return sysfs_emit(buf, "%x\n", val); Sorry I missed this on the previous version, but this should be %#x to add the "0x" prefix. All the other ones in this file have it. Otherwise you can't tell the difference between decimal and hex. > } > > static ssize_t cntr_val_store(struct device *dev,