Skip to content

Commit

Permalink
scst_disk: Fix use of uninitialized variable
Browse files Browse the repository at this point in the history
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: 7ba5b11 ("scst_disk: Add cluster SCSI sync state mode
support to dev_disk")
  • Loading branch information
lnocturno committed Jan 20, 2023
1 parent 7ba5b11 commit ae6c0bf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scst/src/dev_handlers/scst_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ae6c0bf

Please sign in to comment.