mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jes Sorensen <jes.sorensen@gmail.com>
To: Gioh Kim <gi-oh.kim@profitbricks.com>, NeilBrown <neilb@suse.com>
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wol <anthony@youngman.org.uk>
Subject: Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
Date: Thu, 30 Mar 2017 11:53:54 -0400	[thread overview]
Message-ID: <1f82bdbf-6b69-ce77-d989-6f375a9ff61b@gmail.com> (raw)
In-Reply-To: <20170330075209.GF17378@ws00837>

On 03/30/2017 03:52 AM, Gioh Kim wrote:
> On Thu, Mar 30, 2017 at 08:38:35AM +1100, NeilBrown wrote:
>> On Thu, Mar 30 2017, jes.sorensen@gmail.com wrote:
>>
>>> Gioh Kim <gi-oh.kim@profitbricks.com> writes:
>>>> Remove a boolean expression in switch condition
>>>> to prevent compile error of some compilers.
>>>
>>> Please be specific, which compile is unable to handle this?
>>>
>>>> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
>>>> ---
>>>>  mdadm.c | 6 +++---
>>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/mdadm.c b/mdadm.c
>>>> index 08ddcab..a98a051 100644
>>>> --- a/mdadm.c
>>>> +++ b/mdadm.c
>>>> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
>>>>  			rv |= SetAction(dv->devname, c->action);
>>>>  			continue;
>>>>  		}
>>>> -		switch(dv->devname[0] == '/') {
>>>> -			case 0:
>>>> +		switch(dv->devname[0]) {
>>>> +			default:
>>>>  				mdfd = open_dev(dv->devname);
>>>>  				if (mdfd >= 0) break;
>>>> -			case 1:
>>>> +			case '/':
>>>>  				mdfd = open_mddev(dv->devname, 1);
>>>>  		}
>>>>  		if (mdfd>=0) {
>>>
>>> While I agree the original code is ugly, I am not convinced your
>>> replacement is a lot prettier.
>>>
>>
>> Maybe
>>
>> 		if (dv->devname[0] == '/' ||
>> 		    (mdfd = open_dev(dv->devname)) < 0)
>> 				mdfd = open_mddev(dv->devname, 1);
>>
>> ??
>> NeilBrown
>
> Yes, the initial version I thought was:
>
> if (dev->devname[0] != '/')
>     mdfd = open_dev(dv->devname);
> if (dev->devname[0] == '/' || mdfd < 0)
>     mdfd = open_mddev(dv->devname, 1);
>
> But I thought you have a reason to use switch-case expression,
> so I kept switch-case.
> If you agree, I'll send v2 patch using if-expression.
>

I like this solution better, I much favor code that is more explicit in 
what it does. Request less brain capacity for me to read :)

Cheers,
Jes

  reply	other threads:[~2017-03-30 15:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-29  9:40 [PATCH 1/2] super1: replace hard-coded values with bit definitions Gioh Kim
2017-03-29  9:40 ` [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value" Gioh Kim
2017-03-29 15:47   ` jes.sorensen
2017-03-29 15:50     ` Gioh Kim
2017-03-29 21:38     ` NeilBrown
2017-03-30  7:52       ` Gioh Kim
2017-03-30 15:53         ` Jes Sorensen [this message]
2017-03-29 15:41 ` [PATCH 1/2] super1: replace hard-coded values with bit definitions jes.sorensen

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=1f82bdbf-6b69-ce77-d989-6f375a9ff61b@gmail.com \
    --to=jes.sorensen@gmail.com \
    --cc=anthony@youngman.org.uk \
    --cc=gi-oh.kim@profitbricks.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.com \
    /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

Powered by JetHome