cxl/pci: Get rid of pointer arithmetic reading CDAT table
authorRobert Richter <rrichter@amd.com>
Fri, 16 Feb 2024 15:58:43 +0000 (16:58 +0100)
committerDan Williams <dan.j.williams@intel.com>
Wed, 13 Mar 2024 06:52:29 +0000 (23:52 -0700)
commite0c818e00443ce4a704519d85a21e3c14179e3a6
treee6c92ec123c81c99429be4cda41f08183be3308d
parentec8ffff3a9f86435996f71299ce729126a7ac8a2
cxl/pci: Get rid of pointer arithmetic reading CDAT table

Reading the CDAT table using DOE requires a Table Access Response
Header in addition to the CDAT entry. In current implementation this
has caused offsets with sizeof(__le32) to the actual buffers. This led
to hardly readable code and even bugs. E.g., see fix of devm_kfree()
in read_cdat_data():

 commit c65efe3685f5 ("cxl/cdat: Free correct buffer on checksum error")

Rework code to avoid calculations with sizeof(__le32). Introduce
struct cdat_doe_rsp for this which contains the Table Access Response
Header and a variable payload size for various data structures
afterwards to access the CDAT table and its CDAT Data Structures
without recalculating buffer offsets.

Cc: Lukas Wunner <lukas@wunner.de>
Cc: Fan Ni <nifan.cxl@gmail.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Robert Richter <rrichter@amd.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240216155844.406996-3-rrichter@amd.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/core/pci.c
drivers/cxl/cxlpci.h