diff mbox series

cxl/mbox: Remove useless cast in cxl_mem_create_range_info()

Message ID 20230804190309.1665132-1-alison.schofield@intel.com
State Superseded
Headers show
Series cxl/mbox: Remove useless cast in cxl_mem_create_range_info() | expand

Commit Message

Alison Schofield Aug. 4, 2023, 7:03 p.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

DEFINE_RES_MEM() returns a struct resource so the cast is not needed.
Remove it.

Found using sparse:
drivers/cxl/core/mbox.c:1184:18: warning: cast to non-scalar
drivers/cxl/core/mbox.c:1184:18: warning: cast from non-scalar

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 drivers/cxl/core/mbox.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)


base-commit: fe77cc2e5a6a7c85f5c6ef8a39d7694ffc7f41c9

Comments

Jonathan Cameron Aug. 7, 2023, 1:33 p.m. UTC | #1
On Fri,  4 Aug 2023 12:03:09 -0700
alison.schofield@intel.com wrote:

> From: Alison Schofield <alison.schofield@intel.com>
> 
> DEFINE_RES_MEM() returns a struct resource so the cast is not needed.
> Remove it.
> 
> Found using sparse:
> drivers/cxl/core/mbox.c:1184:18: warning: cast to non-scalar
> drivers/cxl/core/mbox.c:1184:18: warning: cast from non-scalar
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Good to call out this is a result of Andy's cleanup

42c4211f1 ("resource: Convert DEFINE_RES_NAMED() to be a compound literal")

I thought we'd long caught all of these (IIRC there were a few at the time).
Ah well.

Jonathan

> ---
>  drivers/cxl/core/mbox.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index d6d067fbee97..01de4b438b2a 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -1180,8 +1180,7 @@ int cxl_mem_create_range_info(struct cxl_memdev_state *mds)
>  		return 0;
>  	}
>  
> -	cxlds->dpa_res =
> -		(struct resource)DEFINE_RES_MEM(0, mds->total_bytes);
> +	cxlds->dpa_res = DEFINE_RES_MEM(0, mds->total_bytes);
>  
>  	if (mds->partition_align_bytes == 0) {
>  		rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,
> 
> base-commit: fe77cc2e5a6a7c85f5c6ef8a39d7694ffc7f41c9
Andy Shevchenko Aug. 7, 2023, 2:28 p.m. UTC | #2
On Mon, Aug 07, 2023 at 02:33:34PM +0100, Jonathan Cameron wrote:
> On Fri,  4 Aug 2023 12:03:09 -0700
> alison.schofield@intel.com wrote:
> 
> > From: Alison Schofield <alison.schofield@intel.com>
> > 
> > DEFINE_RES_MEM() returns a struct resource so the cast is not needed.
> > Remove it.

> Good to call out this is a result of Andy's cleanup
> 
> 42c4211f1 ("resource: Convert DEFINE_RES_NAMED() to be a compound literal")
> 
> I thought we'd long caught all of these (IIRC there were a few at the time).
> Ah well.

We caught only compile-time errors. The "casting" of the compound literal is
only a warning which doesn't affect code generation.

Btw, Alison, the commit message should really be more clear about those macros.
They are compound literals, which are associated with the corresponding data
type. It's not a cast there, but only on the side of the user. I'm not a native
speaker to suggest on how to amend, maybe Jonathan can help?
Alison Schofield Aug. 15, 2023, 4:46 p.m. UTC | #3
On Mon, Aug 07, 2023 at 05:28:00PM +0300, Andy Shevchenko wrote:
> On Mon, Aug 07, 2023 at 02:33:34PM +0100, Jonathan Cameron wrote:
> > On Fri,  4 Aug 2023 12:03:09 -0700
> > alison.schofield@intel.com wrote:
> > 
> > > From: Alison Schofield <alison.schofield@intel.com>
> > > 
> > > DEFINE_RES_MEM() returns a struct resource so the cast is not needed.
> > > Remove it.
> 
> > Good to call out this is a result of Andy's cleanup
> > 
> > 42c4211f1 ("resource: Convert DEFINE_RES_NAMED() to be a compound literal")
> > 
> > I thought we'd long caught all of these (IIRC there were a few at the time).
> > Ah well.
> 
> We caught only compile-time errors. The "casting" of the compound literal is
> only a warning which doesn't affect code generation.
> 
> Btw, Alison, the commit message should really be more clear about those macros.
> They are compound literals, which are associated with the corresponding data
> type. It's not a cast there, but only on the side of the user. I'm not a native
> speaker to suggest on how to amend, maybe Jonathan can help?

Thanks Andy. I see the language others used in these. Will send a v2.


> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
diff mbox series

Patch

diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index d6d067fbee97..01de4b438b2a 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -1180,8 +1180,7 @@  int cxl_mem_create_range_info(struct cxl_memdev_state *mds)
 		return 0;
 	}
 
-	cxlds->dpa_res =
-		(struct resource)DEFINE_RES_MEM(0, mds->total_bytes);
+	cxlds->dpa_res = DEFINE_RES_MEM(0, mds->total_bytes);
 
 	if (mds->partition_align_bytes == 0) {
 		rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,