From: Sumera Priyadarsini <sylphrenadin@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: outreachy-kernel@googlegroups.com, alexander.deucher@amd.com,
christian.koenig@amd.com, airlied@linux.ie, daniel@ffwll.ch,
melissa.srw@gmail.com, linux-media@vger.kernel.org,
amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.or
Subject: [PATCH 3/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit()
Date: Thu, 22 Oct 2020 19:17:04 +0530 [thread overview]
Message-ID: <864a0c5d7bc85d9eeaf1ca7b3db38b58e042471b.1603371258.git.sylphrenadin@gmail.com> (raw)
In-Reply-To: <cover.1603371258.git.sylphrenadin@gmail.com>
Using snprintf() for show() methods holds the risk of buffer overrun
as snprintf() does not know the PAGE_SIZE maximum of the temporary
buffer used to output sysfs content.
Modify amdgpu_gtt_mgr.c to use sysfs_emit() instead which knows the
size of the temporary buffer.
Issue found with Coccinelle.
Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 1721739def84..441e07ee1967 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -49,7 +49,7 @@ static ssize_t amdgpu_mem_info_gtt_total_show(struct device *dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
- return snprintf(buf, PAGE_SIZE, "%llu\n",
+ return sysfs_emit(buf, PAGE_SIZE, "%llu\n",
man->size * PAGE_SIZE);
}
@@ -68,7 +68,7 @@ static ssize_t amdgpu_mem_info_gtt_used_show(struct device *dev,
struct amdgpu_device *adev = drm_to_adev(ddev);
struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
- return snprintf(buf, PAGE_SIZE, "%llu\n",
+ return sysfs_emit(buf, PAGE_SIZE, "%llu\n",
amdgpu_gtt_mgr_usage(man));
}
--
2.25.1
next prev parent reply other threads:[~2020-10-22 13:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-22 13:37 [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit Sumera Priyadarsini
2020-10-22 13:40 ` [PATCH 1/5] gpu: drm: amdgpu: Replace snprintf() with sysfs_emit() Sumera Priyadarsini
2020-10-22 13:43 ` [PATCH 2/5] " Sumera Priyadarsini
2020-10-22 13:47 ` Sumera Priyadarsini [this message]
2020-10-22 13:47 ` [PATCH 4/5] " Sumera Priyadarsini
2020-10-22 13:54 ` [Outreachy kernel] " Greg KH
2020-10-22 13:49 ` [PATCH 5/5] " Sumera Priyadarsini
2020-10-22 14:13 ` [Outreachy kernel][PATCH 0/5] drm/amdgpu: Replace snprintf() with sysfs_emit Daniel Vetter
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=864a0c5d7bc85d9eeaf1ca7b3db38b58e042471b.1603371258.git.sylphrenadin@gmail.com \
--to=sylphrenadin@gmail.com \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.or \
--cc=linux-media@vger.kernel.org \
--cc=melissa.srw@gmail.com \
--cc=outreachy-kernel@googlegroups.com \
/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;
as well as URLs for NNTP newsgroup(s).