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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B802C00140 for ; Thu, 11 Aug 2022 03:31:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7998F8E0002; Wed, 10 Aug 2022 23:31:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 721D18E0001; Wed, 10 Aug 2022 23:31:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59B188E0002; Wed, 10 Aug 2022 23:31:46 -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 463528E0001 for ; Wed, 10 Aug 2022 23:31:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 09622120539 for ; Thu, 11 Aug 2022 03:31:46 +0000 (UTC) X-FDA: 79785887412.07.9381EF2 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf20.hostedemail.com (Postfix) with ESMTP id B25B41C0068 for ; Thu, 11 Aug 2022 03:31:45 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id e8-20020a17090a280800b001f2fef7886eso3958170pjd.3 for ; Wed, 10 Aug 2022 20:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=nizGAqsGvNty3FjGN1FmrbrySk9zLGzFpUrnR3N2SRk=; b=dJ7uOaMmQBw5zAfFc1/imTdbTvwc9jKJSsyfxM+9arNUe4P0A6TcoZhQiCY/3Xr516 Kre6lKgerkFwTGPHSRFO68+JUEn33RJOElXL0IaOuxoGjAf+4BXQlqIZnWlZGgJWD8ef c6DL1hbHN/PiVm4nxzXxPPa3feYvITwWAG99CcyRILSoAIEHlTzih96qWmmyYeCqd5S4 tm9DTdRbhO9v4lwUIYaRecD9XgOc0j8nOogeT/cUV33Ry86SV6UdqO++kuXFpsP6xmzT QEWAkc7mDJFd+M2rr1abUvLJ3GtI5iogY0naB8103iXl8Zlme5hQEBFeaVsBgWyOXbzz 6A/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=nizGAqsGvNty3FjGN1FmrbrySk9zLGzFpUrnR3N2SRk=; b=dhnv46B5mht5tXaqi92KNMqcj979Xfkz/gWyO5XRWcybepQ3YQrFsDQt7yAGbPP/Lz 9HgdGHVSIHlo3BMZ+MRTJ0NDyyXae/6JUbOOcEAh/gP7dCOB+A+Qv0VPcs8STn70MVWw KvQCAPl6jPyD7dE4CD6zaiKaVb3nHBtYQyRXYY3gUFjAthvB/U1mthxWH6vMNsOs0y6/ qxmtJz/ofHzbM472ve+VNiYlhcYNZ5z9NT3Hs4Tjnq3wE/5LZCkfbc6NdcWhYXzCbeZW BIroYW1eLXvs9ASeVOAEXtSPG1G9CyWTghajrVS9Z4KLt1MwMNNFC4pvAfnyW8IbVpSI mcFw== X-Gm-Message-State: ACgBeo2Rtx586K0KU/9aiCyO9SdVPhq7BgO/4g11BKnhUNIEfzKicggs fsk/yvJ7UZmcS2GTu0TSbRI= X-Google-Smtp-Source: AA6agR7R/N0OwsAvUkoa9TMbFz6/N7vEM+iwa14ijVMAkK8pfq2FillX84ubn/vg4F6cJN8OAKt+Aw== X-Received: by 2002:a17:902:b20d:b0:16d:aefa:8ef6 with SMTP id t13-20020a170902b20d00b0016daefa8ef6mr31113052plr.90.1660188704446; Wed, 10 Aug 2022 20:31:44 -0700 (PDT) Received: from ip-172-31-24-42.ap-northeast-1.compute.internal (ec2-35-79-20-36.ap-northeast-1.compute.amazonaws.com. [35.79.20.36]) by smtp.gmail.com with ESMTPSA id y23-20020a170902b49700b0016bf9437766sm13645494plr.261.2022.08.10.20.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 20:31:43 -0700 (PDT) Date: Thu, 11 Aug 2022 03:31:38 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Xin Hao Cc: cl@linux.com, 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: Re: [PATCH] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add Message-ID: References: <20220811025258.68684-1-xhao@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220811025258.68684-1-xhao@linux.alibaba.com> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660188705; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nizGAqsGvNty3FjGN1FmrbrySk9zLGzFpUrnR3N2SRk=; b=48DXUIVoj+PvJ7PtZZuPp4Nby9LtAdGNlBwFXYIHGbDM8lCfie6n3ubGPQiSiy8dM1m1Ym TYkrlHy6Du2RmsAqBsIyM6Ia2Q0w/s9+EIUcixp30THJxVkp/wPSgeEKOAH4odX9z56Rlc RAOHMvw/ekCTGNgQejzvqqfZoArqsXY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dJ7uOaMm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660188705; a=rsa-sha256; cv=none; b=u6p28+X1WOQe5YDnx4l2lkD5oKN2VaAkfJp/0v+bF7RwpDm1Cr50zhAR3aHq+kQi4YXjZ3 HWSTlwheb1UAh1ZGi3oouJkgjfqEhc4Hu715jZEaPs4K7SkxOuyqCi8zoRPgCjzv4B75fm kCJHtwRhD09xzgEjtg3viZP1hjR0nPQ= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B25B41C0068 X-Rspam-User: X-Stat-Signature: 1at38f44b641rxja54cew3ssc5es5ibg Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dJ7uOaMm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-HE-Tag: 1660188705-506832 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: On Thu, Aug 11, 2022 at 10:52:58AM +0800, Xin Hao wrote: > 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 Hello and thanks! Should kobject_del() be called when kobject_add() failed? its comments says: 597 * kobject_del() - Unlink kobject from hierarchy. 598 * @kobj: object. 599 * 600 * This is the function that should be called to delete an object 601 * successfully added via kobject_add(). AFAIK kobject_put() is proper function to call when kobject_init_and_add() failed as stated in its comment: 417 /** 418 * kobject_init_and_add() - Initialize a kobject structure and add it to 419 * the kobject hierarchy. 420 * @kobj: pointer to the kobject to initialize 421 * @ktype: pointer to the ktype for this kobject. 422 * @parent: pointer to the parent of this kobject. 423 * @fmt: the name of the kobject. 424 * 425 * This function combines the call to kobject_init() and kobject_add(). 426 * 427 * If this function returns an error, kobject_put() must be called to 428 * properly clean up the memory associated with the object. This is the 429 * same type of error handling after a call to kobject_add() and kobject 430 * lifetime rules are the same here. > 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