cxl/mem: Correct full ID range allocation
Davidlohr Bueso
maintainerPATCH 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
@@ -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
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.Signed-off-by Davidlohr Bueso <[email protected]>
Quoted 17 lines
--- drivers/cxl/core/memdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/memdev.c +1
-1@@ -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;
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.Signed-off-by Davidlohr Bueso <[email protected]>
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@@ -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;
Davidlohr Bueso
maintainerQuoted 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
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
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.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/memdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/memdev.c +1
-1@@ -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.