Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp82791rwb; Wed, 10 Aug 2022 19:55:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7RNVXtKlC7SYCLSJ/jutZH0O8Qv6z0INvvs4QGID67yxxILtbeIP7vlARkfVz+2h8zg27r X-Received: by 2002:a17:907:7f9f:b0:733:76c:44c9 with SMTP id qk31-20020a1709077f9f00b00733076c44c9mr4435721ejc.642.1660186544442; Wed, 10 Aug 2022 19:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660186544; cv=none; d=google.com; s=arc-20160816; b=lXTDXg6WBAA2XTN51ZCA2yGhkqRM3RUUeZMn0AFmqcxwsELZ2+YsOviEc35kT0AOir RoajB6wwhh5OsjroPxy5rR8MZBPpxEaIiPv9SHbz45Ok5HZu8gpg1hBV3Kwbytsb+Rug EcmzS4MOnhDP2lJoO1/wrPE+u9KbMiyAod5D+LFWfSjfyjD0ddnzDxScLElPrNQoQgKP qwCFDi7UYBTx4K2zKV4RdbbIuuy8fwuEQb7bpFUuEGH9pFKa6cFtNechU758D+IJmdOA Dxo6GuF1/ZDPg8Fi7CNiNRyjmta2HRWLH61GglwvZ/rxXvLxSHC+mDSs2fIhMJ6dDq39 i3Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=m4eupV/bqgraGkoSaNC0TueVTSirQ6nlHGLDaCkBbv0=; b=SD8AePaK81WBC2JF+0WnVJhlifaJ/sJxOdtbi38nEVlYFRXAZqi8517iGbmVnWvMcL TAYGjvQfrcKqiNJhPqD612IOegL7v0Hskp8YjJlQ4Ka7+nmbKtMDTZkWC3udmdXHbT8P K3QW7bsCZVNF1NdeG1NzGrpP+QpbZeE7+RMQ3xzHuHz9ROJ/U3JdWekCiwMEakH44ywX uX22juWEc3M+21y8eNavYlRujKgoeRD0dKSazgUwTdV9dsk/0xuYEBSI58mmgO35bhi2 yhwtnUATL2++IvBeYTORQwQrHrlyH/l9DN8RNMq9/4zl+gaY7laYTUWbbvALugiMGXTO ZxNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw39-20020a1709066a2700b007308bf614f7si5775510ejc.512.2022.08.10.19.55.18; Wed, 10 Aug 2022 19:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233740AbiHKCxI (ORCPT + 99 others); Wed, 10 Aug 2022 22:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbiHKCxG (ORCPT ); Wed, 10 Aug 2022 22:53:06 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 791A0883CE for ; Wed, 10 Aug 2022 19:53:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VLxI13B_1660186379; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VLxI13B_1660186379) by smtp.aliyun-inc.com; Thu, 11 Aug 2022 10:53:01 +0800 From: Xin Hao To: cl@linux.com Cc: penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add Date: Thu, 11 Aug 2022 10:52:58 +0800 Message-Id: <20220811025258.68684-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kobject_init_and_add() function, the refcount is setted by calling kobject_init() function, regardless of whether the return value is zero or not, therefore, we must call kobject_del(&s->kobj) to prevent memory of s->kobj is leaked. Signed-off-by: Xin Hao --- mm/slub.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index b1281b8654bd..63b0a8a3a71f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5981,19 +5981,18 @@ static int sysfs_slab_add(struct kmem_cache *s) err = sysfs_create_group(&s->kobj, &slab_attr_group); if (err) - goto out_del_kobj; + goto out; if (!unmergeable) { /* Setup first alias */ sysfs_slab_alias(s, s->name); } + return err; out: if (!unmergeable) kfree(name); - return err; -out_del_kobj: kobject_del(&s->kobj); - goto out; + return err; } void sysfs_slab_unlink(struct kmem_cache *s) -- 2.31.0