scsi: target: Fix incorrect use of cpumask_t

In commit d72d827f2f26, I used 'cpumask_t' incorrectly:

    void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
    {
            int ord, cpu;
            cpumask_t conn_allowed_cpumask;
            ......
    }

    static ssize_t lio_target_wwn_cpus_allowed_list_store(
                   struct config_item *item, const char *page, size_t count)
    {
            int ret;
            char *orig;
            cpumask_t new_allowed_cpumask;
            ......
    }

The correct pattern should be as follows:

    cpumask_var_t mask;

    if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
            return -ENOMEM;
    ... use 'mask' here ...
    free_cpumask_var(mask);

Link: https://lore.kernel.org/r/20220516054721.1548-1-mingzhe.zou@easystack.cn
Fixes: d72d827f2f26 ("scsi: target: Add iscsi/cpus_allowed_list in configfs")
Reported-by: Test Bot <zgrieee@gmail.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Mingzhe Zou 2022-05-16 13:47:21 +08:00 committed by Martin K. Petersen
parent 7752662071
commit 525f447f88
2 changed files with 36 additions and 20 deletions

View File

@ -3596,10 +3596,7 @@ static int iscsit_send_reject(
void iscsit_thread_get_cpumask(struct iscsi_conn *conn) void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
{ {
int ord, cpu; int ord, cpu;
cpumask_t conn_allowed_cpumask; cpumask_var_t conn_allowed_cpumask;
cpumask_and(&conn_allowed_cpumask, iscsit_global->allowed_cpumask,
cpu_online_mask);
/* /*
* bitmap_id is assigned from iscsit_global->ts_bitmap from * bitmap_id is assigned from iscsit_global->ts_bitmap from
@ -3609,13 +3606,28 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
* iSCSI connection's RX/TX threads will be scheduled to * iSCSI connection's RX/TX threads will be scheduled to
* execute upon. * execute upon.
*/ */
cpumask_clear(conn->conn_cpumask); if (!zalloc_cpumask_var(&conn_allowed_cpumask, GFP_KERNEL)) {
ord = conn->bitmap_id % cpumask_weight(&conn_allowed_cpumask); ord = conn->bitmap_id % cpumask_weight(cpu_online_mask);
for_each_cpu(cpu, &conn_allowed_cpumask) { for_each_online_cpu(cpu) {
if (ord-- == 0) { if (ord-- == 0) {
cpumask_set_cpu(cpu, conn->conn_cpumask); cpumask_set_cpu(cpu, conn->conn_cpumask);
return; return;
}
} }
} else {
cpumask_and(conn_allowed_cpumask, iscsit_global->allowed_cpumask,
cpu_online_mask);
cpumask_clear(conn->conn_cpumask);
ord = conn->bitmap_id % cpumask_weight(conn_allowed_cpumask);
for_each_cpu(cpu, conn_allowed_cpumask) {
if (ord-- == 0) {
cpumask_set_cpu(cpu, conn->conn_cpumask);
free_cpumask_var(conn_allowed_cpumask);
return;
}
}
free_cpumask_var(conn_allowed_cpumask);
} }
/* /*
* This should never be reached.. * This should never be reached..

View File

@ -1137,23 +1137,27 @@ static ssize_t lio_target_wwn_cpus_allowed_list_show(
static ssize_t lio_target_wwn_cpus_allowed_list_store( static ssize_t lio_target_wwn_cpus_allowed_list_store(
struct config_item *item, const char *page, size_t count) struct config_item *item, const char *page, size_t count)
{ {
int ret; int ret = -ENOMEM;
char *orig; char *orig;
cpumask_t new_allowed_cpumask; cpumask_var_t new_allowed_cpumask;
if (!zalloc_cpumask_var(&new_allowed_cpumask, GFP_KERNEL))
goto out;
orig = kstrdup(page, GFP_KERNEL); orig = kstrdup(page, GFP_KERNEL);
if (!orig) if (!orig)
return -ENOMEM; goto out_free_cpumask;
cpumask_clear(&new_allowed_cpumask); ret = cpulist_parse(orig, new_allowed_cpumask);
ret = cpulist_parse(orig, &new_allowed_cpumask); if (!ret)
cpumask_copy(iscsit_global->allowed_cpumask,
new_allowed_cpumask);
kfree(orig); kfree(orig);
if (ret != 0) out_free_cpumask:
return ret; free_cpumask_var(new_allowed_cpumask);
out:
cpumask_copy(iscsit_global->allowed_cpumask, &new_allowed_cpumask); return ret ? ret : count;
return count;
} }
CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list); CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list);