Skip to content

Commit 99ff906

Browse files
Robert Richterdavejiang
authored andcommitted
cxl: Introduce parent_port_of() helper
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 <[email protected]> Reviewed-by: Gregory Price <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Reviewed-by: "Fabio M. De Francesco" <[email protected]> Tested-by: Gregory Price <[email protected]> Acked-by: Dan Williams <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 88bc050 commit 99ff906

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

drivers/cxl/core/port.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,19 @@ struct cxl_port *to_cxl_port(const struct device *dev)
602602
}
603603
EXPORT_SYMBOL_NS_GPL(to_cxl_port, "CXL");
604604

605+
struct cxl_port *parent_port_of(struct cxl_port *port)
606+
{
607+
if (!port || !port->parent_dport)
608+
return NULL;
609+
return port->parent_dport->port;
610+
}
611+
605612
static void unregister_port(void *_port)
606613
{
607614
struct cxl_port *port = _port;
608-
struct cxl_port *parent;
615+
struct cxl_port *parent = parent_port_of(port);
609616
struct device *lock_dev;
610617

611-
if (is_cxl_root(port))
612-
parent = NULL;
613-
else
614-
parent = to_cxl_port(port->dev.parent);
615-
616618
/*
617619
* CXL root port's and the first level of ports are unregistered
618620
* under the platform firmware device lock, all other ports are

drivers/cxl/core/region.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,13 +1747,6 @@ static int cmp_interleave_pos(const void *a, const void *b)
17471747
return cxled_a->pos - cxled_b->pos;
17481748
}
17491749

1750-
static struct cxl_port *next_port(struct cxl_port *port)
1751-
{
1752-
if (!port->parent_dport)
1753-
return NULL;
1754-
return port->parent_dport->port;
1755-
}
1756-
17571750
static int match_switch_decoder_by_range(struct device *dev,
17581751
const void *data)
17591752
{
@@ -1780,7 +1773,7 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
17801773
struct device *dev;
17811774
int rc = -ENXIO;
17821775

1783-
parent = next_port(port);
1776+
parent = parent_port_of(port);
17841777
if (!parent)
17851778
return rc;
17861779

@@ -1860,7 +1853,7 @@ static int cxl_calc_interleave_pos(struct cxl_endpoint_decoder *cxled)
18601853
*/
18611854

18621855
/* Iterate from endpoint to root_port refining the position */
1863-
for (iter = port; iter; iter = next_port(iter)) {
1856+
for (iter = port; iter; iter = parent_port_of(iter)) {
18641857
if (is_cxl_root(iter))
18651858
break;
18661859

drivers/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ static inline bool is_cxl_root(struct cxl_port *port)
724724
int cxl_num_decoders_committed(struct cxl_port *port);
725725
bool is_cxl_port(const struct device *dev);
726726
struct cxl_port *to_cxl_port(const struct device *dev);
727+
struct cxl_port *parent_port_of(struct cxl_port *port);
727728
void cxl_port_commit_reap(struct cxl_decoder *cxld);
728729
struct pci_bus;
729730
int devm_cxl_register_pci_bus(struct device *host, struct device *uport_dev,

0 commit comments

Comments
 (0)