spi: uclass: skip cs lookup if bus not probed - #93
Conversation
ozan956
left a comment
There was a problem hiding this comment.
spi_find_bus_and_cs() is documented as a lookup helper that finds the bus and slave without activating either side, but this change now returns -ENODEV because the bus is not active yet.
Also the commit message is misleading. A bound SPI child device can already exist on an unprobed bus: the SPI uclass scans child nodes at bind time via .post_bind = dm_scan_fdt_dev, and child SPI plat is populated in spi_child_post_bind(). So this patch can hide a valid, already-bound slave device simply because the parent bus is still inactive.
It also does not fix the underlying issue generally. The real problem here is that spi_find_chip_select() may call ->cs_info() on an unprobed bus, but this patch only papers over one caller, spi_find_bus_and_cs(). Other paths such as spi_cs_info() / spi_cs_is_valid() still go through the same unprobed-bus flow.
If the goal is to address cs_info() relying on probe-time private data, I would expect the fix either in spi_find_chip_select() or in the driver-side cs_info() handling, not as a behavioral change in spi_find_bus_and_cs().
Move chip select validation from spi_find_chip_select() into spi_child_pre_probe(), where the bus is guaranteed to be active and driver private data is initialized. This avoids false CS rejections when spi_find_chip_select() is called on an unprobed bus, and simplifies the lookup function. Signed-off-by: Jie Zhang <jie.zhang@analog.com>
0abc067 to
a3262e0
Compare
Thanks for your review! I agree with your comments. I pushed a new commit, which moves cs validation from spi_find_chip_select() to spi_child_pre_probe(), i.e. move cs validation to probe phase. spi_find_chip_select() now does not validate cs. |
|
I haven't had a chance to read this in detail, but it looks like there are still issues. See review-inline.txt from Claude Sonnet 4.6 including Ozan's comment. Given that review and looking at other implementations in U-Boot and Linux Claude suggested the following: |
spi_find_bus_and_cs() uses uclass_find_device_by_seq() which locates the bus without probing it. Calling spi_find_chip_select() on an unprobed bus causes drivers that validate chip selects using private data (initialized only at probe time) to spuriously reject valid CS numbers. Since no SPI device can exist on an unprobed bus, return -ENODEV early instead.