]> www.infradead.org Git - users/hch/configfs.git/commitdiff
drm/xe: prefer snprintf over sprintf
authorBommu Krishnaiah <krishnaiah.bommu@intel.com>
Sat, 9 Dec 2023 23:59:48 +0000 (05:29 +0530)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 4 Apr 2024 18:54:51 +0000 (14:54 -0400)
since the sprintf() function lacks built-in protection against buffer
overflows using the snprintf() function.

v2: Removed hard coded values and used sizeof()

Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231209235949.54524-2-krishnaiah.bommu@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_debugfs.c
drivers/gpu/drm/xe/xe_exec_queue.c
drivers/gpu/drm/xe/xe_gt_debugfs.c
drivers/gpu/drm/xe/xe_gt_idle.c
drivers/gpu/drm/xe/xe_hw_fence.c

index 8abdf3c17e1d35fc0fbe41d8fcc436583c620d96..86150cafe0ffe9b971a287fc6e4d9963b346629d 100644 (file)
@@ -129,7 +129,7 @@ void xe_debugfs_register(struct xe_device *xe)
                if (man) {
                        char name[16];
 
-                       sprintf(name, "vram%d_mm", mem_type - XE_PL_VRAM0);
+                       snprintf(name, sizeof(name), "vram%d_mm", mem_type - XE_PL_VRAM0);
                        ttm_resource_manager_create_debugfs(man, root, name);
                }
        }
index 730eb7d2a63948a8ebe846b33e78d0cf42e59801..71bd52dfebcfaf54564af3db926d36ffabb745b0 100644 (file)
@@ -225,22 +225,22 @@ void xe_exec_queue_assign_name(struct xe_exec_queue *q, u32 instance)
 {
        switch (q->class) {
        case XE_ENGINE_CLASS_RENDER:
-               sprintf(q->name, "rcs%d", instance);
+               snprintf(q->name, sizeof(q->name), "rcs%d", instance);
                break;
        case XE_ENGINE_CLASS_VIDEO_DECODE:
-               sprintf(q->name, "vcs%d", instance);
+               snprintf(q->name, sizeof(q->name), "vcs%d", instance);
                break;
        case XE_ENGINE_CLASS_VIDEO_ENHANCE:
-               sprintf(q->name, "vecs%d", instance);
+               snprintf(q->name, sizeof(q->name), "vecs%d", instance);
                break;
        case XE_ENGINE_CLASS_COPY:
-               sprintf(q->name, "bcs%d", instance);
+               snprintf(q->name, sizeof(q->name), "bcs%d", instance);
                break;
        case XE_ENGINE_CLASS_COMPUTE:
-               sprintf(q->name, "ccs%d", instance);
+               snprintf(q->name, sizeof(q->name), "ccs%d", instance);
                break;
        case XE_ENGINE_CLASS_OTHER:
-               sprintf(q->name, "gsccs%d", instance);
+               snprintf(q->name, sizeof(q->name), "gsccs%d", instance);
                break;
        default:
                XE_WARN_ON(q->class);
index ee4285d42a18de7671c647305e44b3cee5f99f55..ff7f4cf52fa92a5ef77ac8bdbd613bb0bde991f2 100644 (file)
@@ -269,7 +269,7 @@ void xe_gt_debugfs_register(struct xe_gt *gt)
 
        xe_gt_assert(gt, minor->debugfs_root);
 
-       sprintf(name, "gt%d", gt->info.id);
+       snprintf(name, sizeof(name), "gt%d", gt->info.id);
        root = debugfs_create_dir(name, minor->debugfs_root);
        if (IS_ERR(root)) {
                drm_warn(&xe->drm, "Create GT directory failed");
index 2984680de3f934bf27719b54cdb4e4b9f56755a6..bc1426f8d731c37e64203c3c6ac59ff174523096 100644 (file)
@@ -166,10 +166,10 @@ void xe_gt_idle_sysfs_init(struct xe_gt_idle *gtidle)
        }
 
        if (xe_gt_is_media_type(gt)) {
-               sprintf(gtidle->name, "gt%d-mc", gt->info.id);
+               snprintf(gtidle->name, sizeof(gtidle->name), "gt%d-mc", gt->info.id);
                gtidle->idle_residency = xe_guc_pc_mc6_residency;
        } else {
-               sprintf(gtidle->name, "gt%d-rc", gt->info.id);
+               snprintf(gtidle->name, sizeof(gtidle->name), "gt%d-rc", gt->info.id);
                gtidle->idle_residency = xe_guc_pc_rc6_residency;
        }
 
index a5de3e7b0bd6ab134557fdfb52a406d4bf199016..f872ef10312725e85c94411bd9b3e2d5d68b2284 100644 (file)
@@ -130,7 +130,7 @@ void xe_hw_fence_ctx_init(struct xe_hw_fence_ctx *ctx, struct xe_gt *gt,
        ctx->irq = irq;
        ctx->dma_fence_ctx = dma_fence_context_alloc(1);
        ctx->next_seqno = XE_FENCE_INITIAL_SEQNO;
-       sprintf(ctx->name, "%s", name);
+       snprintf(ctx->name, sizeof(ctx->name), "%s", name);
 }
 
 void xe_hw_fence_ctx_finish(struct xe_hw_fence_ctx *ctx)