gpio_flash: fix the CPLB miss bug for gpio expanded flash
PATCH 1/1 gpio_flash: fix the CPLB miss bug for gpio expanded flash
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
--- drivers/mtd/maps/gpio-addr-flash.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
drivers/mtd/maps/gpio-addr-flash.c +28 -6
@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len))); -/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/**
@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len))); -/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; + +gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {
Signature · 1 line
1.7.9.5
+ Mike Frysinger
Hi Aaron,
I'm trying to judge the quality of your patch, but I'm very distracted from this by trying to figure out the original intent of this code. Perhaps Mike can comment.
Quoted 13 lines · Aaron Wu
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
Signed-off-by Aaron Wu <[email protected]>--- drivers/mtd/maps/gpio-addr-flash.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)drivers/mtd/maps/gpio-addr-flash.c +0
-0
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi · line 114
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len)));
What do you think of this BUG_ON()? AFAICT, the BUG_ON() predicate is provably false [1], at least whenever
from >= 0 && len >= 0 && state->win_size > 0.
Was the intent more like this?
BUG_ON((from + len - 1) / state->win_size != from / state->win_size);
If so, then it seems like maybe this patch is trying to address the case that was previously considered a BUG()?
In any case, if we can't figure out what the BUG_ON() really should have been, then maybe we should kill it and take something like your patch to fix the case you're looking at, Aaron.
Quoted 20 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/**
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, unsigned long to, · line 164
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len)));
Same here. I think the BUG_ON() condition is a no-op (always false).
Quoted 9 lines
drivers/mtd/maps/gpio-addr-flash.c +6
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; +
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, unsigned long to, · line 181
Quoted 10 lines
drivers/mtd/maps/gpio-addr-flash.c +7
-0+gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {
Brian
[1] If it was provably false, then I should be able to write out a proof! It relies on something like this:
If x >= 0 and y > 0, then x % y <= x.
Quoted 2 lines · Aaron Wu
(quoted diff) +0
-0@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {
[...]
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi · line 124
Quoted 2 lines
drivers/mtd/maps/gpio-addr-flash.c +2
-0+memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len);
And one nitpick: please put that stray comma on the previous line.
[...]
Thanks,
Brian
Hi Brian,
Thanks for your time and comments.
This patch originally intend to solve the issue that Flash operation address passed in from upper layer may exceed the maxim address boundary allowed by the window size defined by the gpio style of flash.
Take the read, memcpy_fromio for example, this address is described by (map->virt + (from % state->win_size) + this_len), where this_len varies in different situation. If the address do exceed the boundary then we repeat read to work around it.
I actually did not pay enough attention on the BUG_ON condition from Mike, I will check later and be back.
At last this patch fixed a customer reported issue so I suppose this "cross the boundary" bug do exits and this patch roughly fixed it.
Best regards,
Aaron
-----Original Message-----
From: Brian Norris [mailto:[email protected]]
Sent: Friday, August 01, 2014 2:35 PM
To: Wu, Aaron
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: Re: [PATCH] gpio_flash: fix the CPLB miss bug for gpio expanded flash
+ Mike Frysinger
Hi Aaron,
I'm trying to judge the quality of your patch, but I'm very distracted from this by trying to figure out the original intent of this code. Perhaps Mike can comment.
Quoted 14 lines · Aaron Wu
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
Signed-off-by Aaron Wu <[email protected]>--- drivers/mtd/maps/gpio-addr-flash.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)drivers/mtd/maps/gpio-addr-flash.c +0
-0
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, · line 114
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len)));
What do you think of this BUG_ON()? AFAICT, the BUG_ON() predicate is provably false [1], at least whenever
from >= 0 && len >= 0 && state->win_size > 0.
Was the intent more like this?
BUG_ON((from + len - 1) / state->win_size != from / state->win_size);
If so, then it seems like maybe this patch is trying to address the case that was previously considered a BUG()?
In any case, if we can't figure out what the BUG_ON() really should have been, then maybe we should kill it and take something like your patch to fix the case you're looking at, Aaron.
Quoted 20 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/**
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, · line 164
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len)));
Same here. I think the BUG_ON() condition is a no-op (always false).
Quoted 9 lines
drivers/mtd/maps/gpio-addr-flash.c +6
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; +
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, unsigned long to, · line 181
Quoted 10 lines
drivers/mtd/maps/gpio-addr-flash.c +7
-0+gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {
Brian
[1] If it was provably false, then I should be able to write out a proof! It relies on something like this:
If x >= 0 and y > 0, then x % y <= x.
Hi Brian and Mike,
AFAICT I agree with you, I think the BUG_ON is not likely to be executed, I'm OK with removing it, Mike, what's your idea.
And do you want me to make a new patch or make another patch to remove the BUG_ON and the "," issue if we can reach agreement on this issue?
Best regards,
Aaron
-----Original Message-----
From: Wu, Aaron
Sent: Friday, August 01, 2014 3:00 PM
To: 'Brian Norris'
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: RE: [PATCH] gpio_flash: fix the CPLB miss bug for gpio expanded flash
Hi Brian,
Thanks for your time and comments.
This patch originally intend to solve the issue that Flash operation address passed in from upper layer may exceed the maxim address boundary allowed by the window size defined by the gpio style of flash.
Take the read, memcpy_fromio for example, this address is described by (map->virt + (from % state->win_size) + this_len), where this_len varies in different situation. If the address do exceed the boundary then we repeat read to work around it.
I actually did not pay enough attention on the BUG_ON condition from Mike, I will check later and be back.
At last this patch fixed a customer reported issue so I suppose this "cross the boundary" bug do exits and this patch roughly fixed it.
Best regards,
Aaron
-----Original Message-----
From: Brian Norris [mailto:[email protected]]
Sent: Friday, August 01, 2014 2:35 PM
To: Wu, Aaron
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: Re: [PATCH] gpio_flash: fix the CPLB miss bug for gpio expanded flash
+ Mike Frysinger
Hi Aaron,
I'm trying to judge the quality of your patch, but I'm very distracted from this by trying to figure out the original intent of this code. Perhaps Mike can comment.
Quoted 14 lines · Aaron Wu
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
Signed-off-by Aaron Wu <[email protected]>--- drivers/mtd/maps/gpio-addr-flash.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)drivers/mtd/maps/gpio-addr-flash.c +0
-0
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, · line 114
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len)));
What do you think of this BUG_ON()? AFAICT, the BUG_ON() predicate is provably false [1], at least whenever
from >= 0 && len >= 0 && state->win_size > 0.
Was the intent more like this?
BUG_ON((from + len - 1) / state->win_size != from / state->win_size);
If so, then it seems like maybe this patch is trying to address the case that was previously considered a BUG()?
In any case, if we can't figure out what the BUG_ON() really should have been, then maybe we should kill it and take something like your patch to fix the case you're looking at, Aaron.
Quoted 20 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/**
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, · line 164
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len)));
Same here. I think the BUG_ON() condition is a no-op (always false).
Quoted 9 lines
drivers/mtd/maps/gpio-addr-flash.c +6
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; +
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, unsigned long to, · line 181
Quoted 10 lines
drivers/mtd/maps/gpio-addr-flash.c +7
-0+gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {
Brian
[1] If it was provably false, then I should be able to write out a proof! It relies on something like this:
If x >= 0 and y > 0, then x % y <= x.
Hi Aaron,
Please don't top post (like I'm doing right now). It makes it harder to follow what's actually being said.
And please *do* selectively quote (unlike me right now), so it's easy to see what you've responded to without too much other noise.
Mike hasn't been involved in MTD recently, so I don't fully expect an answer.
The BUG_ON() is certainly useless, so we should drop it.
It also seems like your patch is contradicting the other existing comments, so your patch should include more detailed explanation, and it should modify the comments appropriately. Particularly, you should note why this is no longer the case:
"We rely on the MTD layer to chunk up copies such that a single request here will not cross a window size. [...]"
So yes, you need a new patch.
Thanks,
Brian
Quoted 137 lines · Aaron
Hi Brian and Mike,
AFAICT I agree with you, I think the
BUG_ONis not likely to be executed, I'm OK with removing it, Mike, what's your idea.And do you want me to make a new patch or make another patch to remove the
BUG_ONand the "," issue if we can reach agreement on this issue?Best regards,
Aaron-----Original Message-----
From: Wu, Aaron
Sent: Friday, August 01, 2014 3:00 PM
To: 'Brian Norris'
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: RE: [PATCH]gpio_flash: fix the CPLB miss bug for gpio expanded flashHi Brian,
Thanks for your time and comments.
This patch originally intend to solve the issue that Flash operation address passed in from upper layer may exceed the maxim address boundary allowed by the window size defined by the gpio style of flash.
Take the read,
memcpy_fromiofor example, this address is described by (map->virt+ (from %state->win_size) +this_len), wherethis_lenvaries in different situation. If the address do exceed the boundary then we repeat read to work around it.I actually did not pay enough attention on the
BUG_ONcondition from Mike, I will check later and be back.At last this patch fixed a customer reported issue so I suppose this "cross the boundary" bug do exits and this patch roughly fixed it.
Best regards,
Aaron-----Original Message-----
From: Brian Norris [mailto:[email protected]]
Sent: Friday, August 01, 2014 2:35 PM
To: Wu, Aaron
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: Re: [PATCH]gpio_flash: fix the CPLB miss bug for gpio expanded flash+ Mike Frysinger
Hi Aaron,
I'm trying to judge the quality of your patch, but I'm very distracted from this by trying to figure out the original intent of this code. Perhaps Mike can comment.
Quoted 14 lines · Aaron Wu
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
Signed-off-by Aaron Wu <[email protected]>--- drivers/mtd/maps/gpio-addr-flash.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)drivers/mtd/maps/gpio-addr-flash.c +0
-0drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, · line 114
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len)));What do you think of this
BUG_ON()? AFAICT, theBUG_ON()predicate is provably false [1], at least wheneverfrom >= 0 && len >= 0 && state->win_size > 0.Was the intent more like this?
BUG_ON((from + len - 1) / state->win_size != from / state->win_size);If so, then it seems like maybe this patch is trying to address the case that was previously considered a
BUG()?In any case, if we can't figure out what the
BUG_ON()really should have been, then maybe we should kill it and take something like your patch to fix the case you're looking at, Aaron.Quoted 20 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/** drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, · line 164
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len)));Same here. I think the
BUG_ON()condition is a no-op (always false).Quoted 9 lines
drivers/mtd/maps/gpio-addr-flash.c +6
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; +drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, unsigned long to, · line 181
Quoted 10 lines
drivers/mtd/maps/gpio-addr-flash.c +7
-0+gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {Brian
[1] If it was provably false, then I should be able to write out a proof! It relies on something like this:
If x >= 0 and y > 0, then x % y <= x.
Quoted 27 lines
-----Original Message-----
From: Brian Norris [mailto:[email protected]]
Sent: Tuesday, August 05, 2014 4:29 AM
To: Wu, Aaron
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: Re: [PATCH]gpio_flash: fix the CPLB miss bug for gpio expanded flashHi Aaron,
Please don't top post (like I'm doing right now). It makes it harder to follow what's actually being said.
And please *do* selectively quote (unlike me right now), so it's easy to see what you've responded to without too much other noise.
Mike hasn't been involved in MTD recently, so I don't fully expect an answer.
The
BUG_ON()is certainly useless, so we should drop it.It also seems like your patch is contradicting the other existing comments, so your patch should include more detailed explanation, and it should modify the comments appropriately. Particularly, you should note why this is no longer the case:
Quoted 4 lines
"We rely on the MTD layer to chunk up copies such that a single request here will not cross a window size. [...]"
So yes, you need a new patch.
Hi Brian, I git send-email a newer version however I myself did not receive it from the mtd mail list so attach it here. Thanks.
Quoted 154 lines
Thanks,
BrianQuoted 3 lines · Aaron
Hi Brian and Mike,
AFAICT I agree with you, I think the
BUG_ONis not likely to be executed, I'mOK with removing it, Mike, what's your idea.
Quoted 2 lines
And do you want me to make a new patch or make another patch to
remove the
BUG_ONand the "," issue if we can reach agreement on this issue?Quoted 13 lines
Best regards,
Aaron-----Original Message-----
From: Wu, Aaron
Sent: Friday, August 01, 2014 3:00 PM
To: 'Brian Norris'
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: RE: [PATCH]gpio_flash: fix the CPLB miss bug for gpio expanded flashQuoted 5 lines
Hi Brian,
Thanks for your time and comments.
This patch originally intend to solve the issue that Flash operation address
passed in from upper layer may exceed the maxim address boundary allowed by the window size defined by the gpio style of flash.
Quoted 2 lines
Take the read,
memcpy_fromiofor example, this address is described by(
map->virt+ (from %state->win_size) +this_len), wherethis_lenvaries in different situation. If the address do exceed the boundary then we repeat read to work around it.Quoted 2 lines
I actually did not pay enough attention on the
BUG_ONcondition from Mike,I will check later and be back.
Quoted 2 lines
At last this patch fixed a customer reported issue so I suppose this "cross the
boundary" bug do exits and this patch roughly fixed it.
Quoted 13 lines
Best regards,
Aaron-----Original Message-----
From: Brian Norris [mailto:[email protected]]
Sent: Friday, August 01, 2014 2:35 PM
To: Wu, Aaron
Cc: [email protected]; [email protected]; Zhang, Sonic; Mike Frysinger
Subject: Re: [PATCH]gpio_flash: fix the CPLB miss bug for gpio expanded flashQuoted 5 lines
+ Mike Frysinger
Hi Aaron,
I'm trying to judge the quality of your patch, but I'm very distracted from this
by trying to figure out the original intent of this code.
Quoted 9 lines
Perhaps Mike can comment.
Quoted 6 lines · Aaron Wu
In this bug, the address operation range may exceed the window size defined by gpio expanded flash MTD partition.
Signed-off-by Aaron Wu <[email protected]>--- drivers/mtd/maps/gpio-addr-flash.c | 34++++++++++++++++++++++++++++------
Quoted 20 lines
Quoted 8 lines
1 file changed, 28 insertions(+), 6 deletions(-)drivers/mtd/maps/gpio-addr-flash.c +0
-0drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_from(struct map_info *map, · line 114
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -108,13 +108,24 @@ static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssi {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((from + len) % state->win_size <= (from + len)));What do you think of this
BUG_ON()? AFAICT, theBUG_ON()predicate is provably false [1], at least wheneverQuoted 7 lines
from >= 0 && len >= 0 && state->win_size > 0.Was the intent more like this?
BUG_ON((from + len - 1) / state->win_size != from / state->win_size);If so, then it seems like maybe this patch is trying to address the case that
was previously considered a
BUG()?Quoted 2 lines
In any case, if we can't figure out what the
BUG_ON()really should havebeen, then maybe we should kill it and take something like your patch to fix the case you're looking at, Aaron.
Quoted 50 lines
Quoted 21 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; + +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size) + , this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/** drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, · line 164
Quoted 8 lines
drivers/mtd/maps/gpio-addr-flash.c +1
-1@@ -147,13 +158,24 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len;/* BUG if operation crosses the win_size */ BUG_ON (!((to + len) % state->win_size <= (to + len)));Same here. I think the
BUG_ON()condition is a no-op (always false).Quoted 18 lines
drivers/mtd/maps/gpio-addr-flash.c +13
-2-/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; + +gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); + + len -= this_len; + to += this_len; + from += this_len; + } }
Quoted 8 lines
Quoted 5 lines
drivers/mtd/maps/gpio-addr-flash.c static void gf_copy_to(struct map_info *map, · line 180
Quoted 1 line
drivers/mtd/maps/gpio-addr-flash.c +0
-0static const char *const part_probe_types[] = {Brian
[1] If it was provably false, then I should be able to write out a proof! It relies
on something like this:
Quoted 2 lines
If x >= 0 and y > 0, then x % y <= x.
From e566b3919e52e246b980758383e1109fef788673 Mon Sep 17 00:00:00 2001
From: Aaron Wu <[email protected]>
Date: Tue, 5 Aug 2014 13:26:04 +0800
Subject: [PATCH] [mtd] gpio_flash: fix the bug in handling gpio flash
read/write when offset + len from mtd exceeds the window size
fix the bug in handling gpio flash read/write when offset + len from mtd exceeds the window size
--- drivers/mtd/maps/gpio-addr-flash.c | 43 ++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-)
drivers/mtd/maps/gpio-addr-flash.c +29 -14
@@ -99,22 +99,29 @@ static map_word gf_read(struct map_info *map, unsigned long ofs)* @from: flash offset to copy from * @len: how much to copy * -* We rely on the MTD layer to chunk up copies such that a single request here -* will not cross a window size. This allows us to only wiggle the GPIOs once -* before falling back to a normal memcpy. Reading the higher layer code shows -* that this is indeed the case, but add a BUG_ON() to future proof. +*Toggle the correct GPIO according to @from to enable the right flash bank, +*still the read offset plus len may execceds the actual Window size,when +*this happnes, reverts the value for multiple read until all data is read. */ static void gf_copy_from (struct map_info *map,void *to,unsigned long from,ssize_t len) {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, from); +int this_len; -/* BUG if operation crosses the win_size */ -BUG_ON (!((from + len) % state->win_size <= (from + len))); +while (len) { +if ((from % state->win_size) + len > state->win_size) + this_len = state->win_size - (from % state->win_size); +else + this_len = len; -/* operation does not cross the win_size, so one shot it */ -memcpy_fromio (to, map->virt + (from % state->win_size), len); +gf_set_gpios (state, from); +memcpy_fromio (to, map->virt + (from % state->win_size), + this_len); + len -= this_len; + from += this_len; + to += this_len; + } }/**
@@ -147,13 +154,21 @@ static void gf_copy_to(struct map_info *map, unsigned long to, {struct async_state *state =gf_map_info_to_state (map); -gf_set_gpios (state, to); +int this_len; + +while (len) { +if ((to % state->win_size) + len > state->win_size) + this_len = state->win_size - (to % state->win_size); +else + this_len = len; -/* BUG if operation crosses the win_size */ -BUG_ON (!((to + len) % state->win_size <= (to + len))); +gf_set_gpios (state, to); +memcpy_toio (map->virt + (to % state->win_size), from, len); -/* operation does not cross the win_size, so one shot it */ -memcpy_toio (map->virt + (to % state->win_size), from, len); + len -= this_len; + to += this_len; + from += this_len; + } }static const char *const part_probe_types[] = {
Signature · 1 line
1.7.9.5