All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse
@ 2017-05-30 16:25 Johan Hovold
  2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
                   ` (6 more replies)
  0 siblings, 7 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold

This series fixes a few issues related to device-tree node reuse.

It is fairly common for drivers to reuse the device-tree node of a
parent (or other ancestor) device when creating class or bus devices
(e.g. gpio chips, i2c adapters, iio chips, spi masters, serdev, phys,
usb root hubs). But reusing a device-tree node may cause problems *if*
the new device is later probed as for example driver core would
currently attempt to reinitialise an already active associated pinmux
configuration.

[ NB: For most examples above this is currently not a problem as the
devices reusing a node are never probed. ]

Other potential issues include the platform-bus code unconditionally
dropping the device-tree-node reference in its device destructor,
reinitialisation of other bus-managed resources such as clocks, and
(possibly) the recently added DMA-setup in driver core.

Instead of having drivers try to work around this (as is currently done
for USB root hubs), we can allow devices to reuse a device-tree node by
setting a flag in their struct device that can be used by core, bus and
driver code to avoid resources from being over-allocated.

The first two patches fix a device-tree node reference leak for
non-root-hub devices in USB. These were submitted yesterday to the USB
list, but are included here for completeness.

The third and fourth patches add a helper that can be used when reusing
a device-tree node of another device and that specifically sets a new
of_node_reused flag which is then used by driver core to skip the
automatic pinctrl configuration during probe.

The fifth patch removes the pinctrl over-allocation workaround from USB
core, which also had some undesirable side-effects.

The final two patches fix a device-tree node imbalance and
use-after-free in an thermal driver, where a platform device was reusing
the device-tree node of its parent mfd during probe. This would also
prevent the child device from being reprobed (e.g. due to probe
deferral) if the parent node defines a pinctrl configuration.

Note that this series is against 4.12-rc3.

For reference, here is a list of relevant commits leading up to the
current situation:

 - [2013-01-22] ab78029ecc34 ("drivers/pinctrl: grab default handles from device core")
 - [2016-02-19] 69bec7259853 ("USB: core: let USB device know device node")
 - [2016-04-25] dc5878abf49c ("usb: core: move root hub's device node assignment after it is added to bus")
 - [2016-10-06] 51fa91475e43 ("usb/core: Added devspec sysfs entry for devices behind the usb hub")
 - [2017-03-13] a8c06e407ef9 ("usb: separate out sysdev pointer from usb_bus")
 - [2017-04-10] 09515ef5ddad ("of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices")

Johan


Johan Hovold (7):
  USB: core: fix device node leak
  USB: of: document reference taken by child-lookup helper
  driver core: add helper to reuse a device-tree node
  driver core: fix automatic pinctrl management
  USB: of: fix root-hub device-tree node handling
  thermal: max77620: fix device-node reference imbalance
  thermal: max77620: fix pinmux conflict on reprobe

 drivers/base/core.c                | 16 ++++++++++++++++
 drivers/base/pinctrl.c             |  3 +++
 drivers/thermal/max77620_thermal.c |  8 ++++++--
 drivers/usb/core/hcd.c             |  2 --
 drivers/usb/core/of.c              |  3 +++
 drivers/usb/core/usb.c             |  2 ++
 include/linux/device.h             |  2 ++
 7 files changed, 32 insertions(+), 4 deletions(-)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH 1/7] USB: core: fix device node leak
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-30 22:55   ` Tyrel Datwyler
  2017-06-05  3:35     ` Peter Chen
  2017-05-30 16:25 ` [PATCH 2/7] USB: of: document reference taken by child-lookup helper Johan Hovold
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold, stable, Peter Chen

Make sure to release any OF device-node reference taken when creating
the USB device.

Note that we currently do not hold a reference to the root hub
device-tree node (i.e. the parent controller node).

Fixes: 69bec7259853 ("USB: core: let USB device know device node")
Cc: stable <stable@vger.kernel.org>	# v4.6
Cc: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/core/usb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 28b053cacc90..62e1906bb2f3 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
 
 	usb_destroy_configuration(udev);
 	usb_release_bos_descriptor(udev);
+	if (udev->parent)
+		of_node_put(dev->of_node);
 	usb_put_hcd(hcd);
 	kfree(udev->product);
 	kfree(udev->manufacturer);
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 2/7] USB: of: document reference taken by child-lookup helper
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
  2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-30 22:40   ` Tyrel Datwyler
  2017-05-30 16:25 ` [PATCH 3/7] driver core: add helper to reuse a device-tree node Johan Hovold
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold

Document that the child-node lookup helper takes a reference to the
device-tree node which needs to be dropped after use.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/core/of.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index d563cbcf76cf..17a4af02cf5b 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -28,6 +28,9 @@
  *
  * Find the node from device tree according to its port number.
  *
