devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: "Vaittinen, Matti" <Matti.Vaittinen@fi.rohmeurope.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Matti Vaittinen <mazziesaccount@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	Jagath Jog J <jagathjog1996@gmail.com>,
	Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
	Cosmin Tanislav <demonsingur@gmail.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v2 4/5] iio: accel: Support Kionix/ROHM KX022A accelerometer
Date: Fri, 14 Oct 2022 14:34:23 +0100	[thread overview]
Message-ID: <20221014143423.00000379@huawei.com> (raw)
In-Reply-To: <10c4663b-dd65-a545-786d-10aed6e6e5e9@fi.rohmeurope.com>


...

> >   
> >>>>>> +	if (en)
> >>>>>> +		return regmap_set_bits(data->regmap, KX022A_REG_CNTL,
> >>>>>> +				       KX022A_MASK_DRDY);  
> >>>>>
> >>>>> I would put redundant 'else' here to have them on the same column, but
> >>>>> it's pity we don't have regmap_assign_bits() API (or whatever name you
> >>>>> can come up with) to hide this kind of code.  
> >>>>
> >>>> Eh, you mean you would put else here even though we return from the if? And
> >>>> then put another return in else, and no return outside the if/else?
> >>>>
> >>>> I definitely don't like the idea.
> >>>>
> >>>> We could probably use regmap_update_bits and ternary but in my opinion that
> >>>> would be just much less obvious. I do like the use of set/clear bits which
> >>>> also makes the meaning / "polarity" of bits really clear.  
> >>>
> >>> The idea behind is simple (and note that I'm usually on the side of _removing_
> >>> redundancy)
> >>>
> >>> 	if (en)
> >>> 		return regmap_set_bits(data->regmap, KX022A_REG_CNTL,
> >>> 				       KX022A_MASK_DRDY);
> >>> 	else
> >>> 		return regmap_clear_bits(data->regmap, KX022A_REG_CNTL,
> >>> 					 ...
> >>>
> >>> Because the branches are semantically tighten to each other. But it's not
> >>> a big deal to me.  
> >>
> >> What I do not really like in above example is that we never reach the
> >> end of function body.  
> > 
> > What do you mean by that? Compiler does warn or what?  
> 
> I don't know if compiler warns about it as I didn't test it. Now that 
> you mentioned it, I think I have seen such warnings from a compiler or 
> some static analyzer (klocwork?) in the past though. What I mean is that:
> 
> int foo()
> {
> 	if () {
> 		...
> 		return 1;
> 	} else {
> 		...
> 		return 2;
> 	}
> }
> 

For reference, this is the one I'd write if both options are good
(or both are bad) and we don't need to worry about reducing indent
for readability.

However, I long since decided this was trivial enough not to
comment on it in the code of others!

> construct makes mistakes like:
> 
> int foo()
> {
> 	if () {
> 		...
> 		return 1;
> 	} else {
> 		...
> 		return 2;
> 	}
> 
> 	...
> 
> 	return 0;
> }

That should given unreachable code warning unless you've really managed
to confuse the compiler  / static analysis tooling.

> 
> easy to make. When one uses:
> 
> int foo()
> {
> 	if () {
> 		...
> 		return 1;
> 	}
> 
> 	...
> 	return 2;
> }
> 
> to begin with there is zero room for such confusion.
> 
> >   
> >> It is against the expectation - and adding the
> >> else has no real meaning when if returns. I actually think that
> >> checkpatch could even warn about that construct.  
> > 
> > No way we ever accept such a thing for checkpatch because it's subjective  
> 
> Eh. Are you telling me that there is no subjective stuff in checkpatch? ;)
> 
> > (very dependant on the code piece). OTOH the proposed pattern is used in
> > many places and left like that in places where I cleaned up the 'else',
> > to leave the semantic tights with the above lines).
> >   
> >>>>>> +	return regmap_clear_bits(data->regmap, KX022A_REG_CNTL,
> >>>>>> +				 KX022A_MASK_DRDY);  
> > 
> > I see that we have a strong disagreement here. I leave it to maintainers.  
> 
> 
> Okay, let's hear what others have to say here.

Non answer above ;)

Time for the old "Don't let perfect be the enemy of good!"


> 
> Thanks for all the input this far.
> 
> Best Regards
> 	-- Matti
> 


  reply	other threads:[~2022-10-14 13:34 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 14:35 [RFC PATCH v2 0/5] iio: Support ROHM/Kionix kx022a Matti Vaittinen
2022-10-06 14:36 ` [RFC PATCH v2 1/5] regulator: Add devm helpers for get and enable Matti Vaittinen
2022-10-06 16:17   ` Andy Shevchenko
2022-10-09 12:24     ` Jonathan Cameron
2022-10-10  6:11       ` Andy Shevchenko
2022-10-10  9:24       ` Matti Vaittinen
2022-10-14 12:42         ` Jonathan Cameron
2022-10-10  4:13     ` Matti Vaittinen
2022-10-10  6:12       ` Andy Shevchenko
2022-10-06 14:37 ` [RFC PATCH v2 2/5] " Matti Vaittinen
2022-10-06 14:37 ` [RFC PATCH v2 3/5] dt-bindings: iio: Add KX022A accelerometer Matti Vaittinen
2022-10-06 15:23   ` Krzysztof Kozlowski
2022-10-06 15:32     ` Matti Vaittinen
2022-10-09 12:27       ` Jonathan Cameron
2022-10-10  9:28         ` Matti Vaittinen
2022-10-06 14:38 ` [RFC PATCH v2 4/5] iio: accel: Support Kionix/ROHM " Matti Vaittinen
2022-10-06 18:32   ` Andy Shevchenko
2022-10-07  7:04     ` Joe Perches
2022-10-07  9:22       ` Andy Shevchenko
2022-10-07  9:23       ` Andy Shevchenko
2022-10-09 12:33     ` Jonathan Cameron
2022-10-10  6:15       ` Andy Shevchenko
2022-10-11  9:10         ` Vaittinen, Matti
2022-10-14 13:22           ` Jonathan Cameron
2022-10-18 11:27             ` Matti Vaittinen
2022-10-18 12:42               ` Andy Shevchenko
2022-10-10  9:12     ` Matti Vaittinen
2022-10-10 11:58       ` Andy Shevchenko
2022-10-10 13:20         ` Vaittinen, Matti
2022-10-10 14:09           ` Andy Shevchenko
2022-10-11  6:56             ` Vaittinen, Matti
2022-10-14 13:34               ` Jonathan Cameron [this message]
2022-10-12  7:40           ` Matti Vaittinen
2022-10-14 13:42             ` Jonathan Cameron
2022-10-18 11:10               ` Matti Vaittinen
2022-10-24 16:41                 ` Jonathan Cameron
2022-10-06 14:38 ` [RFC PATCH v2 5/5] MAINTAINERS: Add KX022A maintainer entry Matti Vaittinen
2022-10-09 12:38   ` Jonathan Cameron
2022-10-10  9:31     ` Matti Vaittinen

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=20221014143423.00000379@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=Matti.Vaittinen@fi.rohmeurope.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=demonsingur@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jagathjog1996@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=nikita.yoush@cogentembedded.com \
    --cc=robh+dt@kernel.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).