Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3651858pxj; Mon, 21 Jun 2021 03:39:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwntIaguSyRFxFL7wO4UbIv/IqY0y2gsIEnCym/Azwon7pQxY5DY1yvXnEUCV8BzdI6cGpX X-Received: by 2002:a17:906:af85:: with SMTP id mj5mr24776201ejb.352.1624271964003; Mon, 21 Jun 2021 03:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624271963; cv=none; d=google.com; s=arc-20160816; b=PRphCO6gSM0s+WjaUmrpN1/IN/VgAQL6uORZARPjf65V/COHgFWvk4Soxb1EzmZyfL 5eFIBgIVti7j1+Q+zJ2S+Z1vkqfpxCd6ZUScQzZvSLEnpPguOKsXAjT292kync6v7nke I2DnleO5LWA1Xm28HMJOWKPURDIbxnlzDhRMemQbkrhd/M+Fgaxw1bVTfQryeSbXJyLu uCisLYKyuAhOCW8FHqnxyuPlTcYFuXsZMd3gruoqTQVRgjd/kuN1sD5wL6ChKXQBi4Xc hL9zch1ZwlCRkyHkA//2QIfIUFqRCPcodyCuMSTSQ1T74Ty59mldYcwg9cHvTCfTRpno 7KWQ== 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:ironport-sdr :ironport-sdr; bh=wb7bLYHG3yaeP8U9QUOAtSxGj6c982J2SINscz7gzLY=; b=0hA0rDYLoQXFo+WnHNzWDvjGwf1tipV8rikQEl9QVrdharLZ8B9jQMnB/9ianl3C7P r8zOjdSZYWCzQijszPfOO3QKcxunmulRvj8O7YU//o72kzQHUzbzmSRFU2CGOBiOPGb7 eiho8gLlVRdijfzEk40bngl2DQILQF8F5+KWwYx6p5+fvZBFEPMfhegBR4gcpHymOtCG xjedy+xBEXMg3e8uN0cy/dGB/Xzwhe44au2oKE/VbopggWv0MDj3LUpUcRGUkBfp0p5N MqKcPkOlCkIbI7giFrIUY8D006j3NX1URnAHnUcLYzu3gYe7zx9fu4gc1dNFkNikoogf ZDRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si11632727edp.580.2021.06.21.03.39.01; Mon, 21 Jun 2021 03:39:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbhFUKkQ (ORCPT + 99 others); Mon, 21 Jun 2021 06:40:16 -0400 Received: from mga17.intel.com ([192.55.52.151]:19756 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbhFUKkQ (ORCPT ); Mon, 21 Jun 2021 06:40:16 -0400 IronPort-SDR: /x0XUXdtXMdcSu63aD7ZMFmhueVPM1Q/5hgfRDdvlL5961p69G3OZw6QGijX67l1Vc7JQPF+Gg q0sPLKwAdu0g== X-IronPort-AV: E=McAfee;i="6200,9189,10021"; a="187192984" X-IronPort-AV: E=Sophos;i="5.83,289,1616482800"; d="scan'208,223";a="187192984" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2021 03:38:02 -0700 IronPort-SDR: sy5gDF9Gq5G92YANc7zNj+jUlB3Edt4JFFqBdQFsjpaoFCvuk9Hyv1liJZ7AvXfyiSc2RT7TVC xsiz7CaxDKVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,289,1616482800"; d="scan'208,223";a="556202435" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 21 Jun 2021 03:37:59 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 21 Jun 2021 13:37:59 +0300 Date: Mon, 21 Jun 2021 13:37:59 +0300 From: Heikki Krogerus To: Dominik Brodowski , Andy Shevchenko Cc: Lee Jones , Linux Kernel Mailing List Subject: Re: v5.13-rcX regression - NULL pointer dereference - MFD and software node API Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="td8fQmGGYj1nswxy" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --td8fQmGGYj1nswxy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --td8fQmGGYj1nswxy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-software-node-Handle-software-node-injection-to-an-e.patch" From 0cddd29f5d5d41d1b7fa38b0f927f4e755a1bcd0 Mon Sep 17 00:00:00 2001 From: Heikki Krogerus 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 --- 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 --td8fQmGGYj1nswxy--