Messages in this thread | | | Date | Thu, 14 Dec 2023 20:34:09 -0800 | From | Dan Williams <> | Subject | Re: [PATCH] cxl/pci: Get rid of pointer arithmetic reading CDAT table |
| |
Robert Richter wrote: > On 17.11.23 21:09:18, Robert Richter wrote: > > I will send an on-top patch for 6.8 that reworks that code area to > > remove the pointer arithmetic. > > Here it is: > > From 13787f72c20b8c54754ae86015d982307eae0397 Mon Sep 17 00:00:00 2001 > From: Robert Richter <rrichter@amd.com> > Subject: [PATCH] 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 (see fix of devm_kfree() in > read_cdat_data()). > > Rework code to avoid calculations with sizeof(__le32). Introduce > struct cdat_doe 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.
I like reworking the code to introduce an explicit type for the response buffer, but as Ira points out, lets call it a "response" not a "cdat_doe".
The feedback on the flex array is accurate, but I see no reason to have 3 flex arrays vs:
struct cdat_response { __le32 doe_header; union { struct cdat_header header; struct cdat_entry_header entry; u8 table[]; }; } __packed;
As far as I can see nothing outside of drivers/cxl/core/pci.c needs 'struct cdat_response', so it can stay local to this C file.
While you are working on that I will do another lead-in cleanup to kill the goto in cxl_cdat_read_table() and let you come back and kill off the open-coded "+ sizeof(__le32)" that I will leave behind.
| |