Linux CXL
 help / color / mirror / Atom feed
* [PATCH] cxl/mem: Correct full ID range allocation
@ 2023-02-08 18:19 Davidlohr Bueso
  2023-02-08 23:50 ` Dave Jiang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2023-02-08 18:19 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-cxl, dave

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] cxl/mem: Correct full ID range allocation
  2023-02-08 18:19 [PATCH] cxl/mem: Correct full ID range allocation Davidlohr Bueso
@ 2023-02-08 23:50 ` Dave Jiang
  2023-02-09 15:45 ` Jonathan Cameron
  2023-02-09 16:44 ` Dan Williams
  2 siblings, 0 replies; 5+ messages in thread
From: Dave Jiang @ 2023-02-08 23:50 UTC (permalink / raw)
  To: Davidlohr Bueso, dan.j.williams; +Cc: linux-cxl



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;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cxl/mem: Correct full ID range allocation
  2023-02-08 18:19 [PATCH] cxl/mem: Correct full ID range allocation Davidlohr Bueso
  2023-02-08 23:50 ` Dave Jiang
@ 2023-02-09 15:45 ` Jonathan Cameron
  2023-02-09 17:03   ` Davidlohr Bueso
  2023-02-09 16:44 ` Dan Williams
  2 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2023-02-09 15:45 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: dan.j.williams, linux-cxl

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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] cxl/mem: Correct full ID range allocation
  2023-02-08 18:19 [PATCH] cxl/mem: Correct full ID range allocation Davidlohr Bueso
  2023-02-08 23:50 ` Dave Jiang
  2023-02-09 15:45 ` Jonathan Cameron
@ 2023-02-09 16:44 ` Dan Williams
  2 siblings, 0 replies; 5+ messages in thread
From: Dan Williams @ 2023-02-09 16:44 UTC (permalink / raw)
  To: Davidlohr Bueso, dan.j.williams; +Cc: linux-cxl, dave

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] cxl/mem: Correct full ID range allocation
  2023-02-09 15:45 ` Jonathan Cameron
@ 2023-02-09 17:03   ` Davidlohr Bueso
  0 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2023-02-09 17:03 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: dan.j.williams, linux-cxl

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!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-09 17:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08 18:19 [PATCH] cxl/mem: Correct full ID range allocation Davidlohr Bueso
2023-02-08 23:50 ` Dave Jiang
2023-02-09 15:45 ` Jonathan Cameron
2023-02-09 17:03   ` Davidlohr Bueso
2023-02-09 16:44 ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox