jesd204: core: Fix device lifecycle for proper register/unregister cycles #3100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description
Further testing with overlays triggering deferred probe returns exhibited some more problems....
The embedded struct device in jesd204_dev was not properly managed across driver bind/unbind cycles, causing several issues:
Missing release function: The kernel requires every struct device to have a release() function. Without one, put_device() triggers a WARNING ("does not have a release() function, it is broken"). Add a jesd204_dev_type with a no-op release callback, since the jdev memory is managed separately by the jesd204 core.
Missing put_device() calls: device_del() must be paired with put_device() to drop the reference taken by device_initialize(). Add the missing put_device() in both jesd204_dev_unregister() and the err_device_del error path in jesd204_dev_register().
Stale device state on re-probe: After a driver unbinds, jesd204_dev_unregister() must fully reset the embedded struct device via memset so that a subsequent probe can safely call device_initialize() + device_add() again with the same device name. Without the memset, the kobject retains its initialized state, triggering "tried to init an initialized object" warnings on re-probe. Move the memset into the dev.parent conditional block alongside device_del/put_device where it logically belongs.
Stale unregistered flag: When a driver probe fails after successful jesd204_dev_register(), the devm cleanup sets jdev->unregistered to true. On deferred probe retry, this flag was never cleared, which would cause a subsequent unregister to skip cleanup. Reset the flag at the start of jesd204_dev_register().
PR Type