Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bba1a99 authored by Yury Norov [NVIDIA]'s avatar Yury Norov [NVIDIA] Committed by Greg Kroah-Hartman
Browse files

RDMA: hfi1: fix possible divide-by-zero in find_hw_thread_mask()



[ Upstream commit 59f7d2138591ef8f0e4e4ab5f1ab674e8181ad3a ]

The function divides number of online CPUs by num_core_siblings, and
later checks the divider by zero. This implies a possibility to get
and divide-by-zero runtime error. Fix it by moving the check prior to
division. This also helps to save one indentation level.

Signed-off-by: default avatarYury Norov [NVIDIA] <yury.norov@gmail.com>
Link: https://patch.msgid.link/20250604193947.11834-3-yury.norov@gmail.com


Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent ab18e48a
Loading
Loading
Loading
Loading
+24 −20
Original line number Diff line number Diff line
@@ -1009,12 +1009,17 @@ static void find_hw_thread_mask(uint hw_thread_no, cpumask_var_t hw_thread_mask,
				struct hfi1_affinity_node_list *affinity)
{
	int possible, curr_cpu, i;
	uint num_cores_per_socket = node_affinity.num_online_cpus /
	uint num_cores_per_socket;

	cpumask_copy(hw_thread_mask, &affinity->proc.mask);

	if (affinity->num_core_siblings == 0)
		return;

	num_cores_per_socket = node_affinity.num_online_cpus /
					affinity->num_core_siblings /
						node_affinity.num_online_nodes;

	cpumask_copy(hw_thread_mask, &affinity->proc.mask);
	if (affinity->num_core_siblings > 0) {
	/* Removing other siblings not needed for now */
	possible = cpumask_weight(hw_thread_mask);
	curr_cpu = cpumask_first(hw_thread_mask);
@@ -1034,7 +1039,6 @@ static void find_hw_thread_mask(uint hw_thread_no, cpumask_var_t hw_thread_mask,
			   node_affinity.num_online_nodes *
			   hw_thread_no);
}
}

int hfi1_get_proc_affinity(int node)
{