diff mbox series

[v1] cxl/port: Convert to use ERR_CAST()

Message ID 20240829125235.3266865-1-liyuesong@vivo.com
State Accepted
Commit 1f9651bfc51326fbed10df820c4e80f885f921d8
Headers show
Series [v1] cxl/port: Convert to use ERR_CAST() | expand

Commit Message

Yuesong Li Aug. 29, 2024, 12:52 p.m. UTC
Use ERR_CAST() as it is designed for casting an error pointer to
another type.

This macro utilizes the __force and __must_check modifiers, which instruct
the compiler to verify for errors at the locations where it is employed.

Signed-off-by: Yuesong Li <liyuesong@vivo.com>
---
 drivers/cxl/core/port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jonathan Cameron Aug. 29, 2024, 2:43 p.m. UTC | #1
On Thu, 29 Aug 2024 20:52:35 +0800
Yuesong Li <liyuesong@vivo.com> wrote:

> Use ERR_CAST() as it is designed for casting an error pointer to
> another type.
> 
> This macro utilizes the __force and __must_check modifiers, which instruct
> the compiler to verify for errors at the locations where it is employed.
> 
> Signed-off-by: Yuesong Li <liyuesong@vivo.com>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/cxl/core/port.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index 1d5007e3795a..bdd3275ad417 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -941,7 +941,7 @@ struct cxl_root *devm_cxl_add_root(struct device *host,
>  
>  	port = devm_cxl_add_port(host, host, CXL_RESOURCE_NONE, NULL);
>  	if (IS_ERR(port))
> -		return (struct cxl_root *)port;
> +		return ERR_CAST(port);
>  
>  	cxl_root = to_cxl_root(port);
>  	cxl_root->ops = ops;
Alison Schofield Aug. 29, 2024, 9:45 p.m. UTC | #2
On Thu, Aug 29, 2024 at 08:52:35PM +0800, Yuesong Li wrote:
> Use ERR_CAST() as it is designed for casting an error pointer to
> another type.
> 
> This macro utilizes the __force and __must_check modifiers, which instruct
> the compiler to verify for errors at the locations where it is employed.

Reviewed-by: Alison Schofield <alison.schofield@intel.com>

> 
> Signed-off-by: Yuesong Li <liyuesong@vivo.com>
> ---
>  drivers/cxl/core/port.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

snip

>
diff mbox series

Patch

diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 1d5007e3795a..bdd3275ad417 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -941,7 +941,7 @@  struct cxl_root *devm_cxl_add_root(struct device *host,
 
 	port = devm_cxl_add_port(host, host, CXL_RESOURCE_NONE, NULL);
 	if (IS_ERR(port))
-		return (struct cxl_root *)port;
+		return ERR_CAST(port);
 
 	cxl_root = to_cxl_root(port);
 	cxl_root->ops = ops;