+ * Takes a reference to the returned device-tree node, which needs to be
+ * dropped after use.
+ *
  * Return: On success, a pointer to the device node, %NULL on failure.
  */
 struct device_node *usb_of_get_child_node(struct device_node *parent,
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 3/7] driver core: add helper to reuse a device-tree node
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
  2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
  2017-05-30 16:25 ` [PATCH 2/7] USB: of: document reference taken by child-lookup helper Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-30 22:52     ` kbuild test robot
  2017-05-30 16:25 ` [PATCH 4/7] driver core: fix automatic pinctrl management Johan Hovold
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold

Add a helper function to be used when reusing the device-tree node of
another device.

It is fairly common for drivers to reuse the device-tree node of a
parent (or other ancestor) device when creating class or bus devices
(e.g. gpio chips, i2c adapters, iio chips, spi masters, serdev, phys,
usb root hubs). But reusing a device-tree node may cause problems if the
new device is later probed as for example driver core would currently
attempt to reinitialise an already active associated pinmux
configuration.

Other potential issues include the platform-bus code unconditionally
dropping the device-tree node reference in its device destructor,
reinitialisation of other bus-managed resources such as clocks, and the
recently added DMA-setup in driver core.

Note that for most examples above this is currently not an issue as the
devices are never probed, but this is a problem for the USB bus which
has recently gained device-tree support. This was discovered and
worked-around in a rather ad-hoc fashion by commit dc5878abf49c ("usb:
core: move root hub's device node assignment after it is added to bus")
by not setting the of_node pointer until after the root-hub device has
been registered.

Instead we can allow devices to reuse a device-tree node by setting a
flag in their struct device that can be used by core, bus and driver
code to avoid resources from being over-allocated.

Note that the helper also grabs an extra reference to the device node,
which specifically balances the unconditional put in the platform-device
destructor.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/base/core.c    | 16 ++++++++++++++++
 include/linux/device.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index bbecaf9293be..c3064ff09af5 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2884,3 +2884,19 @@ void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	else
 		dev->fwnode = fwnode;
 }
+
+/**
+ * device_set_of_node_from_dev - reuse device-tree node of another device
+ * @dev: device whose device-tree node is being set
+ * @dev2: device whose device-tree node is being reused
+ *
+ * Takes another reference to the new device-tree node after first dropping
+ * any reference held to the old node.
+ */
+void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
+{
+	of_node_put(dev->of_node);
+	dev->of_node = of_node_get(dev2->of_node);
+	dev->of_node_reused = true;
+}
+EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index 9ef518af5515..d7544bb558c3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -966,6 +966,7 @@ struct device {
 
 	bool			offline_disabled:1;
 	bool			offline:1;
+	bool			of_node_reused:1;
 };
 
 static inline struct device *kobj_to_dev(struct kobject *kobj)
@@ -1144,6 +1145,7 @@ extern int device_offline(struct device *dev);
 extern int device_online(struct device *dev);
 extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
 extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
+void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
 
 static inline int dev_num_vf(struct device *dev)
 {
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 4/7] driver core: fix automatic pinctrl management
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
                   ` (2 preceding siblings ...)
  2017-05-30 16:25 ` [PATCH 3/7] driver core: add helper to reuse a device-tree node Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-31  0:39     ` Linus Walleij
  2017-05-30 16:25 ` [PATCH 5/7] USB: of: fix root-hub device-tree node handling Johan Hovold
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold

Commit ab78029ecc34 ("drivers/pinctrl: grab default handles from device
core") added automatic pin-control management to driver core by looking
up and setting any default pinctrl state found in device tree while a
device is being probed.

This obviously runs into problems as soon as device-tree nodes are
reused for child devices which are later also probed as pins would
already have been claimed by the ancestor device.

For example if a USB host controller claims a pin, its root hub would
consequently fail to probe when its device-tree node is set to the node
of the controller:

    pinctrl-single 48002030.pinmux: pin PIN204 already requested by 48064800.ehci; cannot claim for usb1
    pinctrl-single 48002030.pinmux: pin-204 (usb1) status -22
    pinctrl-single 48002030.pinmux: could not request pin 204 (PIN204) from group usb_dbg_pins  on device pinctrl-single
    usb usb1: Error applying setting, reverse things back
    usb: probe of usb1 failed with error -22

Fix this by checking the new of_node_reused flag and skipping automatic
pinctrl configuration during probe if set.

Note that the flag is checked in driver core rather than in pinctrl
(e.g. in pinctrl_dt_to_map()) which would specifically have prevented
intentional use of a parent's pinctrl properties by a child device
(should such a need ever arise).

Fixes: ab78029ecc34 ("drivers/pinctrl: grab default handles from device core")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/base/pinctrl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c
index 5917b4b5fb99..eb929dd6ef1e 100644
--- a/drivers/base/pinctrl.c
+++ b/drivers/base/pinctrl.c
@@ -23,6 +23,9 @@ int pinctrl_bind_pins(struct device *dev)
 {
 	int ret;
 
+	if (dev->of_node_reused)
+		return 0;
+
 	dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL);
 	if (!dev->pins)
 		return -ENOMEM;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 5/7] USB: of: fix root-hub device-tree node handling
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
                   ` (3 preceding siblings ...)
  2017-05-30 16:25 ` [PATCH 4/7] driver core: fix automatic pinctrl management Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-06-05  4:51     ` Peter Chen
  2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
  2017-05-30 16:25 ` [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe Johan Hovold
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold

In an attempt to work around a pinmux over-allocation issue in driver
core, commit dc5878abf49c ("usb: core: move root hub's device node
assignment after it is added to bus") moved the device-tree node
assignment until after the root hub had been registered.

This not only makes the device-tree node unavailable to the usb driver
during probe, but also prevents the of_node from being linked to in
sysfs and causes a race with user-space for the (recently added) devspec
attribute.

Use the new device_set_of_node_from_dev() helper to reuse the node of
the sysdev device, something which now prevents driver core from trying
to reclaim any pinctrl pins during probe.

Fixes: dc5878abf49c ("usb: core: move root hub's device node assignment after it is added to bus")
Fixes: 51fa91475e43 ("usb/core: Added devspec sysfs entry for devices behind the usb hub")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/core/hcd.c | 2 --
 drivers/usb/core/usb.c | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 5dea98358c05..2cff59e9c268 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1076,7 +1076,6 @@ static void usb_deregister_bus (struct usb_bus *bus)
 static int register_root_hub(struct usb_hcd *hcd)
 {
 	struct device *parent_dev = hcd->self.controller;
-	struct device *sysdev = hcd->self.sysdev;
 	struct usb_device *usb_dev = hcd->self.root_hub;
 	const int devnum = 1;
 	int retval;
@@ -1123,7 +1122,6 @@ static int register_root_hub(struct usb_hcd *hcd)
 		/* Did the HC die before the root hub was registered? */
 		if (HCD_DEAD(hcd))
 			usb_hc_died (hcd);	/* This time clean up */
-		usb_dev->dev.of_node = sysdev->of_node;
 	}
 	mutex_unlock(&usb_bus_idr_lock);
 
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 62e1906bb2f3..17681d5638ac 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -416,8 +416,7 @@ static void usb_release_dev(struct device *dev)
 
 	usb_destroy_configuration(udev);
 	usb_release_bos_descriptor(udev);
-	if (udev->parent)
-		of_node_put(dev->of_node);
+	of_node_put(dev->of_node);
 	usb_put_hcd(hcd);
 	kfree(udev->product);
 	kfree(udev->manufacturer);
@@ -616,6 +615,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
 		dev->route = 0;
 
 		dev->dev.parent = bus->controller;
+		device_set_of_node_from_dev(&dev->dev, bus->sysdev);
 		dev_set_name(&dev->dev, "usb%d", bus->busnum);
 		root_hub = 1;
 	} else {
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
                   ` (4 preceding siblings ...)
  2017-05-30 16:25 ` [PATCH 5/7] USB: of: fix root-hub device-tree node handling Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-30 22:59   ` Tyrel Datwyler
  2017-05-30 16:25 ` [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe Johan Hovold
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold, stable, Laxman Dewangan

The thermal child device reuses the parent MFD-device device-tree node
when registering a thermal zone, but did not take a reference to the
node.

This leads to a reference imbalance, and potential use-after-free, when
the node reference is dropped by the platform-bus device destructor
(once for the child and later again for the parent).

Fix this by dropping any reference already held to a device-tree node
and getting a reference to the parent's node which will be balanced on
reprobe or on platform-device release, whichever comes first.

Note that simply clearing the of_node pointer on probe errors and on
driver unbind would not allow the use of device-managed resources as
specifically thermal_zone_of_sensor_unregister() claims that a valid
device-tree node pointer is needed during deregistration (even if it
currently does not seem to use it).

Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
Cc: stable <stable@vger.kernel.org>     # 4.9
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/thermal/max77620_thermal.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
index e9a1fe342760..71d35f3c9215 100644
--- a/drivers/thermal/max77620_thermal.c
+++ b/drivers/thermal/max77620_thermal.c
@@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	pdev->dev.of_node = pdev->dev.parent->of_node;
-
 	mtherm->dev = &pdev->dev;
 	mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
 	if (!mtherm->rmap) {
@@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	/*
+	 * Drop any current reference to a device-tree node and get a
+	 * reference to the parent's node which will be balanced on reprobe or
+	 * on platform-device release.
+	 */
+	of_node_put(pdev->dev.of_node);
+	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
+
 	mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
 				mtherm, &max77620_thermal_ops);
 	if (IS_ERR(mtherm->tz_device)) {
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe
  2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
                   ` (5 preceding siblings ...)
  2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
  2017-05-30 18:57     ` Eduardo Valentin
  6 siblings, 1 reply; 31+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, Johan Hovold, Laxman Dewangan

Use the new helper for reusing a device-tree node of another device
instead of managing the node references explicitly.

This also makes sure that the new of_node_reuse flag is set if the
device is ever reprobed, something which specifically now avoids driver
core from attempting to claim any pinmux resources already claimed by
the parent device.

Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/thermal/max77620_thermal.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
index 71d35f3c9215..159bbcee8821 100644
--- a/drivers/thermal/max77620_thermal.c
+++ b/drivers/thermal/max77620_thermal.c
@@ -112,12 +112,10 @@ static int max77620_thermal_probe(struct platform_device *pdev)
 	}
 
 	/*
-	 * Drop any current reference to a device-tree node and get a
-	 * reference to the parent's node which will be balanced on reprobe or
-	 * on platform-device release.
+	 * The reference taken to the parent's node which will be balanced on
+	 * reprobe or on platform-device release.
 	 */
-	of_node_put(pdev->dev.of_node);
-	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
+	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
 
 	mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
 				mtherm, &max77620_thermal_ops);
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe
  2017-05-30 16:25 ` [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe Johan Hovold
@ 2017-05-30 18:57     ` Eduardo Valentin
  0 siblings, 0 replies; 31+ messages in thread
From: Eduardo Valentin @ 2017-05-30 18:57 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel, Laxman Dewangan

On Tue, May 30, 2017 at 06:25:54PM +0200, Johan Hovold wrote:
> Use the new helper for reusing a device-tree node of another device
> instead of managing the node references explicitly.
> 
> This also makes sure that the new of_node_reuse flag is set if the
> device is ever reprobed, something which specifically now avoids driver
> core from attempting to claim any pinmux resources already claimed by
> the parent device.
> 
> Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/thermal/max77620_thermal.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> index 71d35f3c9215..159bbcee8821 100644
> --- a/drivers/thermal/max77620_thermal.c
> +++ b/drivers/thermal/max77620_thermal.c
> @@ -112,12 +112,10 @@ static int max77620_thermal_probe(struct platform_device *pdev)
>  	}
>  
>  	/*
> -	 * Drop any current reference to a device-tree node and get a
> -	 * reference to the parent's node which will be balanced on reprobe or
> -	 * on platform-device release.
> +	 * The reference taken to the parent's node which will be balanced on
> +	 * reprobe or on platform-device release.
>  	 */
> -	of_node_put(pdev->dev.of_node);
> -	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> +	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);

Should this one be squashed with patch 6/7?

>  
>  	mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
>  				mtherm, &max77620_thermal_ops);
> -- 
> 2.13.0
> 
> 

-- 
All the best,
Eduardo Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe
@ 2017-05-30 18:57     ` Eduardo Valentin
  0 siblings, 0 replies; 31+ messages in thread
From: Eduardo Valentin @ 2017-05-30 18:57 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel, Laxman Dewangan

On Tue, May 30, 2017 at 06:25:54PM +0200, Johan Hovold wrote:
> Use the new helper for reusing a device-tree node of another device
> instead of managing the node references explicitly.
> 
> This also makes sure that the new of_node_reuse flag is set if the
> device is ever reprobed, something which specifically now avoids driver
> core from attempting to claim any pinmux resources already claimed by
> the parent device.
> 
> Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/thermal/max77620_thermal.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> index 71d35f3c9215..159bbcee8821 100644
> --- a/drivers/thermal/max77620_thermal.c
> +++ b/drivers/thermal/max77620_thermal.c
> @@ -112,12 +112,10 @@ static int max77620_thermal_probe(struct platform_device *pdev)
>  	}
>  
>  	/*
> -	 * Drop any current reference to a device-tree node and get a
> -	 * reference to the parent's node which will be balanced on reprobe or
> -	 * on platform-device release.
> +	 * The reference taken to the parent's node which will be balanced on
> +	 * reprobe or on platform-device release.
>  	 */
> -	of_node_put(pdev->dev.of_node);
> -	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> +	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);

