From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D943AC55191 for ; Thu, 23 Apr 2020 03:31:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93882075A for ; Thu, 23 Apr 2020 03:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbgDWDbw (ORCPT ); Wed, 22 Apr 2020 23:31:52 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:37980 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726643AbgDWDbw (ORCPT ); Wed, 22 Apr 2020 23:31:52 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2CC5AF169594084096EF; Thu, 23 Apr 2020 11:31:49 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Thu, 23 Apr 2020 11:31:47 +0800 From: Mao Wenan To: , , , , , , , CC: , , , , Subject: [PATCH bpf-next v2 1/2] bpf: Change error code when ops is NULL Date: Thu, 23 Apr 2020 11:33:13 +0800 Message-ID: <20200423033314.49205-2-maowenan@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200423033314.49205-1-maowenan@huawei.com> References: <20200422093329.GI2659@kadam> <20200423033314.49205-1-maowenan@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is one error printed when use BPF_MAP_TYPE_SOCKMAP to create map: libbpf: failed to create map (name: 'sock_map'): Invalid argument(-22) This is because CONFIG_BPF_STREAM_PARSER is not set, and bpf_map_types[type] return invalid ops. It is not clear to show the cause of config missing with return code -EINVAL, so add pr_warn() and change error code to describe the reason. Signed-off-by: Mao Wenan --- kernel/bpf/syscall.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index d85f37239540..7686778457c7 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -112,9 +112,10 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) return ERR_PTR(-EINVAL); type = array_index_nospec(type, ARRAY_SIZE(bpf_map_types)); ops = bpf_map_types[type]; - if (!ops) - return ERR_PTR(-EINVAL); - + if (!ops) { + pr_warn("map type %d not supported or kernel config not opened\n", type); + return ERR_PTR(-EOPNOTSUPP); + } if (ops->map_alloc_check) { err = ops->map_alloc_check(attr); if (err) -- 2.20.1