Skip to contentSkip to conversation

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

PATCH Applied Dan Carpenter 3 participants 3 messages Aug 25, 2020 – Aug 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: omap-gpmc: Fix a couple off by ones

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")
---
 drivers/memory/omap-gpmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/omap-gpmc.c +2 -2
index cd9e80748591..fd245b82163a 100644
@@ -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;
 	}
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

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")
Quoted 19 lines
---
  drivers/memory/omap-gpmc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/omap-gpmc.c +1 -1
index cd9e80748591..fd245b82163a 100644
@@ -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;
  	}

drivers/memory/omap-gpmc.c int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) · line 1030

Quoted 8 lines
drivers/memory/omap-gpmc.c +1 -1
@@ -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

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
maintainer Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

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")
---
 drivers/memory/omap-gpmc.c | 4 ++--

Thanks, applied.

Best regards,
Krzysztof