Skip to contentSkip to conversation

cxl/mem: Correct full ID range allocation

PATCH In review Davidlohr Bueso 4 participants 5 messages Feb 8, 2023 – Feb 9, 2023 CXL

lore
Share & tools
lore

Davidlohr Bueso

author maintainer
#0 lore raw

PATCH 1/1 cxl/mem: Correct full ID range allocation

For ID allocations we want 0-(max-1), ie: smatch complains:

error: Calling ida_alloc_range() with a 'max' argument which is a power of 2. -1 missing?

Correct this and also replace the call to use the max() flavor instead.

---
 drivers/cxl/core/memdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/memdev.c +1 -1
index a74a93310d26..12bd9ddaba22 100644
@@ -242,7 +242,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
 	if (!cxlmd)
 		return ERR_PTR(-ENOMEM);
 
-	rc = ida_alloc_range(&cxl_memdev_ida, 0, CXL_MEM_MAX_DEVS, GFP_KERNEL);
+	rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL);
 	if (rc < 0)
 		goto err;
 	cxlmd->id = rc;
Signature · 1 line
2.39.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Davidlohr Bueso

For ID allocations we want 0-(max-1), ie: smatch complains:

error: Calling ida_alloc_range() with a 'max' argument which is a power of 2. -1 missing?

Correct this and also replace the call to use the max() flavor instead.

Quoted 17 lines
---
  drivers/cxl/core/memdev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/memdev.c +1 -1
index a74a93310d26..12bd9ddaba22 100644
@@ -242,7 +242,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
  	if (!cxlmd)
  		return ERR_PTR(-ENOMEM);
 
-	rc = ida_alloc_range(&cxl_memdev_ida, 0, CXL_MEM_MAX_DEVS, GFP_KERNEL);
+	rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL);
  	if (rc < 0)
  		goto err;
  	cxlmd->id = rc;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Davidlohr Bueso
Quoted 7 lines · On Wed, 8 Feb 2023 10:19:44 -0800 Davidlohr Bueso <[email protected]> wrote:

For ID allocations we want 0-(max-1), ie: smatch complains:

error: Calling ida_alloc_range() with a 'max' argument which is a power of 2. -1 missing?

Correct this and also replace the call to use the max() flavor instead.

I'm not sure I follow the smatch error always applying, but definitely suspicious here

Quoted 17 lines
---
 drivers/cxl/core/memdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/memdev.c +1 -1
index a74a93310d26..12bd9ddaba22 100644
@@ -242,7 +242,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
 	if (!cxlmd)
 		return ERR_PTR(-ENOMEM);
 
-	rc = ida_alloc_range(&cxl_memdev_ida, 0, CXL_MEM_MAX_DEVS, GFP_KERNEL);
+	rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL);
 	if (rc < 0)
 		goto err;
 	cxlmd->id = rc;
author maintainer
#3 lore raw
Quoted 1 line · Jonathan Cameron

I'm not sure I follow the smatch error always applying, but definitely suspicious here

Just to be clear, I don't believe smatch (or any tool for that matter) ough to "always apply". Smatch is well known for having its share of false positives.

Quoted 1 line

Thanks!

#4 lore raw
In reply to Davidlohr Bueso
Quoted 27 lines · Davidlohr Bueso

For ID allocations we want 0-(max-1), ie: smatch complains:

error: Calling ida_alloc_range() with a 'max' argument which is a power of 2. -1 missing?

Correct this and also replace the call to use the max() flavor instead.

---
 drivers/cxl/core/memdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/memdev.c +1 -1
index a74a93310d26..12bd9ddaba22 100644
@@ -242,7 +242,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
 	if (!cxlmd)
 		return ERR_PTR(-ENOMEM);
 
-	rc = ida_alloc_range(&cxl_memdev_ida, 0, CXL_MEM_MAX_DEVS, GFP_KERNEL);
+	rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL);
 	if (rc < 0)
 		goto err;
 	cxlmd->id = rc;
Signature · 1 line
2.39.1

Looks good to me.