From: Neil Brown <neilb@suse.de>
To: Andre Noll <maan@systemlinux.org>
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH 2/8] md: Simplify sb_equal().
Date: Wed, 9 Jul 2008 08:54:16 +1000 [thread overview]
Message-ID: <18547.61464.526968.728138@notabene.brown> (raw)
In-Reply-To: message from Andre Noll on Sunday March 23
On Sunday March 23, maan@systemlinux.org wrote:
> The only caller of sb_equal() tests the return value against
> zero, so it's OK to return the negated return value of memcmp().
>
> Signed-off-by: Andre Noll <maan@systemlinux.org>
> ---
> drivers/md/md.c | 6 +-----
> 1 files changed, 1 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index c559b9e..58762dd 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -572,11 +572,7 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
> tmp1->nr_disks = 0;
> tmp2->nr_disks = 0;
>
> - if (memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4))
> - ret = 0;
> - else
> - ret = 1;
> -
> + ret = !memcmp(tmp1, tmp2, MD_SB_GENERIC_CONSTANT_WORDS * 4);
One of my pet hates is "!strcmp" and similarly "!memcmp".
memcmp doesn't return a "boolean", so testing it or its inverse
doesn't read well. I always compare the result with '0'. The
comparison operator used matches exactly how I want to compare the two
values.
So I've changed this to
ret = (memcmp(....) == 0).
NeilBrown
next prev parent reply other threads:[~2008-07-08 22:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 15:55 [PATCH 0/8] md: More patches for md.c Andre Noll
2008-03-23 15:09 ` [PATCH 1/8] md: Simplify uuid_equal() Andre Noll
2008-03-23 15:21 ` [PATCH 2/8] md: Simplify sb_equal() Andre Noll
2008-07-08 22:54 ` Neil Brown [this message]
2008-03-25 19:55 ` [PATCH 3/8] md: alloc_disk_sb(): Return proper error value Andre Noll
2008-03-25 20:38 ` [PATCH 4/8] md: analyze_sbs(): Fix potential NULL-pointer dereference Andre Noll
2008-07-08 23:09 ` Neil Brown
2008-03-26 0:25 ` [PATCH 5/8] md: Simplify restart_array() Andre Noll
2008-03-29 19:12 ` [PATCH 6/8] md: get_disk_info(): Don't convert between signed and unsigned and back Andre Noll
2008-04-05 13:54 ` [PATCH 7/8] md: update_size(): Remove useless variable "fit" Andre Noll
2008-07-08 23:08 ` Neil Brown
2008-07-09 9:14 ` Andre Noll
2008-07-09 9:39 ` Neil Brown
2008-04-25 18:20 ` [PATCH 8/8] md: Simplify update_size() Andre Noll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18547.61464.526968.728138@notabene.brown \
--to=neilb@suse.de \
--cc=linux-raid@vger.kernel.org \
--cc=maan@systemlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).