Should this one be squashed with patch 6/7?

>  
>  	mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
>  				mtherm, &max77620_thermal_ops);
> -- 
> 2.13.0
> 
> 

-- 
All the best,
Eduardo Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/7] USB: of: document reference taken by child-lookup helper
  2017-05-30 16:25 ` [PATCH 2/7] USB: of: document reference taken by child-lookup helper Johan Hovold
@ 2017-05-30 22:40   ` Tyrel Datwyler
  2017-06-06 15:38     ` Johan Hovold
  0 siblings, 1 reply; 31+ messages in thread
From: Tyrel Datwyler @ 2017-05-30 22:40 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel

On 05/30/2017 09:25 AM, Johan Hovold wrote:
> Document that the child-node lookup helper takes a reference to the
> device-tree node which needs to be dropped after use.
> 
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/of.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index d563cbcf76cf..17a4af02cf5b 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -28,6 +28,9 @@
>   *
>   * Find the node from device tree according to its port number.
>   *
> + * Takes a reference to the returned device-tree node, which needs to be
> + * dropped after use.
> + *
>   * Return: On success, a pointer to the device node, %NULL on failure.

I would use the same blurb used throughout drivers/of/* for consistency.

 *      Returns a node pointer with refcount incremented, use
 *      of_node_put() on it when done.
 */

Just my 2-cents

-Tyrel

>   */
>  struct device_node *usb_of_get_child_node(struct device_node *parent,
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 3/7] driver core: add helper to reuse a device-tree node
  2017-05-30 16:25 ` [PATCH 3/7] driver core: add helper to reuse a device-tree node Johan Hovold
@ 2017-05-30 22:52     ` kbuild test robot
  0 siblings, 0 replies; 31+ messages in thread
From: kbuild test robot @ 2017-05-30 22:52 UTC (permalink / raw)
  To: Johan Hovold
  Cc: kbuild-all, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel,
	Johan Hovold

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

Hi Johan,

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v4.12-rc3 next-20170530]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Johan-Hovold/driver-core-USB-thermal-fix-device-tree-node-reuse/20170531-043026
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   WARNING: convert(1) not found, for SVG to PDF conversion install ImageMagick (https://www.imagemagick.org)
   arch/x86/include/asm/uaccess_32.h:1: warning: no structured comments found
   include/linux/init.h:1: warning: no structured comments found
   include/linux/mod_devicetable.h:686: warning: Excess struct/union/enum/typedef member 'ver_major' description in 'fsl_mc_device_id'
   include/linux/mod_devicetable.h:686: warning: Excess struct/union/enum/typedef member 'ver_minor' description in 'fsl_mc_device_id'
   kernel/sched/core.c:2088: warning: No description found for parameter 'rf'
   kernel/sched/core.c:2088: warning: Excess function parameter 'cookie' description in 'try_to_wake_up_local'
   include/linux/kthread.h:26: warning: Excess function parameter '...' description in 'kthread_create'
   kernel/sys.c:1: warning: no structured comments found
   include/linux/device.h:970: warning: No description found for parameter 'dma_ops'
>> include/linux/device.h:970: warning: No description found for parameter 'of_node_reused'
   drivers/dma-buf/seqno-fence.c:1: warning: no structured comments found
   include/linux/iio/iio.h:597: warning: No description found for parameter 'trig_readonly'
   include/linux/iio/trigger.h:151: warning: No description found for parameter 'indio_dev'
   include/linux/iio/trigger.h:151: warning: No description found for parameter 'trig'
   include/linux/device.h:971: warning: No description found for parameter 'dma_ops'
   include/linux/device.h:971: warning: No description found for parameter 'of_node_reused'
   include/linux/usb/gadget.h:230: warning: No description found for parameter 'claimed'
   include/linux/usb/gadget.h:230: warning: No description found for parameter 'enabled'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_altset_not_supp'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_stall_not_supp'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_zlp_not_supp'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'set_busid'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_handler'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_preinstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_postinstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_uninstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'debugfs_init'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_open_object'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_close_object'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'prime_handle_to_fd'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'prime_fd_to_handle'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_export'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_import'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_pin'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_unpin'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_res_obj'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_get_sg_table'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_import_sg_table'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_vmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_vunmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_mmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_vm_ops'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'major'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'minor'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'patchlevel'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'name'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'desc'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'date'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'driver_features'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'ioctls'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'num_ioctls'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'fops'
   include/drm/drm_color_mgmt.h:1: warning: no structured comments found
   drivers/gpu/drm/drm_plane_helper.c:403: warning: No description found for parameter 'ctx'
   drivers/gpu/drm/drm_plane_helper.c:404: warning: No description found for parameter 'ctx'
   drivers/gpu/drm/i915/intel_lpe_audio.c:355: warning: No description found for parameter 'dp_output'
   drivers/gpu/drm/i915/intel_lpe_audio.c:355: warning: No description found for parameter 'link_rate'
   drivers/gpu/drm/i915/intel_lpe_audio.c:356: warning: No description found for parameter 'dp_output'
   drivers/gpu/drm/i915/intel_lpe_audio.c:356: warning: No description found for parameter 'link_rate'
   Documentation/core-api/assoc_array.rst:13: WARNING: Enumerated list ends without a blank line; unexpected unindent.
   Documentation/doc-guide/sphinx.rst:126: ERROR: Unknown target name: "sphinx c domain".
   kernel/sched/fair.c:7650: WARNING: Inline emphasis start-string without end-string.
   kernel/time/timer.c:1200: ERROR: Unexpected indentation.
   kernel/time/timer.c:1202: ERROR: Unexpected indentation.
   kernel/time/timer.c:1203: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/wait.h:122: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/wait.h:125: ERROR: Unexpected indentation.
   include/linux/wait.h:127: WARNING: Block quote ends without a blank line; unexpected unindent.
   kernel/time/hrtimer.c:990: WARNING: Block quote ends without a blank line; unexpected unindent.
   kernel/signal.c:322: WARNING: Inline literal start-string without end-string.
   include/linux/iio/iio.h:219: ERROR: Unexpected indentation.
   include/linux/iio/iio.h:220: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/iio/iio.h:226: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/iio/industrialio-core.c:638: ERROR: Unknown target name: "iio_val".
   drivers/iio/industrialio-core.c:645: ERROR: Unknown target name: "iio_val".
   drivers/message/fusion/mptbase.c:5051: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/tty/serial/serial_core.c:1898: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/pci/pci.c:3456: ERROR: Unexpected indentation.
   include/linux/regulator/driver.h:271: ERROR: Unknown target name: "regulator_regmap_x_voltage".
   include/linux/spi/spi.h:370: ERROR: Unexpected indentation.
   drivers/gpu/drm/drm_scdc_helper.c:203: ERROR: Unexpected indentation.
   drivers/gpu/drm/drm_scdc_helper.c:204: WARNING: Block quote ends without a blank line; unexpected unindent.
   drivers/gpu/drm/drm_ioctl.c:690: WARNING: Definition list ends without a blank line; unexpected unindent.
   Documentation/gpu/todo.rst:111: ERROR: Unknown target name: "drm_fb".
   sound/soc/soc-core.c:2670: ERROR: Unknown target name: "snd_soc_daifmt".
   sound/core/jack.c:312: ERROR: Unknown target name: "snd_jack_btn".
   Documentation/userspace-api/unshare.rst:108: WARNING: Inline emphasis start-string without end-string.
   Documentation/usb/typec.rst:: WARNING: document isn't included in any toctree
   Documentation/usb/usb3-debug-port.rst:: WARNING: document isn't included in any toctree
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 56: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 69: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 82: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 96: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 109: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 122: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 133: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 164: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 193: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 56: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 69: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 82: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 96: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 109: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 122: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 133: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 164: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 193: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected

vim +/of_node_reused +970 include/linux/device.h

ca22e56d Kay Sievers        2011-12-14  954  	u32			id;	/* device instance */
929d2fa5 Matthew Wilcox     2008-10-16  955  
9ac7849e Tejun Heo          2007-01-20  956  	spinlock_t		devres_lock;
9ac7849e Tejun Heo          2007-01-20  957  	struct list_head	devres_head;
9ac7849e Tejun Heo          2007-01-20  958  
5a3ceb86 Tejun Heo          2008-08-25  959  	struct klist_node	knode_class;
b7a3e813 Kay Sievers        2006-10-07  960  	struct class		*class;
a4dbd674 David Brownell     2009-06-24  961  	const struct attribute_group **groups;	/* optional groups */
23681e47 Greg Kroah-Hartman 2006-06-14  962  
^1da177e Linus Torvalds     2005-04-16  963  	void	(*release)(struct device *dev);
74416e1e Alex Williamson    2012-05-30  964  	struct iommu_group	*iommu_group;
57f98d2f Robin Murphy       2016-09-13  965  	struct iommu_fwspec	*iommu_fwspec;
4f3549d7 Rafael J. Wysocki  2013-05-02  966  
4f3549d7 Rafael J. Wysocki  2013-05-02  967  	bool			offline_disabled:1;
4f3549d7 Rafael J. Wysocki  2013-05-02  968  	bool			offline:1;
aceb1c08 Johan Hovold       2017-05-30  969  	bool			of_node_reused:1;
^1da177e Linus Torvalds     2005-04-16 @970  };
^1da177e Linus Torvalds     2005-04-16  971  
a4232963 Lars-Peter Clausen 2012-07-03  972  static inline struct device *kobj_to_dev(struct kobject *kobj)
a4232963 Lars-Peter Clausen 2012-07-03  973  {
a4232963 Lars-Peter Clausen 2012-07-03  974  	return container_of(kobj, struct device, kobj);
a4232963 Lars-Peter Clausen 2012-07-03  975  }
a4232963 Lars-Peter Clausen 2012-07-03  976  
9a3df1f7 Alan Stern         2008-03-19  977  /* Get the wakeup routines, which depend on struct device */
9a3df1f7 Alan Stern         2008-03-19  978  #include <linux/pm_wakeup.h>

:::::: The code at line 970 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6634 bytes --]

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 3/7] driver core: add helper to reuse a device-tree node
@ 2017-05-30 22:52     ` kbuild test robot
  0 siblings, 0 replies; 31+ messages in thread
