From nobody Thu Oct 2 22:47:39 2025 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CE1623ED75 for ; Tue, 9 Sep 2025 12:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757422070; cv=none; b=ARGlis5DS02jSj/jiP/V2NxrmwSl1tZgzsG6ho16+whsnlAKQAtuit0dz6WXZfd2cGYk8zwPoKaQAxC/a81KWqmf77RvIt8h0r3ma8tkvHOFmZ2Ve27QS2ho1tq9hU/YbabQSWdI1H1hlnSmDx5g8umzmBkP+eQvdajEvn3+D8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757422070; c=relaxed/simple; bh=C/o3+QkdyajagqcWpvpUtf/kbpe5Cr0u7uLUZDwXD6w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hfSWOtA6Q9HOMX42LStI5/CDmhDPBHJE0kgVqaElpUibtqONbONtZdh6qqFqw8xDmR4WXfJc3niKm+bc9rDsuwcLHGGJweFc8z+TJHq4hLqSwCzd2ratKOwFOZSLC6QuLNKdCBNMtriFQ1TQq+kYZjLBf3/s1rV8/9v0l8pgwJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KG/sKjTM; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KG/sKjTM" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1757422056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Civ3v7++W+FLuwnLZNUaxx6xIkTNDQTvDlA6SdwcjAQ=; b=KG/sKjTMufw82dzqQfGVZtHmIKPFQHjuko4gDGm2VJ8PiUkf/cdXrcsWVNTTRI0/e158e7 vA1IZjtT5F2Ib8aSgAXpjckrO5n7N9Cp53SXyOkPTcvGNW3IavPzg4XB68O7GjhVMY0lAs jNytsDhuBxLvL89RZdlSy706tA7kG78= From: Jiayuan Chen To: jiayuan.chen@linux.dev Cc: Dan Carpenter , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Jiapeng Chong , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2] selftests/bpf: Fix incorrect array size calculation Date: Tue, 9 Sep 2025 20:47:04 +0800 Message-ID: <20250909124721.191555-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The loop in bench_sockmap_prog_destroy() has two issues: 1. Using 'sizeof(ctx.fds)' as the loop bound results in the number of bytes, not the number of file descriptors, causing the loop to iterate far more times than intended. 2. The condition 'ctx.fds[0] > 0' incorrectly checks only the first fd for all iterations, potentially leaving file descriptors unclosed. Change it to 'ctx.fds[i] > 0' to check each fd properly. These fixes ensure correct cleanup of all file descriptors when the benchmark exits. Signed-off-by: Jiayuan Chen Reported-by: Dan Carpenter Closes: https://lore.kernel.org/bpf/aLqfWuRR9R_KTe5e@stanley.mountain/ --- tools/testing/selftests/bpf/benchs/bench_sockmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/benchs/bench_sockmap.c b/tools/tes= ting/selftests/bpf/benchs/bench_sockmap.c index 8ebf563a67a2..cfc072aa7fff 100644 --- a/tools/testing/selftests/bpf/benchs/bench_sockmap.c +++ b/tools/testing/selftests/bpf/benchs/bench_sockmap.c @@ -10,6 +10,7 @@ #include #include "bench.h" #include "bench_sockmap_prog.skel.h" +#include "bpf_util.h" =20 #define FILE_SIZE (128 * 1024) #define DATA_REPEAT_SIZE 10 @@ -124,8 +125,8 @@ static void bench_sockmap_prog_destroy(void) { int i; =20 - for (i =3D 0; i < sizeof(ctx.fds); i++) { - if (ctx.fds[0] > 0) + for (i =3D 0; i < ARRAY_SIZE(ctx.fds); i++) { + if (ctx.fds[i] > 0) close(ctx.fds[i]); } =20 --=20 2.43.0