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=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 270E3C433DF for ; Wed, 3 Jun 2020 00:22:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B95B0206A2 for ; Wed, 3 Jun 2020 00:22:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cyJgKLA6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B95B0206A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 15FFD8E0007; Tue, 2 Jun 2020 20:22:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EA768E0006; Tue, 2 Jun 2020 20:22:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF39E8E0007; Tue, 2 Jun 2020 20:22:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id D72B08E0006 for ; Tue, 2 Jun 2020 20:22:08 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9D4A8180AD801 for ; Wed, 3 Jun 2020 00:22:08 +0000 (UTC) X-FDA: 76885998336.19.wound90_69ecf68caa55c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 58D371AD1B0 for ; Wed, 3 Jun 2020 00:22:08 +0000 (UTC) X-HE-Tag: wound90_69ecf68caa55c X-Filterd-Recvd-Size: 4056 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Jun 2020 00:22:07 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id n141so467102qke.2 for ; Tue, 02 Jun 2020 17:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DRD7YwKwRFVA3B7g0OFuzsnYknxQvOSoNwCph4a8ztU=; b=cyJgKLA6ugqfSABxXXPRe8dx2rMgQbVMym1YRt0QjZfer40tx1GKUOiD4U2QTjjGHY 6LBUJfel2veh1e9nty/6xrBOfWKNzGA+3GAdi0FHZU8k/hdUDMvs9wZA9KyTFfZmw2OH IY9kIsolEq18co4zZFyOMe3Z1pYS779I3BUrE3adDtlFR6rfE7B5KRAlw3vxuu5q5GwE TzBqYJtcY1ZToG73rIOZBnFzpvswIQdRIyTfGCQ8PZO4WxkkHcbouM7dijuBxAOVMOaK l4Krb/CwMD+RtxFc9M+tIwekOOCcKHD9NUAJoXPi24V7MQjUOF48D7f9MBk3MKjcAVB/ sm6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DRD7YwKwRFVA3B7g0OFuzsnYknxQvOSoNwCph4a8ztU=; b=MGrY0fSgGGlxfGROJsxkwkWBQLjgGU4LmX43aa7ZlmmEW73kUFaVAA0P912U0muj4B SGuZaWdQfvnUw7RuQSPigohPxOMCR6hgTe9ayBQEfncqqtjfCnjKJoJZ+bl82Vr6hACu MH5VJlp4Ne7YrCVdAbHM3/2JFNndzdAyMK2siZ8WfF7u4bVofpTHj/KCjcO8QaO/P+oj yuSSONU2Ef3gKfW8lYcxJ/Ti3xBj3BAQLjxeKjyIzf4I1fOWV3ehcqrAqHKLEU0/VYWV 50XyfQ4y5L0T0wdofij+nkJuNJTr6YdDcykK9g1pwVgWAS0ebX4uoDw2UMoQljFlsg7q cxuQ== X-Gm-Message-State: AOAM531/txoWQoRbQjzBvGRyCF19YKXII8wrWjPtid5zEq0X+rhF+eU9 aqPLrzZ+S6pOrWUtlbOtDKYrzQ== X-Google-Smtp-Source: ABdhPJw9dIODI1VMIz7ZY7uYdbgoUa3gNBH/roXr+qSQ6H4FbDKjGaauBBlYNcKV/KSXKFfwudGycg== X-Received: by 2002:ae9:eb83:: with SMTP id b125mr29243448qkg.85.1591143727204; Tue, 02 Jun 2020 17:22:07 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id n85sm258001qkn.31.2020.06.02.17.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 17:22:06 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.93) (envelope-from ) id 1jgHAT-000YFn-J0; Tue, 02 Jun 2020 21:22:05 -0300 Date: Tue, 2 Jun 2020 21:22:05 -0300 From: Jason Gunthorpe To: James Bottomley Cc: Greg Kroah-Hartman , Matthew Wilcox , Wang Hai , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, khlebnikov@yandex-team.ru, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: kobject_init_and_add is easy to misuse Message-ID: <20200603002205.GE6578@ziepe.ca> References: <20200602115033.1054-1-wanghai38@huawei.com> <20200602121035.GL19604@bombadil.infradead.org> <1591111514.4253.32.camel@HansenPartnership.com> <20200602173603.GB3579519@kroah.com> <1591127656.16819.7.camel@HansenPartnership.com> <20200602200756.GA3933938@kroah.com> <1591134670.16819.18.camel@HansenPartnership.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591134670.16819.18.camel@HansenPartnership.com> X-Rspamd-Queue-Id: 58D371AD1B0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > My first thought was "what? I got suckered into creating a patch", > thanks ;-) But now I look, all the error paths do unwind back to the > initial state, so kfree() on error looks to be completely correct. It doesn't fully unwind if the kobject is put into a kset, then another thread can get the kref during kset_find_obj() and kfree() won't wait for the kref to go to 0. It must use put. Jason