Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756678AbbESPPt (ORCPT ); Tue, 19 May 2015 11:15:49 -0400 Received: from rrw.me.uk ([93.93.129.10]:54636 "EHLO rrw.me.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086AbbESPPs (ORCPT ); Tue, 19 May 2015 11:15:48 -0400 Message-ID: <555B53A4.3070907@kynesim.co.uk> Date: Tue, 19 May 2015 16:15:48 +0100 From: Richard Watts User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 003/003] Attempt to cope with device changes and delayed kobject deallocation References: <555B5305.9050506@kynesim.co.uk> In-Reply-To: <555B5305.9050506@kynesim.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1272 Lines: 44 Avoid issuing duplicate name errors when a kobject's sysfs directory is scheduled for deletion but has not yet been deleted, and a directory with the same name is created. Signed-off-by: Richard Watts --- fs/sysfs/dir.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 0b45ff4..e85de14 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -49,6 +49,21 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) else parent = sysfs_root_kn; + kn = kernfs_find_and_get_ns(parent, kobject_name(kobj), + ns); + /* This check is non-atomic, but that is OK - the worst thing + * that can happen is a concurrent removal of the sysfs dir, + * which is exactly what we want anyway. + */ + if (kn) { + struct kobject *kobj_exist = (struct kobject *)kn->priv; + + if (kobject_get_unless_zero(kobj_exist)) + kobject_put(kobj_exist); + else + sysfs_remove_dir(kobj_exist); + } + if (!parent) return -ENOENT; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/