Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1887848rwb; Fri, 11 Nov 2022 01:44:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/RpQ1+ldOGard7NW4nHZMNJdOaYTsQG41gQtEzpmX1JwLyYF18n7QpdCiIqqMH/CtHdQR X-Received: by 2002:a05:6402:2994:b0:460:858e:a8e1 with SMTP id eq20-20020a056402299400b00460858ea8e1mr718089edb.401.1668159853187; Fri, 11 Nov 2022 01:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668159853; cv=none; d=google.com; s=arc-20160816; b=mJUKVDdWkqNYDTN+EYQvgNppGW5zHQO3dLepjtLKnHmITduCNooIDLVCg4tanrm1zN 1lW6HUkUiP/JhGMbaDIYvxPHtNdw+cD2U+2sydSmLbU4AT5RfTc0BwThq1BTu85+cVpV 6fEgMDDEo/M8e3QhI3qPVHNJDxLeFgYM2brWDCjbCxTDK5WgEHp6hkcbM6g/LYBKNmJH lZadnq5WcEiESy+T6qtDi0supTm5Neo+gTwXNf6FNehF+b7IgMEICi/SI6dK6Ely+nCW uCbi1OhAvK85KijsDNy9Icnd6ieKip0XQasXFbiOr8591quMPbcxgswuNS/IZIgpYdH6 CImg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lSwSJupghEHvlKw/QDC7E/zwasXDJhrtxBZPd2Aj4is=; b=IxoJbClNjM9Ft1gem3zpd4Qgmnmr2MBYGDeMm+uHclq9Rer+BvXU2pmpXqHo7V+KQy 9/mbr2xrlNTp63jc/aM9xL7KaZv/Jcez9qFs8544hJk7jGO1UyXiDBL2rWCZpgkiZfMk XRSA0kw8tHMyLG6oKlpfgQAHP1X8+6ge5LXVF6UyvNyFs1urCG6agdcNUnoI3ov0V6/e HuTjAMod8fjZDaP6zLZpyMhyL8RrN6xoC9fzn33tpiz9PATyrsvu5tbX058/OuonX5kY lqvRCfh/scC56eN11Z5UP4p2kfHF8oEpZcce3jO2phrM7ZrP4Dwc3LnY1u6v3Fil9H2+ zWxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ipSXYwkc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a17090646c900b0078db719e54csi1288136ejs.98.2022.11.11.01.43.51; Fri, 11 Nov 2022 01:44:13 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ipSXYwkc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233423AbiKKJMY (ORCPT + 92 others); Fri, 11 Nov 2022 04:12:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbiKKJMB (ORCPT ); Fri, 11 Nov 2022 04:12:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B64345A0A for ; Fri, 11 Nov 2022 01:12:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AF50B61F0B for ; Fri, 11 Nov 2022 09:11:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6FEAC433C1; Fri, 11 Nov 2022 09:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1668157919; bh=nWF/LUpmIzCoLlSE9IWrM8CZh5pW6RJDYoO5gbGF3QU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ipSXYwkcFWUAPXfy/V/09L1fjvZkjZgPBnhQGRvI0SQl/g8csBkktYZOkgTUdSPIM v/KC4EF80V7HLN8YjyEGIt0QtWA1pvzlIaimzbNJHJG21n5UmPF+mOyVzZvabsB5e6 wKN0SkrP6pyGoG4fwTdu9GTFrwqqb02vig9sGuno= Date: Fri, 11 Nov 2022 10:11:56 +0100 From: Greg Kroah-Hartman To: Liu Shixin Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kobject: hide illegible sysfs warning of kobject_del() Message-ID: References: <20221111065807.3278713-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 On Fri, Nov 11, 2022 at 04:27:03PM +0800, Liu Shixin wrote: > > > On 2022/11/11 14:26, Greg Kroah-Hartman wrote: > > On Fri, Nov 11, 2022 at 02:58:07PM +0800, Liu Shixin wrote: > >> Some consumers do not care whether kobject_add() succeed or failed such as > >> irqdesc. They call kobject_del() all the time even if kobject_add() failed. > >> Then kernel will report some illegible sysfs warning like this: > >> > >> kernfs: can not remove 'actions', no directory > >> WARNING: CPU: 0 PID: 277 at fs/kernfs/dir.c:1615 kernfs_remove_by_name_ns+0xd5/0xe0 > > Why not fix the caller here? Is that somehow not possible? > The caller should be freed by kobject_put() if kobject_add() failed. But in fact, the failure does not affect > the function of the caller. So the caller do not call kobject_put() Immediately. > If want to fix the caller, we can check konj->state_in_sysfs before call kobject_del(). This way has no difference > with check kobj->state_in_sysfs in kobject_del(). No, no code should ever be checking the state_in_sysfs flag before calling this function. When a kobject is done with, by the creator of it, then it can call kobject_del(). It can NOT call that function multiple times, as that is just wrong and goes against the whole way the kobject should be used. So there is something very wrong with the caller code here, THAT should be fixed. > By the way, I'm not sure how many callers have this problem. So I think it's better to fix in kobject_del(). As we have never had this report before, I don't know of many problem users. Let's fix the root of the problem here please, do not paper over it by allowing this function to be called multiple times, as that is an indication that the reference counting logic of the caller is very wrong. thanks, greg k-h