diff mbox series

[2/3] cxl/region: prevent underflow in ways_to_cxl()

Message ID Yueo3NV2hFCXx1iV@kili
State Accepted
Commit c7e3548cac4a8a8bc1ad183cc7c7249463dff55f
Headers show
Series [1/3] cxl/region: uninitialized variable in alloc_hpa() | expand

Commit Message

Dan Carpenter Aug. 1, 2022, 10:20 a.m. UTC
The "ways" variable comes from the user.  The ways_to_cxl() function
has an upper bound but it doesn't check for negatives.  Make
the "ways" variable an unsigned int to fix this bug.

Fixes: 80d10a6cee05 ("cxl/region: Add interleave geometry attributes")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/cxl/cxl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dan Williams Aug. 1, 2022, 7:09 p.m. UTC | #1
Dan Carpenter wrote:
> The "ways" variable comes from the user.  The ways_to_cxl() function
> has an upper bound but it doesn't check for negatives.  Make
> the "ways" variable an unsigned int to fix this bug.
> 
> Fixes: 80d10a6cee05 ("cxl/region: Add interleave geometry attributes")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/cxl/cxl.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index 75674400cc8d..969953ce2609 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -102,7 +102,7 @@ static inline int granularity_to_cxl(int g, u16 *ig)
>  	return 0;
>  }
>  
> -static inline int ways_to_cxl(int ways, u8 *iw)
> +static inline int ways_to_cxl(unsigned int ways, u8 *iw)
>  {
>  	if (ways > 16)
>  		return -EINVAL;

Looks good, I'll go ahead and update interleave_ways_store() to also not
allow negative values.
diff mbox series

Patch

diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 75674400cc8d..969953ce2609 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -102,7 +102,7 @@  static inline int granularity_to_cxl(int g, u16 *ig)
 	return 0;
 }
 
-static inline int ways_to_cxl(int ways, u8 *iw)
+static inline int ways_to_cxl(unsigned int ways, u8 *iw)
 {
 	if (ways > 16)
 		return -EINVAL;