Linux CXL
 help / color / mirror / Atom feed
* [PATCH] cxl: Clarify root_port cleanup routine for cxl_qos_class_verify()
@ 2024-01-04 16:08 Dave Jiang
  2024-01-04 17:05 ` Alison Schofield
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dave Jiang @ 2024-01-04 16:08 UTC (permalink / raw)
  To: linux-cxl
  Cc: Robert Richter, dan.j.williams, ira.weiny, vishal.l.verma,
	alison.schofield, Jonathan.Cameron, dave

The current __free() call for root_port in cxl_qos_class_verify() depends
on 'struct device' to be the first member of 'struct cxl_port' and calls
put_device() directly with the root_port pointer passed in. Add a helper
function put_cxl_port() to handle the put_device() properly and avoid
future issues if the 'struct device' member moves.

Suggested-by: Robert Richter <rrichter@amd.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/cxl/core/cdat.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c
index cd84d87f597a..d6e64570032f 100644
--- a/drivers/cxl/core/cdat.c
+++ b/drivers/cxl/core/cdat.c
@@ -345,11 +345,21 @@ static void discard_dpa_perf(struct list_head *list)
 }
 DEFINE_FREE(dpa_perf, struct list_head *, if (!list_empty(_T)) discard_dpa_perf(_T))
 
+static void put_cxl_port(struct cxl_port *port)
+{
+	if (!port)
+		return;
+
+	put_device(&port->dev);
+}
+
+DEFINE_FREE(cxl_port, struct cxl_port *, put_cxl_port(_T))
+
 static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
 {
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
 	struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
-	struct cxl_port *root_port __free(put_device) = NULL;
+	struct cxl_port *root_port __free(cxl_port) = NULL;
 	LIST_HEAD(__discard);
 	struct list_head *discard __free(dpa_perf) = &__discard;
 	int rc;



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-08 12:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-04 16:08 [PATCH] cxl: Clarify root_port cleanup routine for cxl_qos_class_verify() Dave Jiang
2024-01-04 17:05 ` Alison Schofield
2024-01-04 18:22 ` Robert Richter
2024-01-04 18:26   ` Dave Jiang
2024-01-04 19:52 ` Dan Williams
2024-01-08 11:45   ` Jonathan Cameron
2024-01-08 11:57     ` Robert Richter
2024-01-08 12:49       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox