From patchwork Fri Sep 2 02:29:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12963568 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 B46EDECAAD2 for ; Fri, 2 Sep 2022 02:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EDFC8009F; Thu, 1 Sep 2022 22:30:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49DD48008D; Thu, 1 Sep 2022 22:30:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F0B58009F; Thu, 1 Sep 2022 22:30:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1EA008008D for ; Thu, 1 Sep 2022 22:30:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DFAA01A1167 for ; Fri, 2 Sep 2022 02:30:28 +0000 (UTC) X-FDA: 79865566536.17.93993AD Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf18.hostedemail.com (Postfix) with ESMTP id 996B11C0049 for ; Fri, 2 Sep 2022 02:30:28 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id u22so507425plq.12 for ; Thu, 01 Sep 2022 19:30:28 -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=V0gc6AUiAQY/WQln3OGyPk91MKpBrNPoI3+sFkmiGew=; b=YdKJPsj3wxmrtdhJ63cf//SS9jJ7JPgMY5Ex1l+fOx9UNzapxQ7i8fyfCKfg4DC/fk SKCqoIu3Lb00g2SEoCnPl+BmSgfvaKisdl966nvF6kLOv46V4GjP7QAko0FRxIpQUgDP +BAUY24JOpf1j9T/XcBIZ1nzFMUebVEKtDxZ3QHbKE/m/bDB7+h36BTsKpp/lHfXQVv6 GmxW8iDrtqqVi0VcXAO6aBbWMwwAb6hXr2tJE3pBNIxaczYssgaQaXmHSMnehmD0T9In MbelyenA6iu3l7pz8fEFlMFkPExLSWN/gjke+3if8/R7WdY2vWMLVfeC38NKGyCWOiVt Vhjw== 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=V0gc6AUiAQY/WQln3OGyPk91MKpBrNPoI3+sFkmiGew=; b=X2491jjeVKvu7bAiEtU/GExDR4QWJZ4BAcATjL01XNodDhQo6a6PoS9WzGqFrlbDEK /ET/+RAVsAY7DAvAujz12NtX6N+I8vYIJYSJp3DF2/hVxCVspzkztO2HmHyfz4wY0hzp yhG/5B454gAgMMHvWm+PFqqGT0FQOz/27dXVrdq39m0HaCgpy8XGsa/fqbtb+UiWzfFB N7eTfja7CsUA347hHR9/IeAh9HnNgKLlK8Ok3P6lm7F/fW15aAW041lTLipaVdr3Wn6m qbjL2OSQzWqhsHRiuJjqlMdAW6upJOXEVsxKbw/OVBdtuRKJViXKsm/xgCBxIZ8CgdGA WAZQ== X-Gm-Message-State: ACgBeo3T2KNA8jzGUspSn2i6e92/ar49jVXdDqEseRXmjTcgSczGcl4a dBhn3xZaoF6U6NPDYWIZBsU= X-Google-Smtp-Source: AA6agR5uktgD0liwSY6UrfEhRG+mLXx9clJMktiplgxkJLtJtcoS4ulnUGKjv6sSBbLKMm+PhmeuJQ== X-Received: by 2002:a17:902:8e88:b0:172:d1f8:efcb with SMTP id bg8-20020a1709028e8800b00172d1f8efcbmr32528601plb.27.1662085827706; Thu, 01 Sep 2022 19:30:27 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:50ea:5400:4ff:fe1f:fbe2]) by smtp.gmail.com with ESMTPSA id j4-20020a170902da8400b0017297a6b39dsm269719plx.265.2022.09.01.19.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 19:30:26 -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: [PATCH bpf-next v3 08/13] bpf: Use bpf_map_kzalloc in arraymap Date: Fri, 2 Sep 2022 02:29:58 +0000 Message-Id: <20220902023003.47124-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220902023003.47124-1-laoar.shao@gmail.com> References: <20220902023003.47124-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662085828; a=rsa-sha256; cv=none; b=c+cSmfjtAE2UK2MZhK902p4miWqM/JoyTQL3DteDFvqRWumKYOBZuLgustNKaZF9TIVK36 8u0rJNmgtF4hzzNZ0LPyVPkp/UveAQCFaqY8a4Y7yr16iCYfbsoPpijlB6pSAdUCLBnctf b64VDwR9wlrKfTyyjXqfNsXnID3yzcc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YdKJPsj3; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.175 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=1662085828; 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=V0gc6AUiAQY/WQln3OGyPk91MKpBrNPoI3+sFkmiGew=; b=AjFz9IR6ipkZft2mJi6wGNcK7fMmvXp59YLxJPOdk9tzPxbqydji1khsjL+VwecRTn5Ea+ L9y2JlE42r2blGvPxKrY9SOfaf+wm8Fz1tf09jE+XH/mNiMOSk0yjxtqVClSOYgi8rsbjY lWJhGM3LgtNSDGodU5eG5sn3q/V/RZ8= X-Stat-Signature: itddzmrnq9zqujxoxc5iipg4z3mqor16 X-Rspam-User: X-Rspamd-Queue-Id: 996B11C0049 X-Rspamd-Server: rspam07 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YdKJPsj3; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1662085828-83888 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 114fbda..f953acc 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -1096,20 +1096,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;