erofs: clean up a loop
Subsystems (2)
PATCH 1/1 erofs: clean up a loop
It's easier to see what this loop is doing when the decrement is in the normal place.
--- fs/erofs/zdata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/zdata.c +2 -2
@@ -419,8 +419,8 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, {struct z_erofs_pcluster *const pcl = fe->pcl; -while (fe->icur >0 ) { -if (!cmpxchg (&pcl->compressed_bvecs[--fe->icur].page, +while (fe->icur--) { +if (!cmpxchg (&pcl->compressed_bvecs[fe->icur].page,NULL , bvec->page)) { pcl->compressed_bvecs[fe->icur] = *bvec;return true;
Signature · 1 line
2.35.1
Hi Dan,
Quoted 13 lines · Dan Carpenter
It's easier to see what this loop is doing when the decrement is in the normal place.
Signed-off-by Dan Carpenter <[email protected]>--- fs/erofs/zdata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/erofs/zdata.c +0
-0
fs/erofs/zdata.c static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, · line 422
Quoted 6 lines
fs/erofs/zdata.c +1
-2@@ -419,8 +419,8 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, {struct z_erofs_pcluster *const pcl = fe->pcl; - while (fe->icur > 0) { - if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page, +while (fe->icur--) {
Thanks for your patch!
Yet at a quick glance, on my side, that doesn't equal to be honest...
.. What we're trying to do here is to find a free slot for inplace i/o, but also need to leave fe->icur as 0 when going out the loop since z_erofs_try_inplace_io() can be called again the next time when attaching another page but it will overflow then...
Thanks,
Gao Xiang
Quoted 6 lines
fs/erofs/zdata.c +1
-0+if (!cmpxchg (&pcl->compressed_bvecs[fe->icur].page,NULL , bvec->page)) { pcl->compressed_bvecs[fe->icur] = *bvec;return true;Signature · 1 line
2.35.1
Quoted 27 lines · Gao Xiang
Hi Dan,
Quoted 13 lines · Dan Carpenter
It's easier to see what this loop is doing when the decrement is in the normal place.
Signed-off-by Dan Carpenter <[email protected]>--- fs/erofs/zdata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/erofs/zdata.c +0
-0fs/erofs/zdata.c static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, · line 422
Quoted 6 lines
fs/erofs/zdata.c +1
-2@@ -419,8 +419,8 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, {struct z_erofs_pcluster *const pcl = fe->pcl; - while (fe->icur > 0) { - if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page, +while (fe->icur--) {Thanks for your patch!
Yet at a quick glance, on my side, that doesn't equal to be honest...
Quoted 5 lines
.. What we're trying to do here is to find a free slot for inplace i/o, but also need to leave
fe->icuras 0 when going out the loop sincez_erofs_try_inplace_io()can be called again the next time when attaching another page but it will overflow then...
Ah. Sorry. I never thought about it being called twice in a row.
regards,
dan carpenter