From patchwork Tue Aug 20 02:34:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 13769267 X-Patchwork-Delegate: bpf@iogearbox.net Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 68B201E4AB for ; Tue, 20 Aug 2024 02:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724121340; cv=none; b=MxC5yz7SNn9pm0P8TaV/lsMqoNbEMfH87tMiVLIJjjIjC4uRai2IAukYIWjPAc2UWr2oKdpUZ5qKoODCTVI3HKsMPOsK5v9mibPH+Xyk4IHcjfCjQj4Y07JrpeNMlSI00xTFbyut99Kptv2CqZUo6yPRgj47/uZcSega6BxkG+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724121340; c=relaxed/simple; bh=3FA+zhY3J2aurdG8ymeG/8o1uucMCSTevRTGmf/g0j8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uADkD8EPf1zFZBFh5X81RcRorUryJGGokTwXw94suK61PXr5BM8V2T+bF55mq+LUJCdZPjoPkFlJZwHsJFAf+AwWkODiBnf7V+x/xgapGs7C3Xy0buhq00FbdpmrmWKzCc8o96NGC16l/fAF7NuhVgUp+1mhCtT8a16uGe6AQw8= 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=radG637o; arc=none smtp.client-ip=95.215.58.182 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="radG637o" 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=1724121335; 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=d3N4eAp1zNkGpAB397euBnf4ls1mgFuOdl80fVhDMCk=; b=radG637oDVCDIvt3PWEEmr6brYVRi2wD7sDKaadZcZdaos9DGm29UQRQOhBaxZkyFei8yt XpYgTZHIhFpJ7UACs2v2Y20E/WIP2Ig/C1lOjtoPH18y/PXjdgbjXXxrsNGD68CKUUvdKe d5hlpai8hxSjpwwhWaF7ehmziJI1QYc= From: Hao Ge To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hao Ge , Dan Carpenter Subject: [PATCH] selftests/bpf: Fix incorrect parameters in NULL pointer checking Date: Tue, 20 Aug 2024 10:34:47 +0800 Message-Id: <20240820023447.29002-1-hao.ge@linux.dev> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Patchwork-Delegate: bpf@iogearbox.net From: Hao Ge Smatch reported the following warning: ./tools/testing/selftests/bpf/testing_helpers.c:455 get_xlated_program() warn: variable dereferenced before check 'buf' (see line 454) It seems correct,so let's modify it based on it's suggestion. Actually,commit b23ed4d74c4d ("selftests/bpf: Fix invalid pointer check in get_xlated_program()") fixed an issue in the test_verifier.c once,but it was reverted this time. Let's solve this issue with the minimal changes possible. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/1eb3732f-605a-479d-ba64-cd14250cbf91@stanley.mountain/ Fixes: b4b7a4099b8c ("selftests/bpf: Factor out get_xlated_program() helper") Signed-off-by: Hao Ge Acked-by: Yonghong Song --- tools/testing/selftests/bpf/testing_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index d5379a0e6da8..34dfea295c8e 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -451,7 +451,7 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt) *cnt = xlated_prog_len / buf_element_size; *buf = calloc(*cnt, buf_element_size); - if (!buf) { + if (!*buf) { perror("can't allocate xlated program buffer"); return -ENOMEM; }