Repository navigation
RP1: fix remove and re-probe in clk-rp1, pwm-rp1, rp1-adc and raspberrypi-gpiomem - #7785
Open
joshuacov1 wants to merge 5 commits into
Open
joshuacov1 wants to merge 5 commits into
joshuacov1 wants to merge 5 commits into
Conversation
Author
|
The two upstream fixes are posted:
Both carry Fixes: tags, so they should reach 6.18.y through stable. |
joshuacov1
force-pushed
the
rp1-fixes
branch
from
November 21, 2026 18:40
f6785c7 to
6c2a47f
Compare
rpi_gpiomem_remove() frees its private data and then reads priv->name for its final log message. The freed memory may already have been reused, and unbinding the driver oopses: pc : string+0x50/0x140 lr : vsnprintf+0x1bc/0x64c Call trace: string+0x50/0x140 (P) vsnprintf+0x1bc/0x64c ... _dev_info+0x54/0x60 rpi_gpiomem_remove+0x5c/0x6c platform_remove+0x20/0x30 Log the message before freeing the data, and terminate it with a newline. Signed-off-by: Joshua Covington <joshuacov@gmail.com>
rp1_pwm_probe() never sets the platform driver data, so rp1_pwm_remove() reads the clock through a NULL pointer, and removing the device oopses with a NULL pointer dereference at address 0x8: pc : rp1_pwm_remove+0x14/0x38 lr : platform_remove+0x20/0x30 The clock comes from devm_clk_get_enabled(), which already disables it on probe failure and on remove, so both the remove callback and the error path in probe would disable it a second time. Drop the remove callback and the manual clock disable. Signed-off-by: Joshua Covington <joshuacov@gmail.com>
The clock descriptors are static. The clock core clears hw.init when a clock is registered. When RP1 is unbound and bound again, the second probe registers the clocks without init data and oopses: pc : __clk_register+0x5c/0x9dc Call trace: __clk_register+0x5c/0x9dc (P) devm_clk_hw_register+0x5c/0xe0 rp1_register_pll+0x24/0x40 rp1_clk_probe+0xc0/0x168 The clock core also leaves hw.core pointing to the freed clk_core on unregister. Some clocks refer to a parent that is registered after them, e.g. clk_mipi0_dpi to clksrc_mipi0_dsi_byteclk. On the second probe, their parent lookup can use the stale clk_core. Restore hw.init and clear the stale state of all descriptors before registering them. Fixes: 6486341 ("clk: rp1: Add support for clocks provided by RP1") Signed-off-by: Joshua Covington <joshuacov@gmail.com>
The hwmon device is registered with devm_hwmon_device_register_with_groups(), which unregisters it when the driver is unbound. rp1_adc_remove() unregisters it as well, so the devres action later operates on a device that is already gone. Drop the remove callback. Signed-off-by: Joshua Covington <joshuacov@gmail.com>
The driver is registered with module_platform_driver_probe(), so its probe function is discarded after boot and later devices fail to probe. When the RP1 device is unbound and bound again, the ADC device is recreated but never gets a driver, and the RP1 sensors stay missing until the next reboot. Register the driver with module_platform_driver() and drop __init from the probe function. Signed-off-by: Joshua Covington <joshuacov@gmail.com>
joshuacov1
force-pushed
the
rp1-fixes
branch
from
November 21, 2026 18:44
6c2a47f to
4c0a73a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Unbinding and binding the RP1 PCI device again (rp1_pci, drivers/misc/rp1) removes and re-probes all RP1 peripheral drivers. Several of them do not survive this:
To reproduce (run detached, or over SSH, as a ttyAMA0 console is an RP1 UART and goes away with the unbind):
Without these patches, the unbind oopses in rpi_gpiomem_remove() and then in rp1_pwm_remove(), and the bind oopses in __clk_register(). Each oops stops the test, so each one shows up only once the previous one is fixed:
Tested on a CM5 with 6.18.64: unbind and rebind of 0002:01:00.0 complete without oopses, and all RP1 platform devices enabled in the DT (13 on this board), Ethernet, USB and the ttyAMA0 console come back. The rp1-adc patches are build-tested only, as the ADC driver was not enabled on the test image.
The same code is still present in rpi-7.4.y.