Skip to contentSkip to conversation

staging: lustre: libcfs: Use swap() in cfs_hash_bd_order()

PATCH Superseded Amitoj Kaur Chawla 2 participants 5 messages Feb 23, 2016 1 message not in the archive Staging

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/3 staging: lustre: libcfs: Use swap() in cfs_hash_bd_order()

Use swap() function instead of using a temporary variable for swapping two variables.

The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@@
type T;
T a,b,c;
@@
- a = b;
- b = c;
- c = a;
+ swap(b, c);
//<smpl>

---
Changes in v2:
-Divided one patch into a series.

 drivers/staging/lustre/lustre/libcfs/hash.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/libcfs/hash.c +2 -6
index 5e2afe4..c8d8bc8 100644
@@ -803,12 +803,8 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2)
 	if (rc == 0) {
 		bd2->bd_bucket = NULL;
 
-	} else if (rc > 0) { /* swab bd1 and bd2 */
-		struct cfs_hash_bd tmp;
-
-		tmp = *bd2;
-		*bd2 = *bd1;
-		*bd1 = tmp;
+	} else if (rc > 0) {
+		swap(*bd1, *bd2); /* swab bd1 and bd2 */
 	}
 }
 
Signature · 1 line
1.9.1
#2 lore raw
Quoted 29 lines · Amitoj Kaur Chawla

Use swap() function instead of using a temporary variable for swapping two variables.

The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@@
type T;
T a,b,c;
@@
- a = b;
- b = c;
- c = a;
+ swap(b, c);
//<smpl>

---
Changes in v2:
-Divided one patch into a series.

 drivers/staging/lustre/lustre/libcfs/hash.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/libcfs/hash.c +0 -0
index 5e2afe4..c8d8bc8 100644
@@ -803,12 +803,8 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2)
 	if (rc == 0) {

drivers/staging/lustre/lustre/libcfs/hash.c cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2) · line 807

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/hash.c +2 -6
 		bd2->bd_bucket = NULL;
 
-	} else if (rc > 0) { /* swab bd1 and bd2 */
-		struct cfs_hash_bd tmp;
-
-		tmp = *bd2;
-		*bd2 = *bd1;
-		*bd1 = tmp;
+	} else if (rc > 0) {
+		swap(*bd1, *bd2); /* swab bd1 and bd2 */

I think it would be reasonable to fix the spelling mistake in the comment as well.

julia

Quoted 13 lines
drivers/staging/lustre/lustre/libcfs/hash.c +0 -0
 	}
 }
 
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/ab41303260243d22196ab846c092faac61ae6bf4.1456236436.git.amitoj1606%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#3 lore raw
Quoted 6 lines · Julia Lawall
Quoted 1 line

+ swap(*bd1, *bd2); /* swab bd1 and bd2 */

I think it would be reasonable to fix the spelling mistake in the comment as well.

julia

Oops. Didn't notice that :)
I'll send v3.

Amitoj

#4 lore raw

PATCH v2 2/3 staging: lustre: libcfs: Remove unnecessary braces

In reply to a message not in the archive

Removed unncessary braces from the if-else block to remove the following checkpatch.pl warning:
WARNING: braces {} are not necessary for any arm of this statement

---
Changes in v2:
-Divide one patch into a series.

 drivers/staging/lustre/lustre/libcfs/hash.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/libcfs/hash.c +2 -4
index c8d8bc8..b9bdb67 100644
@@ -800,12 +800,10 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2)
 	}
 
 	rc = cfs_hash_bd_compare(bd1, bd2);
-	if (rc == 0) {
+	if (rc == 0)
 		bd2->bd_bucket = NULL;
-
-	} else if (rc > 0) {
+	else if (rc > 0)
 		swap(*bd1, *bd2); /* swab bd1 and bd2 */
-	}
 }
 
 void
Signature · 1 line
1.9.1
#5 lore raw

PATCH v2 3/3 staging: lustre: libcfs: Remove comparison with zero

In reply to a message not in the archive

Replace comparison with zero with ! operator.

---
Changes in v2:
-Divide one patch into a series.

 drivers/staging/lustre/lustre/libcfs/hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/libcfs/hash.c +1 -1
index b9bdb67..a645f50 100644
@@ -800,7 +800,7 @@ cfs_hash_bd_order(struct cfs_hash_bd *bd1, struct cfs_hash_bd *bd2)
 	}
 
 	rc = cfs_hash_bd_compare(bd1, bd2);
-	if (rc == 0)
+	if (!rc)
 		bd2->bd_bucket = NULL;
 	else if (rc > 0)
 		swap(*bd1, *bd2); /* swab bd1 and bd2 */
Signature · 1 line
1.9.1