From patchwork Thu Feb 17 18:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yucong Sun X-Patchwork-Id: 12750521 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACFFBC433EF for ; Thu, 17 Feb 2022 18:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243953AbiBQSCe (ORCPT ); Thu, 17 Feb 2022 13:02:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240904AbiBQSCd (ORCPT ); Thu, 17 Feb 2022 13:02:33 -0500 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704F4AC for ; Thu, 17 Feb 2022 10:02:18 -0800 (PST) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21HGBl8F014678 for ; Thu, 17 Feb 2022 10:02:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Y7tWtgbUaW7J7+rA0eFz4vEDWQPfdO0pLfSsD6UM/2c=; b=qYZaFEMdGQXkXtEPhcogWhIS1/wsX+4YLr0YBNS8/c2Ith78SHNBDV5/c3pZDvzYEHVS N+Z1lmH2/mWWBYF8e7yhc70+z5DsrdIADt4xZTQ05LkGTH71s4j9nwvMNVqDkp388ZR9 DUGOMwTmx+MHiXklZMce68vuWr41bTHm0Uk= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3e9dfbd1qw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 17 Feb 2022 10:02:18 -0800 Received: from twshared33837.14.frc2.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 17 Feb 2022 10:02:16 -0800 Received: by devvm4573.vll0.facebook.com (Postfix, from userid 200310) id 2A3D53A4A60A; Thu, 17 Feb 2022 10:02:12 -0800 (PST) From: Yucong Sun To: CC: , , Subject: [PATCH bpf-next] selftests/bpf: fix crash in core_reloc when bpftool btfgen fails Date: Thu, 17 Feb 2022 10:02:10 -0800 Message-ID: <20220217180210.2981502-1-fallentree@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: rI2cfgL7P1yStzA5ysNf9_2jShmrM-BR X-Proofpoint-GUID: rI2cfgL7P1yStzA5ysNf9_2jShmrM-BR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-17_06,2022-02-17_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 clxscore=1015 suspectscore=0 phishscore=0 spamscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=744 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170083 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Initialize obj to null and skip closing if null. Signed-off-by: Yucong Sun --- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c index baf53c23c08d..7211243a22c3 100644 --- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c @@ -861,7 +861,7 @@ static void run_core_reloc_tests(bool use_btfgen) struct bpf_link *link = NULL; struct bpf_map *data_map; struct bpf_program *prog; - struct bpf_object *obj; + struct bpf_object *obj = NULL; uint64_t my_pid_tgid; struct data *data; void *mmap_data = NULL; @@ -992,7 +992,8 @@ static void run_core_reloc_tests(bool use_btfgen) remove(btf_file); bpf_link__destroy(link); link = NULL; - bpf_object__close(obj); + if (obj) + bpf_object__close(obj); } }