From: kbuild test robot @ 2017-05-30 22:52 UTC (permalink / raw)
  Cc: kbuild-all, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel,
	Johan Hovold

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

Hi Johan,

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v4.12-rc3 next-20170530]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Johan-Hovold/driver-core-USB-thermal-fix-device-tree-node-reuse/20170531-043026
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   WARNING: convert(1) not found, for SVG to PDF conversion install ImageMagick (https://www.imagemagick.org)
   arch/x86/include/asm/uaccess_32.h:1: warning: no structured comments found
   include/linux/init.h:1: warning: no structured comments found
   include/linux/mod_devicetable.h:686: warning: Excess struct/union/enum/typedef member 'ver_major' description in 'fsl_mc_device_id'
   include/linux/mod_devicetable.h:686: warning: Excess struct/union/enum/typedef member 'ver_minor' description in 'fsl_mc_device_id'
   kernel/sched/core.c:2088: warning: No description found for parameter 'rf'
   kernel/sched/core.c:2088: warning: Excess function parameter 'cookie' description in 'try_to_wake_up_local'
   include/linux/kthread.h:26: warning: Excess function parameter '...' description in 'kthread_create'
   kernel/sys.c:1: warning: no structured comments found
   include/linux/device.h:970: warning: No description found for parameter 'dma_ops'
>> include/linux/device.h:970: warning: No description found for parameter 'of_node_reused'
   drivers/dma-buf/seqno-fence.c:1: warning: no structured comments found
   include/linux/iio/iio.h:597: warning: No description found for parameter 'trig_readonly'
   include/linux/iio/trigger.h:151: warning: No description found for parameter 'indio_dev'
   include/linux/iio/trigger.h:151: warning: No description found for parameter 'trig'
   include/linux/device.h:971: warning: No description found for parameter 'dma_ops'
   include/linux/device.h:971: warning: No description found for parameter 'of_node_reused'
   include/linux/usb/gadget.h:230: warning: No description found for parameter 'claimed'
   include/linux/usb/gadget.h:230: warning: No description found for parameter 'enabled'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_altset_not_supp'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_stall_not_supp'
   include/linux/usb/gadget.h:408: warning: No description found for parameter 'quirk_zlp_not_supp'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'set_busid'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_handler'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_preinstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_postinstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'irq_uninstall'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'debugfs_init'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_open_object'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_close_object'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'prime_handle_to_fd'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'prime_fd_to_handle'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_export'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_import'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_pin'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_unpin'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_res_obj'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_get_sg_table'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_import_sg_table'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_vmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_vunmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_prime_mmap'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'gem_vm_ops'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'major'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'minor'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'patchlevel'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'name'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'desc'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'date'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'driver_features'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'ioctls'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'num_ioctls'
   include/drm/drm_drv.h:524: warning: No description found for parameter 'fops'
   include/drm/drm_color_mgmt.h:1: warning: no structured comments found
   drivers/gpu/drm/drm_plane_helper.c:403: warning: No description found for parameter 'ctx'
   drivers/gpu/drm/drm_plane_helper.c:404: warning: No description found for parameter 'ctx'
   drivers/gpu/drm/i915/intel_lpe_audio.c:355: warning: No description found for parameter 'dp_output'
   drivers/gpu/drm/i915/intel_lpe_audio.c:355: warning: No description found for parameter 'link_rate'
   drivers/gpu/drm/i915/intel_lpe_audio.c:356: warning: No description found for parameter 'dp_output'
   drivers/gpu/drm/i915/intel_lpe_audio.c:356: warning: No description found for parameter 'link_rate'
   Documentation/core-api/assoc_array.rst:13: WARNING: Enumerated list ends without a blank line; unexpected unindent.
   Documentation/doc-guide/sphinx.rst:126: ERROR: Unknown target name: "sphinx c domain".
   kernel/sched/fair.c:7650: WARNING: Inline emphasis start-string without end-string.
   kernel/time/timer.c:1200: ERROR: Unexpected indentation.
   kernel/time/timer.c:1202: ERROR: Unexpected indentation.
   kernel/time/timer.c:1203: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/wait.h:122: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/wait.h:125: ERROR: Unexpected indentation.
   include/linux/wait.h:127: WARNING: Block quote ends without a blank line; unexpected unindent.
   kernel/time/hrtimer.c:990: WARNING: Block quote ends without a blank line; unexpected unindent.
   kernel/signal.c:322: WARNING: Inline literal start-string without end-string.
   include/linux/iio/iio.h:219: ERROR: Unexpected indentation.
   include/linux/iio/iio.h:220: WARNING: Block quote ends without a blank line; unexpected unindent.
   include/linux/iio/iio.h:226: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/iio/industrialio-core.c:638: ERROR: Unknown target name: "iio_val".
   drivers/iio/industrialio-core.c:645: ERROR: Unknown target name: "iio_val".
   drivers/message/fusion/mptbase.c:5051: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/tty/serial/serial_core.c:1898: WARNING: Definition list ends without a blank line; unexpected unindent.
   drivers/pci/pci.c:3456: ERROR: Unexpected indentation.
   include/linux/regulator/driver.h:271: ERROR: Unknown target name: "regulator_regmap_x_voltage".
   include/linux/spi/spi.h:370: ERROR: Unexpected indentation.
   drivers/gpu/drm/drm_scdc_helper.c:203: ERROR: Unexpected indentation.
   drivers/gpu/drm/drm_scdc_helper.c:204: WARNING: Block quote ends without a blank line; unexpected unindent.
   drivers/gpu/drm/drm_ioctl.c:690: WARNING: Definition list ends without a blank line; unexpected unindent.
   Documentation/gpu/todo.rst:111: ERROR: Unknown target name: "drm_fb".
   sound/soc/soc-core.c:2670: ERROR: Unknown target name: "snd_soc_daifmt".
   sound/core/jack.c:312: ERROR: Unknown target name: "snd_jack_btn".
   Documentation/userspace-api/unshare.rst:108: WARNING: Inline emphasis start-string without end-string.
   Documentation/usb/typec.rst:: WARNING: document isn't included in any toctree
   Documentation/usb/usb3-debug-port.rst:: WARNING: document isn't included in any toctree
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 56: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 69: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 82: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 96: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 109: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 122: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 133: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 164: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 193: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 56: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 69: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 82: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 96: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 109: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 122: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 133: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 164: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "~/.fonts.conf", line 193: Having multiple values in <test> isn't supported and may not work as expected
   Fontconfig warning: "/home/kbuild/.config/fontconfig/fonts.conf", line 43: Having multiple values in <test> isn't supported and may not work as expected

vim +/of_node_reused +970 include/linux/device.h

ca22e56d Kay Sievers        2011-12-14  954  	u32			id;	/* device instance */
929d2fa5 Matthew Wilcox     2008-10-16  955  
9ac7849e Tejun Heo          2007-01-20  956  	spinlock_t		devres_lock;
9ac7849e Tejun Heo          2007-01-20  957  	struct list_head	devres_head;
9ac7849e Tejun Heo          2007-01-20  958  
5a3ceb86 Tejun Heo          2008-08-25  959  	struct klist_node	knode_class;
b7a3e813 Kay Sievers        2006-10-07  960  	struct class		*class;
a4dbd674 David Brownell     2009-06-24  961  	const struct attribute_group **groups;	/* optional groups */
23681e47 Greg Kroah-Hartman 2006-06-14  962  
^1da177e Linus Torvalds     2005-04-16  963  	void	(*release)(struct device *dev);
74416e1e Alex Williamson    2012-05-30  964  	struct iommu_group	*iommu_group;
57f98d2f Robin Murphy       2016-09-13  965  	struct iommu_fwspec	*iommu_fwspec;
4f3549d7 Rafael J. Wysocki  2013-05-02  966  
4f3549d7 Rafael J. Wysocki  2013-05-02  967  	bool			offline_disabled:1;
4f3549d7 Rafael J. Wysocki  2013-05-02  968  	bool			offline:1;
aceb1c08 Johan Hovold       2017-05-30  969  	bool			of_node_reused:1;
^1da177e Linus Torvalds     2005-04-16 @970  };
^1da177e Linus Torvalds     2005-04-16  971  
a4232963 Lars-Peter Clausen 2012-07-03  972  static inline struct device *kobj_to_dev(struct kobject *kobj)
a4232963 Lars-Peter Clausen 2012-07-03  973  {
a4232963 Lars-Peter Clausen 2012-07-03  974  	return container_of(kobj, struct device, kobj);
a4232963 Lars-Peter Clausen 2012-07-03  975  }
a4232963 Lars-Peter Clausen 2012-07-03  976  
9a3df1f7 Alan Stern         2008-03-19  977  /* Get the wakeup routines, which depend on struct device */
9a3df1f7 Alan Stern         2008-03-19  978  #include <linux/pm_wakeup.h>

