aboutsummaryrefslogtreecommitdiff
path: root/drivers/cxl
diff options
context:
space:
mode:
authorDan Carpenter2022-08-01 13:20:12 +0300
committerDan Williams2022-08-01 12:12:33 -0700
commitc7e3548cac4a8a8bc1ad183cc7c7249463dff55f (patch)
treef288dd095c2354807dfbc116363c376d9baff822 /drivers/cxl
parent88ab1dde792aa6a3902e2a30929e00acc99d351a (diff)
cxl/region: prevent underflow in ways_to_cxl()
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> Link: https://lore.kernel.org/r/Yueo3NV2hFCXx1iV@kili [djbw: fixup interleave_ways_store() to only accept unsigned input] Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/cxl')
-rw-r--r--drivers/cxl/core/region.c5
-rw-r--r--drivers/cxl/cxl.h2
2 files changed, 4 insertions, 3 deletions
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index c80932bca667..516ba7e2de81 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -319,10 +319,11 @@ static ssize_t interleave_ways_store(struct device *dev,
struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
struct cxl_region *cxlr = to_cxl_region(dev);
struct cxl_region_params *p = &cxlr->params;
- int rc, val, save;
+ unsigned int val, save;
+ int rc;
u8 iw;
- rc = kstrtoint(buf, 0, &val);
+ rc = kstrtouint(buf, 0, &val);
if (rc)
return rc;
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;