Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/testing/cxl: Fix cxl_hdm_decode_init() calling convention

This failing signature:

[ 8.392669] cxl_bus_probe: cxl_port endpoint2: probe: 970997760
[ 8.392670] cxl_port: probe of endpoint2 failed with error 970997760
[ 8.392719] create_endpoint: cxl_mem mem0: add: endpoint2
[ 8.392721] cxl_mem mem0: endpoint2 failed probe
[ 8.392725] cxl_bus_probe: cxl_mem mem0: probe: -6

...shows cxl_hdm_decode_init() resulting in a return code ("970997760")
that looks like stack corruption. The problem goes away if
cxl_hdm_decode_init() is not mocked via __wrap_cxl_hdm_decode_init().

The corruption results from the mismatch that the calling convention for
cxl_hdm_decode_init() is:

int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm)

...and __wrap_cxl_hdm_decode_init() is:

bool __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm)

...i.e. an int is expected but __wrap_hdm_decode_init() returns bool.

Fix the convention and cleanup the organization to match
__wrap_cxl_await_media_ready() as the difference was a red herring that
distracted from finding the bug.

Fixes: 92804edb11f0 ("cxl/pci: Drop @info argument to cxl_hdm_decode_init()")
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Adam Manzanares <a.manzanares@samsung.com>
Link: https://lore.kernel.org/r/165603870776.551046.8709990108936497723.stgit@dwillia2-xfh
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+5 -3
+5 -3
tools/testing/cxl/test/mock.c
··· 208 208 } 209 209 EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready, CXL); 210 210 211 - bool __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds, 212 - struct cxl_hdm *cxlhdm) 211 + int __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds, 212 + struct cxl_hdm *cxlhdm) 213 213 { 214 214 int rc = 0, index; 215 215 struct cxl_mock_ops *ops = get_cxl_mock_ops(&index); 216 216 217 - if (!ops || !ops->is_mock_dev(cxlds->dev)) 217 + if (ops && ops->is_mock_dev(cxlds->dev)) 218 + rc = 0; 219 + else 218 220 rc = cxl_hdm_decode_init(cxlds, cxlhdm); 219 221 put_cxl_mock_ops(index); 220 222