:::::: The code at line 970 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6634 bytes --]

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/7] USB: core: fix device node leak
  2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
@ 2017-05-30 22:55   ` Tyrel Datwyler
  2017-05-31  8:25       ` Johan Hovold
  2017-06-05  3:35     ` Peter Chen
  1 sibling, 1 reply; 31+ messages in thread
From: Tyrel Datwyler @ 2017-05-30 22:55 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, stable, Peter Chen

On 05/30/2017 09:25 AM, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
> 
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
> 
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org>	# v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/usb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> +	if (udev->parent)
> +		of_node_put(dev->of_node);

If I'm following the root hub doesn't hold an of_node reference, so does that guarantee
that dev->of_node is NULL for the root hub? If so of_node_put() is safely called with a
NULL reference, making the if(udev->parent) unnecessary, and further no need to remove it
in follow-up patch #5.

-Tyrel

>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
  2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
@ 2017-05-30 22:59   ` Tyrel Datwyler
  2017-05-31  8:28     ` Johan Hovold
  0 siblings, 1 reply; 31+ messages in thread
From: Tyrel Datwyler @ 2017-05-30 22:59 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman
  Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel, stable, Laxman Dewangan

On 05/30/2017 09:25 AM, Johan Hovold wrote:
> The thermal child device reuses the parent MFD-device device-tree node
> when registering a thermal zone, but did not take a reference to the
> node.
> 
> This leads to a reference imbalance, and potential use-after-free, when
> the node reference is dropped by the platform-bus device destructor
> (once for the child and later again for the parent).
> 
> Fix this by dropping any reference already held to a device-tree node
> and getting a reference to the parent's node which will be balanced on
> reprobe or on platform-device release, whichever comes first.
> 
> Note that simply clearing the of_node pointer on probe errors and on
> driver unbind would not allow the use of device-managed resources as
> specifically thermal_zone_of_sensor_unregister() claims that a valid
> device-tree node pointer is needed during deregistration (even if it
> currently does not seem to use it).
> 
> Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> Cc: stable <stable@vger.kernel.org>     # 4.9
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/thermal/max77620_thermal.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> index e9a1fe342760..71d35f3c9215 100644
> --- a/drivers/thermal/max77620_thermal.c
> +++ b/drivers/thermal/max77620_thermal.c
> @@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	pdev->dev.of_node = pdev->dev.parent->of_node;
> -
>  	mtherm->dev = &pdev->dev;
>  	mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
>  	if (!mtherm->rmap) {
> @@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> +	/*
> +	 * Drop any current reference to a device-tree node and get a
> +	 * reference to the parent's node which will be balanced on reprobe or
> +	 * on platform-device release.
> +	 */
> +	of_node_put(pdev->dev.of_node);
> +	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> +

This seems like needless churn. Can't this just be squashed into patch #7?

-Tyrel

>  	mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
>  				mtherm, &max77620_thermal_ops);
>  	if (IS_ERR(mtherm->tz_device)) {
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 4/7] driver core: fix automatic pinctrl management
@ 2017-05-31  0:39     ` Linus Walleij
  0 siblings, 0 replies; 31+ messages in thread
From: Linus Walleij @ 2017-05-31  0:39 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
	linux-kernel

On Tue, May 30, 2017 at 6:25 PM, Johan Hovold <johan@kernel.org> wrote:

