From patchwork Fri Dec 6 00:38:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 3291981 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F7EC9F37C for ; Fri, 6 Dec 2013 00:38:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AFB72050B for ; Fri, 6 Dec 2013 00:38:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72037204FB for ; Fri, 6 Dec 2013 00:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650Ab3LFAiE (ORCPT ); Thu, 5 Dec 2013 19:38:04 -0500 Received: from mail-ob0-f170.google.com ([209.85.214.170]:42746 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756520Ab3LFAiD (ORCPT ); Thu, 5 Dec 2013 19:38:03 -0500 Received: by mail-ob0-f170.google.com with SMTP id wp18so3033obc.1 for ; Thu, 05 Dec 2013 16:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=TtNtic8qQ8nSvUN8D9bR6GukoD5vIpuk6aEqQLUVpZ0=; b=CmbUyRkEYTMumQvSzoq3qlFvO8/cmBgoSKe4Z6oPTbgIJXR2opLTq5JYF5LxkUhv0z 0YX4eiIsJdg3ZKXKZelqyepHqrR1K79vVeboV+K5OZEmieO+qeAlo/O5Fox5rz7+Nd1S 3SApq7xcDpdp+0PGFaoL2Jz1h4WCMrDk9iDBXrQMpZqtv6G4Va0EhKNAoJPWnLhrZHBp HPHekj1nrVgflzuJogUUNk2CF884sdQXUYdyG7dH8fmvTwXXhQiK2ltlrckls9PYtIYC PFjlh9jwyq57uqJ4GXYp1oh2IOuIUJRUyLxX6s2Ysm/oBm1K9Ol7HhuT+4yr39fHyM7I XBBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=TtNtic8qQ8nSvUN8D9bR6GukoD5vIpuk6aEqQLUVpZ0=; b=h8hNr8eoaLSA1WjUZ5XSZTGf6N8wsiNt2m+3L/eWG2OlYjVniqP3aUM0M+1LPiWSkC I799TgCZDcHAqPJXuGDxBW/plNdUSV6c2k7oiFdereZmlQUE2RYeGbZOzw3cvwN8ufru urqDg4eFCBrPniFOo2ciOwTS1Nyi4BoBu6h7GqpUZDt9TJ+bwmG69bLXRjFQEKCEbf9T ObgF0JQGschx2RPWKRWsTRE+GPSD2yxUqegpaFZdWr5n1a0KpJeeMxmDAcFmL/ArNp2M zFKw3K8/l5StBfqYIMCw/+oovEXMzOH+aePMyGvTWpa+QZwnk0XycTRckmTWL3CA0IqQ PJxQ== X-Gm-Message-State: ALoCoQn1Cuwp/b96XJqQUYOkxM4aYHRFZhnHrxYjlal3ltBxI377DrvqVJJD5tsV7YjuGqpEZKtCAk4BVKaYORzwU7Tmz6+5slI3dLBrp6K6q19p2Dw+NcRg6jRtzJW7sRAiWO+BlNQQQ0DlMiv3SjJYY+tLaeBewETspZnkWtTJorqbE7tnU7XGVZqio7lr4TKla2VixCSpa8gshaTYyyCurUCeCdBc/w== X-Received: by 10.182.42.105 with SMTP id n9mr414958obl.33.1386290282443; Thu, 05 Dec 2013 16:38:02 -0800 (PST) Received: from localhost ([216.160.131.133]) by mx.google.com with ESMTPSA id m4sm569366oen.7.2013.12.05.16.38.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 16:38:01 -0800 (PST) Subject: [PATCH v2 2/2] kobject: remove kset from sysfs immediately in kset_unregister() To: Greg Kroah-Hartman From: Bjorn Helgaas Cc: Veaceslav Falico , Russell King , Neil Horman , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Zdenek Kabelac Date: Thu, 05 Dec 2013 17:38:00 -0700 Message-ID: <20131206003759.28684.63772.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20131206003508.28684.1337.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20131206003508.28684.1337.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's no "unlink from sysfs" interface for ksets, so I think callers of kset_unregister() expect the kset to be removed from sysfs immediately, without waiting for the last reference to be released. This patch makes the sysfs removal happen immediately, so the caller may create a new kset with the same name as soon as kset_unregister() returns. Without this, every caller has to call "kobject_del(&kset->kobj)" first unless it knows it will never create a new kset with the same name. This sometimes shows up on module unload and reload, where the reload fails because it tries to create a kobject with the same name as one from the original load that still exists. CONFIG_DEBUG_KOBJECT_RELEASE=y makes this problem easier to hit. Signed-off-by: Bjorn Helgaas --- Documentation/kobject.txt | 5 ++++- lib/kobject.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt index c5182bb2c16c..f87241dfed87 100644 --- a/Documentation/kobject.txt +++ b/Documentation/kobject.txt @@ -342,7 +342,10 @@ kset use: When you are finished with the kset, call: void kset_unregister(struct kset *kset); -to destroy it. +to destroy it. This removes the kset from sysfs and decrements its reference +count. When the reference count goes to zero, the kset will be released. +Because other references to the kset may still exist, the release may happen +after kset_unregister() returns. An example of using a kset can be seen in the samples/kobject/kset-example.c file in the kernel tree. diff --git a/lib/kobject.c b/lib/kobject.c index bc73312ac797..40e3b2c0abae 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -757,6 +757,7 @@ void kset_unregister(struct kset *k) { if (!k) return; + kobject_del(&k->kobj); kobject_put(&k->kobj); }