Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp856700pxj; Fri, 28 May 2021 18:28:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMm4PHBxoB8/C8cZ2idEB+8yeYehZuBwRFUOvB2libUY+n8IHQd32fXHYr24zwfZnstr2F X-Received: by 2002:a6b:dc13:: with SMTP id s19mr9282752ioc.14.1622251724607; Fri, 28 May 2021 18:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622251724; cv=none; d=google.com; s=arc-20160816; b=pA2Ax8tLMMPKkcBu0Hwc/bnFFiBG9dcaXh/ScL+CMCdMNF5mmkpNaf3jM0LQLm7u2U jcxXeHs2ilBYGk4AMfFrwxHgl+TJEnAKheLwbzwjXsNwzcf6rJT1Qq+uiGaQoSXhVYM/ dkLldTEJ4ueNi3tefz/iUP0O2/DTrbAVpzA3iinvpJPRbTEZZiJLuxDWrViM9H8vryM5 u1guxSBr+fcukS5beOB1jQkhQJNn8j3FUK52qhbQDF2HAA6KOpsUtDFnvh8NeCLfurBg kNnkxVHV6eh7Pk+vfA1kN0Or2X5UXz1mLmFyMN1mpuRaOKkRVsf+cGgGaJHUjDqkFTrY kx4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=WoAN4g3jk5Eo5mmWSIBKK/Zcbj8PE3Upd8YzI7/hkcs=; b=QpqQjx8MgSync8I842XZxevhVjbER7XvjdTom0Dbg/QJEP8ihpx7Os1LNBA9U6Lt3i +9QtcQ/KUJA9A6ahEk6Y4Vla+h9uctBAJ38u0Qnr9y+lc2Wu5fx31uGrTi+F8fU5XwP/ 250XgVnMr7QQIayPIGZVQx0nitDhkGplDiFCbykm3CMmt8FCReAm8tOqREzb8LNXRDru tv0nJvNviFlk0+UCeGDd0lqribY/96PvQ469MS3xGfXHLtEDbgmby0Ifur59FBDFGTns 9OfEH0XsTY4yU7Ed2Dov5KUweWwo4lB2i1H1x4Mfvcw79EtxBUSkfSDtKxvRREsv/t7t ktuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si8849634ilm.45.2021.05.28.18.28.29; Fri, 28 May 2021 18:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229741AbhE2B1J (ORCPT + 99 others); Fri, 28 May 2021 21:27:09 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:5135 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbhE2B1H (ORCPT ); Fri, 28 May 2021 21:27:07 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FsP1j0W6jzYn66; Sat, 29 May 2021 09:22:49 +0800 (CST) Received: from dggema762-chm.china.huawei.com (10.1.198.204) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sat, 29 May 2021 09:25:30 +0800 Received: from [10.174.179.129] (10.174.179.129) by dggema762-chm.china.huawei.com (10.1.198.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 29 May 2021 09:25:29 +0800 Subject: Re: [PATCH] selftests/bpf: Fix return value check in attach_bpf() To: Daniel Borkmann , , , CC: , , , , References: <20210528090758.1108464-1-yukuai3@huawei.com> From: "yukuai (C)" Message-ID: Date: Sat, 29 May 2021 09:25:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.129] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggema762-chm.china.huawei.com (10.1.198.204) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/05/29 4:46, Daniel Borkmann wrote: > On 5/28/21 11:07 AM, Yu Kuai wrote: >> use libbpf_get_error() to check the return value of >> bpf_program__attach(). >> >> Reported-by: Hulk Robot >> Signed-off-by: Yu Kuai >> --- >>   tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +- >>   1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/testing/selftests/bpf/benchs/bench_rename.c >> b/tools/testing/selftests/bpf/benchs/bench_rename.c >> index c7ec114eca56..b7d4a1d74fca 100644 >> --- a/tools/testing/selftests/bpf/benchs/bench_rename.c >> +++ b/tools/testing/selftests/bpf/benchs/bench_rename.c >> @@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog) >>       struct bpf_link *link; >>       link = bpf_program__attach(prog); >> -    if (!link) { >> +    if (libbpf_get_error(link)) { >>           fprintf(stderr, "failed to attach program!\n"); >>           exit(1); >>       } > > Could you explain the rationale of this patch? bad2e478af3b > ("selftests/bpf: Turn > on libbpf 1.0 mode and fix all IS_ERR checks") explains: 'Fix all the > explicit > IS_ERR checks that now will be broken because libbpf returns NULL on > error (and > sets errno).' So the !link check looks totally reasonable to me. > Converting to > libbpf_get_error() is not wrong in itself, but given you don't make any > use of > the err code, there is also no point in this diff here. Hi, I was thinking that bpf_program__attach() can return error code theoretically(for example -ESRCH), and such case need to be handled. Thanks, Yu Kuai > > Thanks, > Daniel > . >