diff mbox series

[1/3] cxl: Remove cxl_root check after find_cxl_root

Message ID 170476242895.115624.3127891331552985140.stgit@djiang5-mobl3
State New, archived
Headers show
Series [1/3] cxl: Remove cxl_root check after find_cxl_root | expand

Commit Message

Dave Jiang Jan. 9, 2024, 1:07 a.m. UTC
find_cxl_root() can't fail in practice as CXL root exit unregisters all
descendant ports and that in turn synchronizes with cxl_port_probe().
Remove unnecessary check after calling find_cxl_root().

Suggested-by: Robert Richter <rrichter@amd.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/cxl/core/cdat.c |    6 ------
 drivers/cxl/core/pmem.c |    3 ---
 2 files changed, 9 deletions(-)

Comments

Dan Williams Jan. 9, 2024, 1:16 a.m. UTC | #1
Dave Jiang wrote:
> find_cxl_root() can't fail in practice as CXL root exit unregisters all
> descendant ports and that in turn synchronizes with cxl_port_probe().
> Remove unnecessary check after calling find_cxl_root().
> 
> Suggested-by: Robert Richter <rrichter@amd.com>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/cxl/core/cdat.c |    6 ------
>  drivers/cxl/core/pmem.c |    3 ---
>  2 files changed, 9 deletions(-)
> 
> diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c
> index 6fe11546889f..f7ba7bd2e459 100644
> --- a/drivers/cxl/core/cdat.c
> +++ b/drivers/cxl/core/cdat.c
> @@ -176,9 +176,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
>  
>  	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
>  
> -	if (!cxl_root)
> -		return -ENODEV;
> -
>  	if (!cxl_root->ops || !cxl_root->ops->qos_class)
>  		return -EOPNOTSUPP;
>  
> @@ -357,9 +354,6 @@ static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
>  	struct cxl_root *cxl_root __free(put_cxl_root) =
>  		find_cxl_root(cxlmd->endpoint);
>  
> -	if (!cxl_root)
> -		return -ENODEV;
> -

These are kind of ok because cxl_port_perf_data_calculate() is called
from cxl_endpoint_port_probe() which has the exact comment you reference
in the changelog. However it is not clear a couple of calls away that
cxl_port_perf_data_calculate() can / should be assuming its calling
context.

I would be inclined to keep them.

>  	root_port = &cxl_root->port;
>  
>  	/* Check that the QTG IDs are all sane between end device and root decoders */
> diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
> index e69625a8d6a1..ed76d37e4fd9 100644
> --- a/drivers/cxl/core/pmem.c
> +++ b/drivers/cxl/core/pmem.c
> @@ -68,9 +68,6 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
>  		find_cxl_root(cxlmd->endpoint);
>  	struct device *dev;
>  
> -	if (!cxl_root)
> -		return NULL;
> -

This one is definitely needed since it is not called from
cxl_endpoint_port_probe() where it knows the linkage exists.
diff mbox series

Patch

diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c
index 6fe11546889f..f7ba7bd2e459 100644
--- a/drivers/cxl/core/cdat.c
+++ b/drivers/cxl/core/cdat.c
@@ -176,9 +176,6 @@  static int cxl_port_perf_data_calculate(struct cxl_port *port,
 
 	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
 
-	if (!cxl_root)
-		return -ENODEV;
-
 	if (!cxl_root->ops || !cxl_root->ops->qos_class)
 		return -EOPNOTSUPP;
 
@@ -357,9 +354,6 @@  static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
 	struct cxl_root *cxl_root __free(put_cxl_root) =
 		find_cxl_root(cxlmd->endpoint);
 
-	if (!cxl_root)
-		return -ENODEV;
-
 	root_port = &cxl_root->port;
 
 	/* Check that the QTG IDs are all sane between end device and root decoders */
diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
index e69625a8d6a1..ed76d37e4fd9 100644
--- a/drivers/cxl/core/pmem.c
+++ b/drivers/cxl/core/pmem.c
@@ -68,9 +68,6 @@  struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
 		find_cxl_root(cxlmd->endpoint);
 	struct device *dev;
 
-	if (!cxl_root)
-		return NULL;
-
 	dev = device_find_child(&cxl_root->port.dev, NULL, match_nvdimm_bridge);
 
 	if (!dev)