> Commit ab78029ecc34 ("drivers/pinctrl: grab default handles from device
> core") added automatic pin-control management to driver core by looking
> up and setting any default pinctrl state found in device tree while a
> device is being probed.

Actually we do not just support device tree, but also passing pin control
states from board files. It is handled by the core all the same.
So it's not a device tree thing.

One of those days we will have ACPI passing state tables too...

But I understand what you mean.

> Fix this by checking the new of_node_reused flag and skipping automatic
> pinctrl configuration during probe if set.

Seems like a solid idea. I hope we don't need another quirk for ACPI.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 4/7] driver core: fix automatic pinctrl management
@ 2017-05-31  0:39     ` Linus Walleij
  0 siblings, 0 replies; 31+ messages in thread
From: Linus Walleij @ 2017-05-31  0:39 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tue, May 30, 2017 at 6:25 PM, Johan Hovold <johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:

> Commit ab78029ecc34 ("drivers/pinctrl: grab default handles from device
> core") added automatic pin-control management to driver core by looking
> up and setting any default pinctrl state found in device tree while a
> device is being probed.

Actually we do not just support device tree, but also passing pin control
states from board files. It is handled by the core all the same.
So it's not a device tree thing.

One of those days we will have ACPI passing state tables too...

But I understand what you mean.

> Fix this by checking the new of_node_reused flag and skipping automatic
> pinctrl configuration during probe if set.

Seems like a solid idea. I hope we don't need another quirk for ACPI.
Acked-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe
  2017-05-30 18:57     ` Eduardo Valentin
  (?)
@ 2017-05-31  8:23     ` Johan Hovold
  -1 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:23 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel,
	Laxman Dewangan

On Tue, May 30, 2017 at 11:57:07AM -0700, Eduardo Valentin wrote:
> On Tue, May 30, 2017 at 06:25:54PM +0200, Johan Hovold wrote:
> > Use the new helper for reusing a device-tree node of another device
> > instead of managing the node references explicitly.
> > 
> > This also makes sure that the new of_node_reuse flag is set if the
> > device is ever reprobed, something which specifically now avoids driver
> > core from attempting to claim any pinmux resources already claimed by
> > the parent device.
> > 
> > Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> > Cc: Laxman Dewangan <ldewangan@nvidia.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/thermal/max77620_thermal.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> > index 71d35f3c9215..159bbcee8821 100644
> > --- a/drivers/thermal/max77620_thermal.c
> > +++ b/drivers/thermal/max77620_thermal.c
> > @@ -112,12 +112,10 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> >  	}
> >  
> >  	/*
> > -	 * Drop any current reference to a device-tree node and get a
> > -	 * reference to the parent's node which will be balanced on reprobe or
> > -	 * on platform-device release.
> > +	 * The reference taken to the parent's node which will be balanced on
> > +	 * reprobe or on platform-device release.
> >  	 */
> > -	of_node_put(pdev->dev.of_node);
> > -	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> > +	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
> 
> Should this one be squashed with patch 6/7?

I separated the two fixes this way as 6/7 does not depend on the rest of
the series and could be backported to stable, while this one fixes
something that has never worked (e.g. deferred probe of the thermal
child when the parent has a pinctrl configuration) and therefore is not
stable material.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/7] USB: core: fix device node leak
@ 2017-05-31  8:25       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:25 UTC (permalink / raw)
  To: Tyrel Datwyler
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel, stable,
	Peter Chen

On Tue, May 30, 2017 at 03:55:56PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > Make sure to release any OF device-node reference taken when creating
> > the USB device.
> > 
> > Note that we currently do not hold a reference to the root hub
> > device-tree node (i.e. the parent controller node).
> > 
> > Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> > Cc: stable <stable@vger.kernel.org>	# v4.6
> > Cc: Peter Chen <peter.chen@nxp.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/usb/core/usb.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> > index 28b053cacc90..62e1906bb2f3 100644
> > --- a/drivers/usb/core/usb.c
> > +++ b/drivers/usb/core/usb.c
> > @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
> >  
> >  	usb_destroy_configuration(udev);
> >  	usb_release_bos_descriptor(udev);
> > +	if (udev->parent)
> > +		of_node_put(dev->of_node);
> 
> If I'm following the root hub doesn't hold an of_node reference, so
> does that guarantee that dev->of_node is NULL for the root hub?

No, it may be non-NULL.

> If so of_node_put() is safely called with a NULL reference, making the
> if(udev->parent) unnecessary, and further no need to remove it in
> follow-up patch #5.

So this one is still needed.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/7] USB: core: fix device node leak
@ 2017-05-31  8:25       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:25 UTC (permalink / raw)
  To: Tyrel Datwyler
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, stable, Peter Chen

On Tue, May 30, 2017 at 03:55:56PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > Make sure to release any OF device-node reference taken when creating
> > the USB device.
> > 
> > Note that we currently do not hold a reference to the root hub
> > device-tree node (i.e. the parent controller node).
> > 
> > Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> > Cc: stable <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>	# v4.6
> > Cc: Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>
> > Signed-off-by: Johan Hovold <johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > ---
> >  drivers/usb/core/usb.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> > index 28b053cacc90..62e1906bb2f3 100644
> > --- a/drivers/usb/core/usb.c
> > +++ b/drivers/usb/core/usb.c
> > @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
> >  
> >  	usb_destroy_configuration(udev);
> >  	usb_release_bos_descriptor(udev);
> > +	if (udev->parent)
> > +		of_node_put(dev->of_node);
> 
> If I'm following the root hub doesn't hold an of_node reference, so
> does that guarantee that dev->of_node is NULL for the root hub?

No, it may be non-NULL.

> If so of_node_put() is safely called with a NULL reference, making the
> if(udev->parent) unnecessary, and further no need to remove it in
> follow-up patch #5.

So this one is still needed.

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
  2017-05-30 22:59   ` Tyrel Datwyler
@ 2017-05-31  8:28     ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:28 UTC (permalink / raw)
  To: Tyrel Datwyler
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel, stable,
	Laxman Dewangan

On Tue, May 30, 2017 at 03:59:10PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > The thermal child device reuses the parent MFD-device device-tree node
> > when registering a thermal zone, but did not take a reference to the
> > node.
> > 
> > This leads to a reference imbalance, and potential use-after-free, when
> > the node reference is dropped by the platform-bus device destructor
> > (once for the child and later again for the parent).
> > 
> > Fix this by dropping any reference already held to a device-tree node
> > and getting a reference to the parent's node which will be balanced on
> > reprobe or on platform-device release, whichever comes first.
> > 
> > Note that simply clearing the of_node pointer on probe errors and on
> > driver unbind would not allow the use of device-managed resources as
> > specifically thermal_zone_of_sensor_unregister() claims that a valid
> > device-tree node pointer is needed during deregistration (even if it
> > currently does not seem to use it).
> > 
> > Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> > Cc: stable <stable@vger.kernel.org>     # 4.9
> > Cc: Laxman Dewangan <ldewangan@nvidia.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/thermal/max77620_thermal.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> > index e9a1fe342760..71d35f3c9215 100644
> > --- a/drivers/thermal/max77620_thermal.c
> > +++ b/drivers/thermal/max77620_thermal.c
> > @@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> >  		return -EINVAL;
> >  	}
> >  
> > -	pdev->dev.of_node = pdev->dev.parent->of_node;
> > -
> >  	mtherm->dev = &pdev->dev;
> >  	mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
> >  	if (!mtherm->rmap) {
> > @@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> >  		return -ENODEV;
> >  	}
> >  
> > +	/*
> > +	 * Drop any current reference to a device-tree node and get a
> > +	 * reference to the parent's node which will be balanced on reprobe or
> > +	 * on platform-device release.
> > +	 */
> > +	of_node_put(pdev->dev.of_node);
> > +	pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> > +
> 
> This seems like needless churn. Can't this just be squashed into patch
> #7?

As I just replied to Eduardo, I'm fixing two separate issues here of
which this one might qualify for stable while the other (7/7) does not.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 4/7] driver core: fix automatic pinctrl management
@ 2017-05-31  8:35       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:35 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Johan Hovold, Greg Kroah-Hartman, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel

