From patchwork Wed Sep 21 16:59:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12984029 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D12D3C6FA8B for ; Wed, 21 Sep 2022 17:00:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C4396B007E; Wed, 21 Sep 2022 13:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6746A940007; Wed, 21 Sep 2022 13:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 514516B0081; Wed, 21 Sep 2022 13:00:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 401456B007E for ; Wed, 21 Sep 2022 13:00:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 919C7121221 for ; Wed, 21 Sep 2022 17:00:24 +0000 (UTC) X-FDA: 79936705968.19.9A59ED4 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf02.hostedemail.com (Postfix) with ESMTP id 24F0080024 for ; Wed, 21 Sep 2022 17:00:23 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id o99-20020a17090a0a6c00b002039c4fce53so9478220pjo.2 for ; Wed, 21 Sep 2022 10:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=gqCnXF6pL1DkeQyk82Z43CJDm8euemRLx+k6VOog8Uc=; b=UGRZwVaZmlJMU25ZsQipxPfiqXs+wsllhJ+tOSSDcAUjFGAX7DQpWyoztud6+XklKC nu8mtVQhAabPURghaZx7jg8BVskiJM/UYMNF3dkH8+cvzz/onhdgh3QlOUj/uLvR9tcc 2H31ALd6zzINn3zaoG/SK9MPdeYtU7JXkF7VliyTYP/e66MQ/ut7KGcJQZeoJUkXcYcH js+Cz02F2TZtIl25SDE8O4d9j6s9E8shiwIAPCn/yl46O+Envod6GqXKimJU0wpKiFxq HbAdN9rj34msRsmvaFGVBspvNxRmwm3ZAnxbroDnhMw2M3KrHWP120R2b3iMAiyReA34 93Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=gqCnXF6pL1DkeQyk82Z43CJDm8euemRLx+k6VOog8Uc=; b=ch7qyVBU4XXMbjvTws7CmALW7MwPupRybgan+BjA1zeKsIsOYBVeMHa0IjZVzWiEWM clrU77DH9VaDWL8yZFonml/Hz5svK6USvaj6CfEoIjd+rr88FFpLTaNNqRO9CkxxIJTd xh0j7Uo73IHnbuYnAumjHjeoj9o2lVoa52CLdepyN7+VkH7FG9fzy359ip88fXZM+jti Ll6pKV2De3MSwT3WoFShEK88FM3KcNdCwyGLA7WIEp9U6murOFvxJXxtaFkYancjOV+f YJzNmuZfteYhjsLrrTrqcJS5eFo/TMNAwKmyaRXRhndVt9bmgUywAMs/WCP/rKRwqiwD UGDg== X-Gm-Message-State: ACrzQf3oONjLOv9TQX5OolSlBaCv0DjL2VlzH12RXMH7zFjv/66fjA+G xRlfsLZttU+Je6h3tEND9Co= X-Google-Smtp-Source: AMsMyM6HRw/Vr5zpNcVZxiuAc86cjAkLvMMsOYZ0frkrsI/RI9RosxyjVSCqGe6nLjJt+N6Ie7/jvQ== X-Received: by 2002:a17:902:d40c:b0:178:4439:69f9 with SMTP id b12-20020a170902d40c00b00178443969f9mr5780706ple.118.1663779623293; Wed, 21 Sep 2022 10:00:23 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:488e:5400:4ff:fe25:7db8]) by smtp.gmail.com with ESMTPSA id mp4-20020a17090b190400b002006f8e7688sm2102495pjb.32.2022.09.21.10.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 10:00:22 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org, tj@kernel.org, lizefan.x@bytedance.com Cc: cgroups@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [RFC PATCH bpf-next 07/10] bpf: Use bpf_map_kzalloc in arraymap Date: Wed, 21 Sep 2022 16:59:59 +0000 Message-Id: <20220921170002.29557-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220921170002.29557-1-laoar.shao@gmail.com> References: <20220921170002.29557-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663779624; a=rsa-sha256; cv=none; b=0v3Jo9jXRQi+XoeGXadhN/fQ8KYvNgt0YVWOHOK134QnLliqosMIKg3KATImShb3fO6Ybc nOMGW9Bb0kS1OVaT+HyILJphXnQiegdA6p2Lu4c+Z+rNqHY6cHpb2wnOsEv3fO/7dSePRI c3UhLNRAvxTxvPwj4h3dQR6+oZTE58U= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UGRZwVaZ; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663779624; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gqCnXF6pL1DkeQyk82Z43CJDm8euemRLx+k6VOog8Uc=; b=vQF4lmqKhzwt8vlEAT+mSLSC2LhatoEVCADUqKXniKyX1iJPdc6bHd3vmlDMTfQaNeVuu3 XKD61SFBfxXXfD4VlrHkPn8Wz5JU3bRBiL5W7I+Gh/+lpKcMtdpJRzP47/82OYbevwI8UR PAujpcmcOtouKveoE0HWcpOsTHRexW4= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 24F0080024 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UGRZwVaZ; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: cdxszjqdxgbfmxbfgfrkjwjpf6uj6yd3 X-HE-Tag: 1663779623-578066 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allocates memory after map creation, then we can use the generic helper bpf_map_kzalloc() instead of the open-coded kzalloc(). Signed-off-by: Yafang Shao --- kernel/bpf/arraymap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index dd79d0d..7f1766c 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -1111,20 +1111,20 @@ static struct bpf_map *prog_array_map_alloc(union bpf_attr *attr) struct bpf_array_aux *aux; struct bpf_map *map; - aux = kzalloc(sizeof(*aux), GFP_KERNEL_ACCOUNT); - if (!aux) + map = array_map_alloc(attr); + if (IS_ERR(map)) return ERR_PTR(-ENOMEM); + aux = bpf_map_kzalloc(map, sizeof(*aux), GFP_KERNEL); + if (!aux) { + array_map_free(map); + return ERR_PTR(-ENOMEM); + } + INIT_WORK(&aux->work, prog_array_map_clear_deferred); INIT_LIST_HEAD(&aux->poke_progs); mutex_init(&aux->poke_mutex); - map = array_map_alloc(attr); - if (IS_ERR(map)) { - kfree(aux); - return map; - } - container_of(map, struct bpf_array, map)->aux = aux; aux->map = map;