Skip to content

Commit 525f447

Browse files
zoumingzhemartinkpetersen
authored andcommitted
scsi: target: Fix incorrect use of cpumask_t
In commit d72d827, 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/[email protected] Fixes: d72d827 ("scsi: target: Add iscsi/cpus_allowed_list in configfs") Reported-by: Test Bot <[email protected]> Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Mingzhe Zou <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 7752662 commit 525f447

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

drivers/target/iscsi/iscsi_target.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,10 +3596,7 @@ static int iscsit_send_reject(
35963596
void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
35973597
{
35983598
int ord, cpu;
3599-
cpumask_t conn_allowed_cpumask;
3600-
3601-
cpumask_and(&conn_allowed_cpumask, iscsit_global->allowed_cpumask,
3602-
cpu_online_mask);
3599+
cpumask_var_t conn_allowed_cpumask;
36033600

36043601
/*
36053602
* bitmap_id is assigned from iscsit_global->ts_bitmap from
@@ -3609,13 +3606,28 @@ void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
36093606
* iSCSI connection's RX/TX threads will be scheduled to
36103607
* execute upon.
36113608
*/
3612-
cpumask_clear(conn->conn_cpumask);
3613-
ord = conn->bitmap_id % cpumask_weight(&conn_allowed_cpumask);
3614-
for_each_cpu(cpu, &conn_allowed_cpumask) {
3615-
if (ord-- == 0) {
3616-
cpumask_set_cpu(cpu, conn->conn_cpumask);
3617-
return;
3609+
if (!zalloc_cpumask_var(&conn_allowed_cpumask, GFP_KERNEL)) {
3610+
ord = conn->bitmap_id % cpumask_weight(cpu_online_mask);
3611+
for_each_online_cpu(cpu) {
3612+
if (ord-- == 0) {
3613+
cpumask_set_cpu(cpu, conn->conn_cpumask);
3614+
return;
3615+
}
3616+
}
3617+
} else {
3618+
cpumask_and(conn_allowed_cpumask, iscsit_global->allowed_cpumask,
3619+
cpu_online_mask);
3620+
3621+
cpumask_clear(conn->conn_cpumask);
3622+
ord = conn->bitmap_id % cpumask_weight(conn_allowed_cpumask);
3623+
for_each_cpu(cpu, conn_allowed_cpumask) {
3624+
if (ord-- == 0) {
3625+
cpumask_set_cpu(cpu, conn->conn_cpumask);
3626+
free_cpumask_var(conn_allowed_cpumask);
3627+
return;
3628+
}
36183629
}
3630+
free_cpumask_var(conn_allowed_cpumask);
36193631
}
36203632
/*
36213633
* This should never be reached..

drivers/target/iscsi/iscsi_target_configfs.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,23 +1137,27 @@ static ssize_t lio_target_wwn_cpus_allowed_list_show(
11371137
static ssize_t lio_target_wwn_cpus_allowed_list_store(
11381138
struct config_item *item, const char *page, size_t count)
11391139
{
1140-
int ret;
1140+
int ret = -ENOMEM;
11411141
char *orig;
1142-
cpumask_t new_allowed_cpumask;
1142+
cpumask_var_t new_allowed_cpumask;
1143+
1144+
if (!zalloc_cpumask_var(&new_allowed_cpumask, GFP_KERNEL))
1145+
goto out;
11431146

11441147
orig = kstrdup(page, GFP_KERNEL);
11451148
if (!orig)
1146-
return -ENOMEM;
1149+
goto out_free_cpumask;
11471150

1148-
cpumask_clear(&new_allowed_cpumask);
1149-
ret = cpulist_parse(orig, &new_allowed_cpumask);
1151+
ret = cpulist_parse(orig, new_allowed_cpumask);
1152+
if (!ret)
1153+
cpumask_copy(iscsit_global->allowed_cpumask,
1154+
new_allowed_cpumask);
11501155

11511156
kfree(orig);
1152-
if (ret != 0)
1153-
return ret;
1154-
1155-
cpumask_copy(iscsit_global->allowed_cpumask, &new_allowed_cpumask);
1156-
return count;
1157+
out_free_cpumask:
1158+
free_cpumask_var(new_allowed_cpumask);
1159+
out:
1160+
return ret ? ret : count;
11571161
}
11581162

11591163
CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list);

0 commit comments

Comments
 (0)