From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 978103F4DD2; Fri, 4 Sep 2026 06:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788502343; cv=none; b=lrubLKiI4j6kiGDKQOCyxas0GAw9LqmKGZHYnummM/GKPYZh+2EKbBNWtQhY7jQP2tsd7MZAN2m2Kedq1gOkUum0x9V+5+qrz1s4PmumK0EQtIGswJHhaqyzT4gn1S/SEiAha6/Mp2+JOZIS9gOw6f5I0p6cC++QUmRcUbJYBiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788502343; c=relaxed/simple; bh=KhTGmrxgLBQQLTfbPY61VobGWBS2Ia/LjvaZPSb0ZAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y1gv6SaSwUAF/fTVV3GKz+1zvBHajesvMtQst7Q3s/p/FA2qhZ45v7T4KWxhwcXDxaYAQdH/GuENf8RzlOq2E9Y12uSJ/8sMGtmQbdxf+5Q3SNpV4jSJxdM3zr/fanzREnALKGZYJ+Nn2lMqJYG3x3OM9iFSMEZ7c7J0+6kTEa4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=o831ISfw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="o831ISfw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6F2A1F00A3E; Fri, 4 Sep 2026 06:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788502342; bh=aQV1/5KrJ7ByINJSqaarzjXdJ+c+JyjGM6SG5NWen4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=o831ISfwLdpia/IZozs3sNWsK3xsdmoUjnDsOZzWmIAw63/xJHyAnq3PktmAn3Gne MhZSWRFUUOGaSNedvZPiX7l2JxU3DXOcuSsGJBXN4OwM5IZBvYmZgZiog6TAdkUO7E YtNS/xQR6JbxrAeaBJCNOxi+VKJuxm04tlT1TjDc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kuan-Wei Chiu , James Clark , Suzuki K Poulose Subject: [PATCH 6.12 172/403] coresight: etm3x: Fix cntr_val_show() to match cntr_val_store() behavior Date: Fri, 4 Sep 2026 06:59:35 +0200 Message-ID: <20260904045738.772164300@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045734.806166532@linuxfoundation.org> References: <20260904045734.806166532@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuan-Wei Chiu commit 41fb4e925528aefa4b7a5f76c7f81db99c0d0f38 upstream. 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") Cc: stable@vger.kernel.org Signed-off-by: Kuan-Wei Chiu Reviewed-by: James Clark Signed-off-by: Suzuki K Poulose Link: https://lore.kernel.org/r/20251202082613.3265761-1-visitorckw@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) --- 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; + } else { + val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx)); } - for (i = 0; i < drvdata->nr_cntr; i++) { - val = etm_readl(drvdata, ETMCNTVRn(i)); - ret += sprintf(buf, "counter %d: %x\n", i, val); - } - - return ret; + return sysfs_emit(buf, "%#x\n", val); } static ssize_t cntr_val_store(struct device *dev,