* [PATCH] xfs_quota: drop pointless qsort cmp casting
@ 2021-02-02 19:08 Eric Sandeen
2021-02-02 19:16 ` Darrick J. Wong
2021-02-02 19:16 ` Christoph Hellwig
0 siblings, 2 replies; 3+ messages in thread
From: Eric Sandeen @ 2021-02-02 19:08 UTC (permalink / raw)
To: xfs
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.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/quota/quot.c b/quota/quot.c
index 8544aef6..9e8086c4 100644
--- a/quota/quot.c
+++ b/quota/quot.c
@@ -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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs_quota: drop pointless qsort cmp casting
2021-02-02 19:08 [PATCH] xfs_quota: drop pointless qsort cmp casting Eric Sandeen
@ 2021-02-02 19:16 ` Darrick J. Wong
2021-02-02 19:16 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2021-02-02 19:16 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs
On Tue, Feb 02, 2021 at 01:08:31PM -0600, Eric Sandeen wrote:
> 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.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Looks simple enough,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
>
> diff --git a/quota/quot.c b/quota/quot.c
> index 8544aef6..9e8086c4 100644
> --- a/quota/quot.c
> +++ b/quota/quot.c
> @@ -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;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs_quota: drop pointless qsort cmp casting
2021-02-02 19:08 [PATCH] xfs_quota: drop pointless qsort cmp casting Eric Sandeen
2021-02-02 19:16 ` Darrick J. Wong
@ 2021-02-02 19:16 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-02-02 19:16 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs
On Tue, Feb 02, 2021 at 01:08:31PM -0600, Eric Sandeen wrote:
> - 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;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-02 19:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 19:08 [PATCH] xfs_quota: drop pointless qsort cmp casting Eric Sandeen
2021-02-02 19:16 ` Darrick J. Wong
2021-02-02 19:16 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.