On Wed, May 31, 2017 at 02:39:28AM +0200, Linus Walleij wrote:
> On Tue, May 30, 2017 at 6:25 PM, Johan Hovold <johan@kernel.org> wrote:
> 
> > Commit ab78029ecc34 ("drivers/pinctrl: grab default handles from device
> > core") added automatic pin-control management to driver core by looking
> > up and setting any default pinctrl state found in device tree while a
> > device is being probed.
> 
> Actually we do not just support device tree, but also passing pin control
> states from board files. It is handled by the core all the same.
> So it's not a device tree thing.
> 
> One of those days we will have ACPI passing state tables too...
> 
> But I understand what you mean.

Yes, I could have mentioned board files, but this problem only applies
to device-tree descriptions (for the time being at least).

> > Fix this by checking the new of_node_reused flag and skipping automatic
> > pinctrl configuration during probe if set.
> 
> Seems like a solid idea. I hope we don't need another quirk for ACPI.

We should be able to just generalise and rename the flag (or add a
second one) if it turns out ACPI needs this too.

> Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 4/7] driver core: fix automatic pinctrl management
@ 2017-05-31  8:35       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:35 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Johan Hovold, Greg Kroah-Hartman, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Wed, May 31, 2017 at 02:39:28AM +0200, Linus Walleij wrote:
> On Tue, May 30, 2017 at 6:25 PM, Johan Hovold <johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> 
> > Commit ab78029ecc34 ("drivers/pinctrl: grab default handles from device
> > core") added automatic pin-control management to driver core by looking
> > up and setting any default pinctrl state found in device tree while a
> > device is being probed.
> 
> Actually we do not just support device tree, but also passing pin control
> states from board files. It is handled by the core all the same.
> So it's not a device tree thing.
> 
> One of those days we will have ACPI passing state tables too...
> 
> But I understand what you mean.

Yes, I could have mentioned board files, but this problem only applies
to device-tree descriptions (for the time being at least).

> > Fix this by checking the new of_node_reused flag and skipping automatic
> > pinctrl configuration during probe if set.
> 
> Seems like a solid idea. I hope we don't need another quirk for ACPI.

We should be able to just generalise and rename the flag (or add a
second one) if it turns out ACPI needs this too.

> Acked-by: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 3/7] driver core: add helper to reuse a device-tree node
@ 2017-05-31  8:38       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:38 UTC (permalink / raw)
  To: kbuild test robot
  Cc: Johan Hovold, kbuild-all, Greg Kroah-Hartman, Linus Walleij,
	Peter Chen, Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel

On Wed, May 31, 2017 at 06:52:39AM +0800, kbuild test robot wrote:
> Hi Johan,
> 
> [auto build test WARNING on usb/usb-testing]
> [also build test WARNING on v4.12-rc3 next-20170530]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Johan-Hovold/driver-core-USB-thermal-fix-device-tree-node-reuse/20170531-043026
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
> reproduce: make htmldocs
> 
> All warnings (new ones prefixed by >>):

> >> include/linux/device.h:970: warning: No description found for parameter 'of_node_reused'

Forgot to update the kernel docs here. Will fix this in a v2 after
addressing any further comments.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 3/7] driver core: add helper to reuse a device-tree node
@ 2017-05-31  8:38       ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-05-31  8:38 UTC (permalink / raw)
  To: kbuild test robot
  Cc: Johan Hovold, kbuild-all-JC7UmRfGjtg, Greg Kroah-Hartman,
	Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
	Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Wed, May 31, 2017 at 06:52:39AM +0800, kbuild test robot wrote:
> Hi Johan,
> 
> [auto build test WARNING on usb/usb-testing]
> [also build test WARNING on v4.12-rc3 next-20170530]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Johan-Hovold/driver-core-USB-thermal-fix-device-tree-node-reuse/20170531-043026
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
> reproduce: make htmldocs
> 
> All warnings (new ones prefixed by >>):

> >> include/linux/device.h:970: warning: No description found for parameter 'of_node_reused'

Forgot to update the kernel docs here. Will fix this in a v2 after
addressing any further comments.

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/7] USB: core: fix device node leak
@ 2017-06-05  3:35     ` Peter Chen
  0 siblings, 0 replies; 31+ messages in thread
From: Peter Chen @ 2017-06-05  3:35 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel, stable, Peter Chen

On Tue, May 30, 2017 at 06:25:48PM +0200, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
> 
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
> 
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org>	# v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/usb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> +	if (udev->parent)
> +		of_node_put(dev->of_node);
>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);

Acked-by: Peter Chen <peter.chen@nxp.com>

-- 

Best Regards,
Peter Chen

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/7] USB: core: fix device node leak
@ 2017-06-05  3:35     ` Peter Chen
  0 siblings, 0 replies; 31+ messages in thread
From: Peter Chen @ 2017-06-05  3:35 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, stable, Peter Chen

On Tue, May 30, 2017 at 06:25:48PM +0200, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
> 
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
> 
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>	# v4.6
> Cc: Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>
> Signed-off-by: Johan Hovold <johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
>  drivers/usb/core/usb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> +	if (udev->parent)
> +		of_node_put(dev->of_node);
>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);

Acked-by: Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 5/7] USB: of: fix root-hub device-tree node handling
  2017-05-30 16:25 ` [PATCH 5/7] USB: of: fix root-hub device-tree node handling Johan Hovold
@ 2017-06-05  4:51     ` Peter Chen
  0 siblings, 0 replies; 31+ messages in thread
From: Peter Chen @ 2017-06-05  4:51 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel

