Skip to contentSkip to conversation

xfs_quota: drop pointless qsort cmp casting

PATCH In review Eric Sandeen 3 participants 3 messages Feb 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_quota: drop pointless qsort cmp casting

The function cast in this call to qsort is odd - we don't do it anywhere else, and it doesn't gain us anything or help in any way.

So remove it; since we are now passing void *p pointers in, locally use du_t *d pointers to refer to the du_t's in the compare function.

---

quota/quot.c +10 -8
index 8544aef6..9e8086c4 100644
@@ -173,16 +173,19 @@ quot_bulkstat_mount(
 
 static int
 qcompare(
-	du_t		*p1,
-	du_t		*p2)
+	const void	*p1,
+	const void	*p2)
 {
-	if (p1->blocks > p2->blocks)
+	du_t		*d1 = (struct du *)p1;
+	du_t		*d2 = (struct du *)p2;
+
+	if (d1->blocks > d2->blocks)
 		return -1;
-	if (p1->blocks < p2->blocks)
+	if (d1->blocks < d2->blocks)
 		return 1;
-	if (p1->id > p2->id)
+	if (d1->id > d2->id)
 		return 1;
-	else if (p1->id < p2->id)
+	else if (d1->id < d2->id)
 		return -1;
 	return 0;
 }
@@ -204,8 +207,7 @@ quot_report_mount_any_type(
 
 	fprintf(fp, _("%s (%s) %s:\n"),
 		mount->fs_name, mount->fs_dir, type_to_string(type));
-	qsort(dp, count, sizeof(dp[0]),
-		(int (*)(const void *, const void *))qcompare);
+	qsort(dp, count, sizeof(dp[0]), qcompare);
 	for (; dp < &dp[count]; dp++) {
 		if (dp->blocks == 0)
 			return;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Sandeen

The function cast in this call to qsort is odd - we don't do it anywhere else, and it doesn't gain us anything or help in any way.

So remove it; since we are now passing void *p pointers in, locally use du_t *d pointers to refer to the du_t's in the compare function.

Looks simple enough,

--D

Quoted 43 lines

---

quota/quot.c +10 -8
index 8544aef6..9e8086c4 100644
@@ -173,16 +173,19 @@ quot_bulkstat_mount(
 
 static int
 qcompare(
-	du_t		*p1,
-	du_t		*p2)
+	const void	*p1,
+	const void	*p2)
 {
-	if (p1->blocks > p2->blocks)
+	du_t		*d1 = (struct du *)p1;
+	du_t		*d2 = (struct du *)p2;
+
+	if (d1->blocks > d2->blocks)
 		return -1;
-	if (p1->blocks < p2->blocks)
+	if (d1->blocks < d2->blocks)
 		return 1;
-	if (p1->id > p2->id)
+	if (d1->id > d2->id)
 		return 1;
-	else if (p1->id < p2->id)
+	else if (d1->id < d2->id)
 		return -1;
 	return 0;
 }
@@ -204,8 +207,7 @@ quot_report_mount_any_type(
 
 	fprintf(fp, _("%s (%s) %s:\n"),
 		mount->fs_name, mount->fs_dir, type_to_string(type));
-	qsort(dp, count, sizeof(dp[0]),
-		(int (*)(const void *, const void *))qcompare);
+	qsort(dp, count, sizeof(dp[0]), qcompare);
 	for (; dp < &dp[count]; dp++) {
 		if (dp->blocks == 0)
 			return;
#2 lore raw
In reply to Eric Sandeen

quota/quot.c quot_bulkstat_mount( · line 180

Quoted 7 lines · Eric Sandeen
quota/quot.c +4 -2
-	du_t		*p2)
+	const void	*p1,
+	const void	*p2)
 {
-	if (p1->blocks > p2->blocks)
+	du_t		*d1 = (struct du *)p1;
+	du_t		*d2 = (struct du *)p2;

Do we even need the casts here? Shouldn't this be something like:

	const struct du		*d1 = p1;
	const struct du		*d2 = p2;