mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Dominik Brodowski <linux@dominikbrodowski.net>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: v5.13-rcX regression - NULL pointer dereference - MFD and software node API
Date: Mon, 21 Jun 2021 13:37:59 +0300	[thread overview]
Message-ID: <YNBsB6zIo4A4vD4w@kuha.fi.intel.com> (raw)
In-Reply-To: <YNBjJnxrXaWmfUqo@smile.fi.intel.com>

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

On Mon, Jun 21, 2021 at 01:00:06PM +0300, Andy Shevchenko wrote:
> Can you, please, attach this to the bug report?
> 
> Long story here is that the device creation fails but we already have added
> swnode to it. Meanwhile, device itself is not completely instantiated (yet)
> and dev_name(dev) is NULL. The software_node_notify() is called with such
> device and Oopses in the following line
> 
> 	sysfs_remove_link(&swnode->kobj, dev_name(dev));
> 
> My patch fixes another issue that might happen before this and in the code
> that retrieves swnode itself in the device_remove_software_node().
> 
> Of course my patch won't fix this issue.
> 
> I have heard that Heikki is looking how to fix the issue in your case and
> potentially in any other cases where device_add_software_node() is called
> against not formed object instance.

Dominik, can you test the attached patch to confirm if this really is
the case.

thanks,

-- 
heikki

[-- Attachment #2: 0001-software-node-Handle-software-node-injection-to-an-e.patch --]
[-- Type: text/plain, Size: 1759 bytes --]

From 0cddd29f5d5d41d1b7fa38b0f927f4e755a1bcd0 Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Date: Mon, 21 Jun 2021 13:31:51 +0300
Subject: [PATCH] software node: Handle software node injection to an existing
 device properly

Interim, work-in-progress.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/base/swnode.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 3cc11b813f28c..33c8f31dbab4f 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -1045,7 +1045,15 @@ int device_add_software_node(struct device *dev, const struct software_node *nod
 	}
 
 	set_secondary_fwnode(dev, &swnode->fwnode);
-	software_node_notify(dev, KOBJ_ADD);
+
+	/*
+	 * In some special cases the software node has to be injected to an
+	 * already existing device. In these cases software_node_node() has to
+	 * be called separate from here. Using the device name here to check was
+	 * the device already added or not.
+	 */
+	if (dev_name(dev))
+		software_node_notify(dev, KOBJ_ADD);
 
 	return 0;
 }
@@ -1065,7 +1073,8 @@ void device_remove_software_node(struct device *dev)
 	if (!swnode)
 		return;
 
-	software_node_notify(dev, KOBJ_REMOVE);
+	if (dev_name(dev))
+		software_node_notify(dev, KOBJ_REMOVE);
 	set_secondary_fwnode(dev, NULL);
 	kobject_put(&swnode->kobj);
 }
@@ -1119,8 +1128,7 @@ int software_node_notify(struct device *dev, unsigned long action)
 
 	switch (action) {
 	case KOBJ_ADD:
-		ret = sysfs_create_link_nowarn(&dev->kobj, &swnode->kobj,
-					       "software_node");
+		ret = sysfs_create_link(&dev->kobj, &swnode->kobj, "software_node");
 		if (ret)
 			break;
 
-- 
2.30.2


  reply	other threads:[~2021-06-21 10:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-20  8:26 Dominik Brodowski
2021-06-20 11:19 ` Andy Shevchenko
2021-06-20 11:49   ` Dominik Brodowski
2021-06-20 16:36     ` Andy Shevchenko
2021-06-20 18:27       ` Andy Shevchenko
2021-06-21  8:59         ` Dominik Brodowski
2021-06-21 10:00           ` Andy Shevchenko
2021-06-21 10:37             ` Heikki Krogerus [this message]
2021-06-21 15:31               ` Dominik Brodowski
2021-06-22  8:09                 ` Heikki Krogerus
2021-06-22 14:10                   ` Heikki Krogerus
2021-06-22 14:36                     ` Dominik Brodowski
2021-06-22 15:28                       ` Andy Shevchenko
2021-06-22 17:19                         ` Dominik Brodowski
2021-06-22 15:28                     ` Andy Shevchenko
2021-06-22 15:30                       ` Andy Shevchenko
2021-06-23 10:51                         ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YNBsB6zIo4A4vD4w@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®