cxl: Introduce parent_port_of() helper
authorRobert Richter <rrichter@amd.com>
Fri, 9 May 2025 15:06:49 +0000 (17:06 +0200)
committerDave Jiang <dave.jiang@intel.com>
Fri, 9 May 2025 16:48:25 +0000 (09:48 -0700)
Often a parent port must be determined. Introduce the parent_port_of()
helper function to avoid open coding of determination of a parent
port.

Signed-off-by: Robert Richter <rrichter@amd.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>
Tested-by: Gregory Price <gourry@gourry.net>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20250509150700.2817697-5-rrichter@amd.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/port.c
drivers/cxl/core/region.c
drivers/cxl/cxl.h

index 726bd4a7de2703acf1f2823e9714364c1351839a..83cfebe8d3e9d56ebfe9930ed25ab64f2f122941 100644 (file)
@@ -602,17 +602,19 @@ struct cxl_port *to_cxl_port(const struct device *dev)
 }
 EXPORT_SYMBOL_NS_GPL(to_cxl_port, "CXL");
 
+struct cxl_port *parent_port_of(struct cxl_port *port)
+{
+       if (!port || !port->parent_dport)
+               return NULL;
+       return port->parent_dport->port;
+}
+
 static void unregister_port(void *_port)
 {
        struct cxl_port *port = _port;
-       struct cxl_port *parent;
+       struct cxl_port *parent = parent_port_of(port);
        struct device *lock_dev;
 
-       if (is_cxl_root(port))
-               parent = NULL;
-       else
-               parent = to_cxl_port(port->dev.parent);
-
        /*
         * CXL root port's and the first level of ports are unregistered
         * under the platform firmware device lock, all other ports are
index f67fbb3c9e226243ef3f0b68850ccfbe5ec1ba87..28c1e292c62664fa5a5abb01a26b26710dd1dd2a 100644 (file)
@@ -1747,13 +1747,6 @@ static int cmp_interleave_pos(const void *a, const void *b)
        return cxled_a->pos - cxled_b->pos;
 }
 
-static struct cxl_port *next_port(struct cxl_port *port)
-{
-       if (!port->parent_dport)
-               return NULL;
-       return port->parent_dport->port;
-}
-
 static int match_switch_decoder_by_range(struct device *dev,
                                         const void *data)
 {
@@ -1780,7 +1773,7 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
        struct device *dev;
        int rc = -ENXIO;
 
-       parent = next_port(port);
+       parent = parent_port_of(port);
        if (!parent)
                return rc;
 
@@ -1860,7 +1853,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled)
         */
 
        /* Iterate from endpoint to root_port refining the position */
-       for (iter = port; iter; iter = next_port(iter)) {
+       for (iter = port; iter; iter = parent_port_of(iter)) {
                if (is_cxl_root(iter))
                        break;
 
index a9ab46eb0610012f268d482df006122d5d984239..14e20b44f2f459b4a642a37c4a2969635593f44f 100644 (file)
@@ -724,6 +724,7 @@ static inline bool is_cxl_root(struct cxl_port *port)
 int cxl_num_decoders_committed(struct cxl_port *port);
 bool is_cxl_port(const struct device *dev);
 struct cxl_port *to_cxl_port(const struct device *dev);
+struct cxl_port *parent_port_of(struct cxl_port *port);
 void cxl_port_commit_reap(struct cxl_decoder *cxld);
 struct pci_bus;
 int devm_cxl_register_pci_bus(struct device *host, struct device *uport_dev,