Takashi Iwai 76fc68
From d0ff14fdc987303aeeb7de6f1bd72c3749ae2a9b Mon Sep 17 00:00:00 2001
Takashi Iwai 76fc68
From: Michael Kelley <mikelley@microsoft.com>
Takashi Iwai 76fc68
Date: Thu, 1 Aug 2019 23:53:53 +0000
Takashi Iwai 76fc68
Subject: [PATCH] genirq: Properly pair kobject_del() with kobject_add()
Takashi Iwai 76fc68
Git-commit: d0ff14fdc987303aeeb7de6f1bd72c3749ae2a9b
Takashi Iwai 76fc68
Patch-mainline: v5.3-rc6
Takashi Iwai 76fc68
References: bsc#1051510
Takashi Iwai 76fc68
Takashi Iwai 76fc68
If alloc_descs() fails before irq_sysfs_init() has run, free_desc() in the
Takashi Iwai 76fc68
cleanup path will call kobject_del() even though the kobject has not been
Takashi Iwai 76fc68
added with kobject_add().
Takashi Iwai 76fc68
Takashi Iwai 76fc68
Fix this by making the call to kobject_del() conditional on whether
Takashi Iwai 76fc68
irq_sysfs_init() has run.
Takashi Iwai 76fc68
Takashi Iwai 76fc68
This problem surfaced because commit aa30f47cf666 ("kobject: Add support
Takashi Iwai 76fc68
for default attribute groups to kobj_type") makes kobject_del() stricter
Takashi Iwai 76fc68
about pairing with kobject_add(). If the pairing is incorrrect, a WARNING
Takashi Iwai 76fc68
and backtrace occur in sysfs_remove_group() because there is no parent.
Takashi Iwai 76fc68
Takashi Iwai 76fc68
[ tglx: Add a comment to the code and make it work with CONFIG_SYSFS=n ]
Takashi Iwai 76fc68
Takashi Iwai 76fc68
Fixes: ecb3f394c5db ("genirq: Expose interrupt information through sysfs")
Takashi Iwai 76fc68
Signed-off-by: Michael Kelley <mikelley@microsoft.com>
Takashi Iwai 76fc68
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Takashi Iwai 76fc68
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Takashi Iwai 76fc68
Cc: stable@vger.kernel.org
Takashi Iwai 76fc68
Link: https://lkml.kernel.org/r/1564703564-4116-1-git-send-email-mikelley@microsoft.com
Takashi Iwai 76fc68
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 76fc68
Takashi Iwai 76fc68
---
Takashi Iwai 76fc68
 kernel/irq/irqdesc.c | 15 ++++++++++++++-
Takashi Iwai 76fc68
 1 file changed, 14 insertions(+), 1 deletion(-)
Takashi Iwai 76fc68
Takashi Iwai 76fc68
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
Takashi Iwai 76fc68
index 9484e88dabc2..9be995fc3c5a 100644
Takashi Iwai 76fc68
--- a/kernel/irq/irqdesc.c
Takashi Iwai 76fc68
+++ b/kernel/irq/irqdesc.c
Takashi Iwai 76fc68
@@ -295,6 +295,18 @@ static void irq_sysfs_add(int irq, struct irq_desc *desc)
Takashi Iwai 76fc68
 	}
Takashi Iwai 76fc68
 }
Takashi Iwai 76fc68
 
Takashi Iwai 76fc68
+static void irq_sysfs_del(struct irq_desc *desc)
Takashi Iwai 76fc68
+{
Takashi Iwai 76fc68
+	/*
Takashi Iwai 76fc68
+	 * If irq_sysfs_init() has not yet been invoked (early boot), then
Takashi Iwai 76fc68
+	 * irq_kobj_base is NULL and the descriptor was never added.
Takashi Iwai 76fc68
+	 * kobject_del() complains about a object with no parent, so make
Takashi Iwai 76fc68
+	 * it conditional.
Takashi Iwai 76fc68
+	 */
Takashi Iwai 76fc68
+	if (irq_kobj_base)
Takashi Iwai 76fc68
+		kobject_del(&desc->kobj);
Takashi Iwai 76fc68
+}
Takashi Iwai 76fc68
+
Takashi Iwai 76fc68
 static int __init irq_sysfs_init(void)
Takashi Iwai 76fc68
 {
Takashi Iwai 76fc68
 	struct irq_desc *desc;
Takashi Iwai 76fc68
@@ -325,6 +337,7 @@ static struct kobj_type irq_kobj_type = {
Takashi Iwai 76fc68
 };
Takashi Iwai 76fc68
 
Takashi Iwai 76fc68
 static void irq_sysfs_add(int irq, struct irq_desc *desc) {}
Takashi Iwai 76fc68
+static void irq_sysfs_del(struct irq_desc *desc) {}
Takashi Iwai 76fc68
 
Takashi Iwai 76fc68
 #endif /* CONFIG_SYSFS */
Takashi Iwai 76fc68
 
Takashi Iwai 76fc68
@@ -438,7 +451,7 @@ static void free_desc(unsigned int irq)
Takashi Iwai 76fc68
 	 * The sysfs entry must be serialized against a concurrent
Takashi Iwai 76fc68
 	 * irq_sysfs_init() as well.
Takashi Iwai 76fc68
 	 */
Takashi Iwai 76fc68
-	kobject_del(&desc->kobj);
Takashi Iwai 76fc68
+	irq_sysfs_del(desc);
Takashi Iwai 76fc68
 	delete_irq_desc(irq);
Takashi Iwai 76fc68
 
Takashi Iwai 76fc68
 	/*
Takashi Iwai 76fc68
-- 
Takashi Iwai 76fc68
2.16.4
Takashi Iwai 76fc68