diff mbox series

cxl/mem: Correct full ID range allocation

Message ID 20230208181944.240261-1-dave@stgolabs.net
State Accepted
Commit d874297bc7c8bb69f9fcbe6422ac5623c5897977
Headers show
Series cxl/mem: Correct full ID range allocation | expand

Commit Message

Davidlohr Bueso Feb. 8, 2023, 6:19 p.m. UTC
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 <dave@stgolabs.net>
---
 drivers/cxl/core/memdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dave Jiang Feb. 8, 2023, 11:50 p.m. UTC | #1
On 2/8/23 11:19 AM, Davidlohr Bueso 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 <dave@stgolabs.net>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>   drivers/cxl/core/memdev.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index a74a93310d26..12bd9ddaba22 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -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;
Jonathan Cameron Feb. 9, 2023, 3:45 p.m. UTC | #2
On Wed,  8 Feb 2023 10:19:44 -0800
Davidlohr Bueso <dave@stgolabs.net> 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 <dave@stgolabs.net>

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

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/cxl/core/memdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index a74a93310d26..12bd9ddaba22 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -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;
Dan Williams Feb. 9, 2023, 4:44 p.m. UTC | #3
Davidlohr Bueso 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 <dave@stgolabs.net>
> ---
>  drivers/cxl/core/memdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index a74a93310d26..12bd9ddaba22 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -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;
> -- 
> 2.39.1
> 

Looks good to me.
Davidlohr Bueso Feb. 9, 2023, 5:03 p.m. UTC | #4
On Thu, 09 Feb 2023, Jonathan Cameron wrote:

>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.

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

Thanks!
diff mbox series

Patch

diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index a74a93310d26..12bd9ddaba22 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -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;