On Tue, May 30, 2017 at 06:25:52PM +0200, Johan Hovold wrote:
> In an attempt to work around a pinmux over-allocation issue in driver
> core, commit dc5878abf49c ("usb: core: move root hub's device node
> assignment after it is added to bus") moved the device-tree node
> assignment until after the root hub had been registered.
> 
> This not only makes the device-tree node unavailable to the usb driver
> during probe, but also prevents the of_node from being linked to in
> sysfs and causes a race with user-space for the (recently added) devspec
> attribute.
> 
> Use the new device_set_of_node_from_dev() helper to reuse the node of
> the sysdev device, something which now prevents driver core from trying
> to reclaim any pinctrl pins during probe.
> 
> Fixes: dc5878abf49c ("usb: core: move root hub's device node assignment after it is added to bus")
> Fixes: 51fa91475e43 ("usb/core: Added devspec sysfs entry for devices behind the usb hub")
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/hcd.c | 2 --
>  drivers/usb/core/usb.c | 4 ++--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 5dea98358c05..2cff59e9c268 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1076,7 +1076,6 @@ static void usb_deregister_bus (struct usb_bus *bus)
>  static int register_root_hub(struct usb_hcd *hcd)
>  {
>  	struct device *parent_dev = hcd->self.controller;
> -	struct device *sysdev = hcd->self.sysdev;
>  	struct usb_device *usb_dev = hcd->self.root_hub;
>  	const int devnum = 1;
>  	int retval;
> @@ -1123,7 +1122,6 @@ static int register_root_hub(struct usb_hcd *hcd)
>  		/* Did the HC die before the root hub was registered? */
>  		if (HCD_DEAD(hcd))
>  			usb_hc_died (hcd);	/* This time clean up */
> -		usb_dev->dev.of_node = sysdev->of_node;
>  	}
>  	mutex_unlock(&usb_bus_idr_lock);
>  
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 62e1906bb2f3..17681d5638ac 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,8 +416,7 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> -	if (udev->parent)
> -		of_node_put(dev->of_node);
> +	of_node_put(dev->of_node);
>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);
> @@ -616,6 +615,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
>  		dev->route = 0;
>  
>  		dev->dev.parent = bus->controller;
> +		device_set_of_node_from_dev(&dev->dev, bus->sysdev);
>  		dev_set_name(&dev->dev, "usb%d", bus->busnum);
>  		root_hub = 1;
>  	} else {
> -- 
> 2.13.0

I am OK with it, but I suggest adding it for new rc1 since it is based
on the 1st patch which is a bug-fix. If this one is really needed for
stable tree in future, you can cherry-pick it.

-- 

Best Regards,
Peter Chen

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 5/7] USB: of: fix root-hub device-tree node handling
@ 2017-06-05  4:51     ` Peter Chen
  0 siblings, 0 replies; 31+ messages in thread
From: Peter Chen @ 2017-06-05  4:51 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
	Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin,
	linux-pm, linux-usb, linux-kernel

On Tue, May 30, 2017 at 06:25:52PM +0200, Johan Hovold wrote:
> In an attempt to work around a pinmux over-allocation issue in driver
> core, commit dc5878abf49c ("usb: core: move root hub's device node
> assignment after it is added to bus") moved the device-tree node
> assignment until after the root hub had been registered.
> 
> This not only makes the device-tree node unavailable to the usb driver
> during probe, but also prevents the of_node from being linked to in
> sysfs and causes a race with user-space for the (recently added) devspec
> attribute.
> 
> Use the new device_set_of_node_from_dev() helper to reuse the node of
> the sysdev device, something which now prevents driver core from trying
> to reclaim any pinctrl pins during probe.
> 
> Fixes: dc5878abf49c ("usb: core: move root hub's device node assignment after it is added to bus")
> Fixes: 51fa91475e43 ("usb/core: Added devspec sysfs entry for devices behind the usb hub")
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/hcd.c | 2 --
>  drivers/usb/core/usb.c | 4 ++--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 5dea98358c05..2cff59e9c268 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1076,7 +1076,6 @@ static void usb_deregister_bus (struct usb_bus *bus)
>  static int register_root_hub(struct usb_hcd *hcd)
>  {
>  	struct device *parent_dev = hcd->self.controller;
> -	struct device *sysdev = hcd->self.sysdev;
>  	struct usb_device *usb_dev = hcd->self.root_hub;
>  	const int devnum = 1;
>  	int retval;
> @@ -1123,7 +1122,6 @@ static int register_root_hub(struct usb_hcd *hcd)
>  		/* Did the HC die before the root hub was registered? */
>  		if (HCD_DEAD(hcd))
>  			usb_hc_died (hcd);	/* This time clean up */
> -		usb_dev->dev.of_node = sysdev->of_node;
>  	}
>  	mutex_unlock(&usb_bus_idr_lock);
>  
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 62e1906bb2f3..17681d5638ac 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,8 +416,7 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> -	if (udev->parent)
> -		of_node_put(dev->of_node);
> +	of_node_put(dev->of_node);
>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);
> @@ -616,6 +615,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
>  		dev->route = 0;
>  
>  		dev->dev.parent = bus->controller;
> +		device_set_of_node_from_dev(&dev->dev, bus->sysdev);
>  		dev_set_name(&dev->dev, "usb%d", bus->busnum);
>  		root_hub = 1;
>  	} else {
> -- 
> 2.13.0

I am OK with it, but I suggest adding it for new rc1 since it is based
on the 1st patch which is a bug-fix. If this one is really needed for
stable tree in future, you can cherry-pick it.

-- 

Best Regards,
Peter Chen

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/7] USB: of: document reference taken by child-lookup helper
  2017-05-30 22:40   ` Tyrel Datwyler
@ 2017-06-06 15:38     ` Johan Hovold
  0 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-06-06 15:38 UTC (permalink / raw)
  To: Tyrel Datwyler
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel

On Tue, May 30, 2017 at 03:40:03PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > Document that the child-node lookup helper takes a reference to the
> > device-tree node which needs to be dropped after use.
> > 
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/usb/core/of.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> > index d563cbcf76cf..17a4af02cf5b 100644
> > --- a/drivers/usb/core/of.c
> > +++ b/drivers/usb/core/of.c
> > @@ -28,6 +28,9 @@
> >   *
> >   * Find the node from device tree according to its port number.
> >   *
> > + * Takes a reference to the returned device-tree node, which needs to be
> > + * dropped after use.
> > + *
> >   * Return: On success, a pointer to the device node, %NULL on failure.
> 
> I would use the same blurb used throughout drivers/of/* for consistency.
> 
>  *      Returns a node pointer with refcount incremented, use
>  *      of_node_put() on it when done.
>  */
> 
> Just my 2-cents

I updated the comment to use a version of this also found in drivers/of:

 * Return: A pointer to the node with incremented refcount if found, or
 * %NULL otherwise.

which is on kernel-doc format. I don't think we need to explicitly
mention which function to manipulate the refcount with in every header.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 5/7] USB: of: fix root-hub device-tree node handling
  2017-06-05  4:51     ` Peter Chen
  (?)
@ 2017-06-06 15:44     ` Johan Hovold
  -1 siblings, 0 replies; 31+ messages in thread
From: Johan Hovold @ 2017-06-06 15:44 UTC (permalink / raw)
  To: Peter Chen
  Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
	Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
	Eduardo Valentin, linux-pm, linux-usb, linux-kernel

On Mon, Jun 05, 2017 at 12:51:04PM +0800, Peter Chen wrote:
> On Tue, May 30, 2017 at 06:25:52PM +0200, Johan Hovold wrote:
> > In an attempt to work around a pinmux over-allocation issue in driver
> > core, commit dc5878abf49c ("usb: core: move root hub's device node
> > assignment after it is added to bus") moved the device-tree node
> > assignment until after the root hub had been registered.
> > 
> > This not only makes the device-tree node unavailable to the usb driver
> > during probe, but also prevents the of_node from being linked to in
> > sysfs and causes a race with user-space for the (recently added) devspec
> > attribute.
> > 
> > Use the new device_set_of_node_from_dev() helper to reuse the node of
> > the sysdev device, something which now prevents driver core from trying
> > to reclaim any pinctrl pins during probe.
> > 
> > Fixes: dc5878abf49c ("usb: core: move root hub's device node assignment after it is added to bus")
> > Fixes: 51fa91475e43 ("usb/core: Added devspec sysfs entry for devices behind the usb hub")
> > Signed-off-by: Johan Hovold <johan@kernel.org>

> I am OK with it, but I suggest adding it for new rc1 since it is based
> on the 1st patch which is a bug-fix. If this one is really needed for
> stable tree in future, you can cherry-pick it.

I agree, and didn't intent for this one to go into 4.12-rc. Let's see
how Greg wants to handle this. I'll add some comments to the cover
letter in v2.

Thanks,
Johan

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2017-06-06 15:44 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-30 16:25 [PATCH 0/7] driver core/USB/thermal: fix device-tree node reuse Johan Hovold
2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
2017-05-30 22:55   ` Tyrel Datwyler
2017-05-31  8:25     ` Johan Hovold
2017-05-31  8:25       ` Johan Hovold
2017-06-05  3:35   ` Peter Chen
2017-06-05  3:35     ` Peter Chen
2017-05-30 16:25 ` [PATCH 2/7] USB: of: document reference taken by child-lookup helper Johan Hovold
2017-05-30 22:40   ` Tyrel Datwyler
2017-06-06 15:38     ` Johan Hovold
2017-05-30 16:25 ` [PATCH 3/7] driver core: add helper to reuse a device-tree node Johan Hovold
2017-05-30 22:52   ` kbuild test robot
2017-05-30 22:52     ` kbuild test robot
2017-05-31  8:38     ` Johan Hovold
2017-05-31  8:38       ` Johan Hovold
2017-05-30 16:25 ` [PATCH 4/7] driver core: fix automatic pinctrl management Johan Hovold
2017-05-31  0:39   ` Linus Walleij
2017-05-31  0:39     ` Linus Walleij
2017-05-31  8:35     ` Johan Hovold
2017-05-31  8:35       ` Johan Hovold
2017-05-30 16:25 ` [PATCH 5/7] USB: of: fix root-hub device-tree node handling Johan Hovold
2017-06-05  4:51   ` Peter Chen
2017-06-05  4:51     ` Peter Chen
2017-06-06 15:44     ` Johan Hovold
2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
2017-05-30 22:59   ` Tyrel Datwyler
2017-05-31  8:28     ` Johan Hovold
2017-05-30 16:25 ` [PATCH 7/7] thermal: max77620: fix pinmux conflict on reprobe Johan Hovold
2017-05-30 18:57   ` Eduardo Valentin
2017-05-30 18:57     ` Eduardo Valentin
2017-05-31  8:23     ` Johan Hovold

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.