From ae6c0bf914b8c6749317e1298d505602856e20e5 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Fri, 20 Jan 2023 10:43:37 +0300 Subject: [PATCH] scst_disk: Fix use of uninitialized variable This patch fixes the following Coverity complaint: CID 307352 (#1 of 1): Uninitialized pointer read (UNINIT) uninit_use_in_call: Using uninitialized value arg when calling kfree. Fixes: 7ba5b11f0a30 ("scst_disk: Add cluster SCSI sync state mode support to dev_disk") --- scst/src/dev_handlers/scst_disk.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index 606557587..9150dd5e2 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -633,34 +633,42 @@ static ssize_t disk_sysfs_cluster_mode_store(struct kobject *kobj, struct scst_device *dev = container_of(kobj, struct scst_device, dev_kobj); struct scst_sysfs_work_item *work; - char *arg; + char *arg = NULL; int res; TRACE_ENTRY(); - res = -ENOMEM; /* Must have a serial number to enable cluster_mode */ - if (count && !dev->dh_priv) + if (count && !dev->dh_priv) { + res = -ENOENT; goto out; + } + arg = kasprintf(GFP_KERNEL, "%.*s", (int)count, buf); - if (!arg) + if (!arg) { + res = -ENOMEM; goto out; + } res = scst_alloc_sysfs_work(disk_sysfs_process_cluster_mode_store, false, &work); if (res) goto out; + work->dev = dev; swap(work->buf, arg); kobject_get(&dev->dev_kobj); + res = scst_sysfs_queue_wait_work(work); if (res) goto out; + res = count; out: kfree(arg); TRACE_EXIT_RES(res); + return res; }