Skip to contentSkip to conversation

cxl/mbox: Remove useless cast in cxl_mem_create_range_info()

PATCH Superseded [email protected] 3 participants 4 messages Aug 4, 2023 – Aug 15, 2023 CXL

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 cxl/mbox: Remove useless cast in cxl_mem_create_range_info()

From: Alison Schofield <[email protected]>

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

---
 drivers/cxl/core/mbox.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/mbox.c +1 -2
index d6d067fbee97..01de4b438b2a 100644
@@ -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

Signature · 1 line
2.37.3
#1 lore raw
Quoted 10 lines · On Fri, 4 Aug 2023 12:03:09 -0700 [email protected] wrote:

From: Alison Schofield <[email protected]>

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

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

Quoted 20 lines
---
 drivers/cxl/core/mbox.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/mbox.c +1 -2
index d6d067fbee97..01de4b438b2a 100644
@@ -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

#2 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 4 Aug 2023 12:03:09 -0700 [email protected] wrote:

From: Alison Schofield <[email protected]>

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

Quoted 6 lines

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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#3 lore raw
Quoted 16 lines · Andy Shevchenko
Quoted 8 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 4 Aug 2023 12:03:09 -0700 [email protected] wrote:

From: Alison Schofield <[email protected]>

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

Quoted 6 lines

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.

Quoted 7 lines

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.

Quoted 6 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko