Skip to contentSkip to conversation

erofs: clean up a loop

PATCH In review Dan Carpenter 2 participants 3 messages Jul 18, 2022

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

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
index 601cfcb07c50..2691100eb231 100644
@@ -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
#1 lore raw

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.

---
 fs/erofs/zdata.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/zdata.c +0 -0
index 601cfcb07c50..2691100eb231 100644

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
#2 lore raw
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.

---
 fs/erofs/zdata.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/zdata.c +0 -0
index 601cfcb07c50..2691100eb231 100644

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...

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->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...

Ah. Sorry. I never thought about it being called twice in a row.

regards,
dan carpenter