mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shi Hao <i.shihao.999@gmail.com>
To: koby.elbaz@intel.com
Cc: konstantin.sinyuk@intel.com, ogabbay@kernel.org,
	i.shihao.999@gmail.com, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] accel: goya: replace sprintf() with sysfs_emit()
Date: Fri, 31 Oct 2025 00:05:29 +0530	[thread overview]
Message-ID: <20251030183529.93665-1-i.shihao.999@gmail.com> (raw)

Replace deprecated sprintf() with sysfs_emit() in various sysfs show
functions to avoid buffer overflows.

The sysfs_emit() function is specifically designed for sysfs show handlers
and provides built-in bounds checking by limiting output to PAGE_SIZE,
unlike sprintf() which has no bounds checking. This prevents buffer
overflows that could result in kernel crashes or potential security
vulnerabilities.

Convert sprintf() to sysfs_emit() as per kernel code practices and
guidelines.

Signed-off-by: Shi Hao <i.shihao.999@gmail.com>
---
 drivers/accel/habanalabs/goya/goya_hwmgr.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/accel/habanalabs/goya/goya_hwmgr.c b/drivers/accel/habanalabs/goya/goya_hwmgr.c
index b595721751c1..3ef18f42c393 100644
--- a/drivers/accel/habanalabs/goya/goya_hwmgr.c
+++ b/drivers/accel/habanalabs/goya/goya_hwmgr.c
@@ -49,7 +49,7 @@ static ssize_t mme_clk_show(struct device *dev, struct device_attribute *attr,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t mme_clk_store(struct device *dev, struct device_attribute *attr,
@@ -98,7 +98,7 @@ static ssize_t tpc_clk_show(struct device *dev, struct device_attribute *attr,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t tpc_clk_store(struct device *dev, struct device_attribute *attr,
@@ -147,7 +147,7 @@ static ssize_t ic_clk_show(struct device *dev, struct device_attribute *attr,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t ic_clk_store(struct device *dev, struct device_attribute *attr,
@@ -196,7 +196,7 @@ static ssize_t mme_clk_curr_show(struct device *dev,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t tpc_clk_curr_show(struct device *dev,
@@ -213,7 +213,7 @@ static ssize_t tpc_clk_curr_show(struct device *dev,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t ic_clk_curr_show(struct device *dev,
@@ -230,7 +230,7 @@ static ssize_t ic_clk_curr_show(struct device *dev,
 	if (value < 0)
 		return value;

-	return sprintf(buf, "%lu\n", value);
+	return sysfs_emit(buf, "%lu\n", value);
 }

 static ssize_t pm_mng_profile_show(struct device *dev,
@@ -242,7 +242,7 @@ static ssize_t pm_mng_profile_show(struct device *dev,
 	if (!hl_device_operational(hdev, NULL))
 		return -ENODEV;

-	return sprintf(buf, "%s\n",
+	return sysfs_emit(buf, "%s\n",
 			(goya->pm_mng_profile == PM_AUTO) ? "auto" :
 			(goya->pm_mng_profile == PM_MANUAL) ? "manual" :
 			"unknown");
@@ -313,7 +313,7 @@ static ssize_t high_pll_show(struct device *dev, struct device_attribute *attr,
 	if (!hl_device_operational(hdev, NULL))
 		return -ENODEV;

-	return sprintf(buf, "%u\n", hdev->high_pll);
+	return sysfs_emit(buf, "%u\n", hdev->high_pll);
 }

 static ssize_t high_pll_store(struct device *dev, struct device_attribute *attr,
@@ -369,7 +369,7 @@ static ssize_t infineon_ver_show(struct device *dev, struct device_attribute *at

 	cpucp_info = &hdev->asic_prop.cpucp_info;

-	return sprintf(buf, "%#04x\n", le32_to_cpu(cpucp_info->infineon_version));
+	return sysfs_emit(buf, "%#04x\n", le32_to_cpu(cpucp_info->infineon_version));
 }

 static DEVICE_ATTR_RO(infineon_ver);
--
2.51.0


             reply	other threads:[~2025-10-30 18:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30 18:35 Shi Hao [this message]
2025-11-29 20:35 ` Sinyuk, Konstantin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251030183529.93665-1-i.shihao.999@gmail.com \
    --to=i.shihao.999@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=koby.elbaz@intel.com \
    --cc=konstantin.sinyuk@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®