[PATCH] cxl: replace loop with for_each_child_of_node(), remove unneeded of_node_put()

Frederic Barrat fbarrat at linux.vnet.ibm.com
Mon Aug 1 23:34:09 AEST 2016

Le 29/07/2016 à 13:38, Michael Ellerman a écrit :
> But who does keep a reference on the device_node? I can't see it anywhere. Which
> means in theory the device_node can be freed out from under you.
> You have a reference for afu_np as part of for_each_child_of_node(), but it's
> dropped as soon as you go around the loop.
> The typical pattern would be that cxl_guest_init_afu() takes an additional
> reference once it's done all its setup and can't fail.
> That way at the end of the loop when the loop construct has dropped all
> references, the nodes you actually init'ed have their reference count
> incremented by 1.

We don't keep a reference on the AFU device_node. Once we've read the 
config of the AFU, the AFU device_node is never accessed again. So I 
guess it's possible (though unexpected) that it's freed from under us, 
but it should not affect the driver.

The AFU is really dependent on the adapter itself, which is one level up 
in the device tree, and for which we create a device through 
of_platform_device_create(). The properties under the AFU device node 
are read directly from the PCI config space in the bare-metal case, 
where the cxl adapter is a PCI device.

Do we really have a problem here?


More information about the Linuxppc-dev mailing list