diff mbox series

memory: omap-gpmc: Fix a couple off by ones

Message ID 20200825104707.GB278587@mwanda (mailing list archive)
State New, archived
Headers show
Series memory: omap-gpmc: Fix a couple off by ones | expand

Commit Message

Dan Carpenter Aug. 25, 2020, 10:47 a.m. UTC
These comparisons should be >= instead of > to prevent reading one
element beyond the end of the gpmc_cs[] array.

Fixes: cdd6928c589a ("ARM: OMAP2+: Add device-tree support for NOR flash")
Fixes: f37e4580c409 ("ARM: OMAP2: Dynamic allocator for GPMC memory space")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/memory/omap-gpmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Roger Quadros Aug. 26, 2020, 1:05 p.m. UTC | #1
On 25/08/2020 13:47, Dan Carpenter wrote:
> These comparisons should be >= instead of > to prevent reading one
> element beyond the end of the gpmc_cs[] array.
> 
> Fixes: cdd6928c589a ("ARM: OMAP2+: Add device-tree support for NOR flash")
> Fixes: f37e4580c409 ("ARM: OMAP2: Dynamic allocator for GPMC memory space")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Roger Quadros <rogerq@ti.com>

> ---
>   drivers/memory/omap-gpmc.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c
> index cd9e80748591..fd245b82163a 100644
> --- a/drivers/memory/omap-gpmc.c
> +++ b/drivers/memory/omap-gpmc.c
> @@ -989,7 +989,7 @@ static int gpmc_cs_remap(int cs, u32 base)
>   	int ret;
>   	u32 old_base, size;
>   
> -	if (cs > gpmc_cs_num) {
> +	if (cs >= gpmc_cs_num) {
>   		pr_err("%s: requested chip-select is disabled\n", __func__);
>   		return -ENODEV;
>   	}
> @@ -1024,7 +1024,7 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
>   	struct resource *res = &gpmc->mem;
>   	int r = -1;
>   
> -	if (cs > gpmc_cs_num) {
> +	if (cs >= gpmc_cs_num) {
>   		pr_err("%s: requested chip-select is disabled\n", __func__);
>   		return -ENODEV;
>   	}
> 

cheers,
-roger
Krzysztof Kozlowski Aug. 26, 2020, 6:22 p.m. UTC | #2
On Tue, Aug 25, 2020 at 01:47:07PM +0300, Dan Carpenter wrote:
> These comparisons should be >= instead of > to prevent reading one
> element beyond the end of the gpmc_cs[] array.
> 
> Fixes: cdd6928c589a ("ARM: OMAP2+: Add device-tree support for NOR flash")
> Fixes: f37e4580c409 ("ARM: OMAP2: Dynamic allocator for GPMC memory space")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/memory/omap-gpmc.c | 4 ++--

Thanks, applied.

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c
index cd9e80748591..fd245b82163a 100644
--- a/drivers/memory/omap-gpmc.c
+++ b/drivers/memory/omap-gpmc.c
@@ -989,7 +989,7 @@  static int gpmc_cs_remap(int cs, u32 base)
 	int ret;
 	u32 old_base, size;
 
-	if (cs > gpmc_cs_num) {
+	if (cs >= gpmc_cs_num) {
 		pr_err("%s: requested chip-select is disabled\n", __func__);
 		return -ENODEV;
 	}
@@ -1024,7 +1024,7 @@  int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
 	struct resource *res = &gpmc->mem;
 	int r = -1;
 
-	if (cs > gpmc_cs_num) {
+	if (cs >= gpmc_cs_num) {
 		pr_err("%s: requested chip-select is disabled\n", __func__);
 		return -ENODEV;
 	}