public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jai Luthra <jai.luthra@ideasonboard.com>
Subject: Re: [PATCH 12/13] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
Date: Fri, 8 Nov 2024 13:27:25 +0200	[thread overview]
Message-ID: <Zy31nf_B-O_UTXSo@smile.fi.intel.com> (raw)
In-Reply-To: <f1cc3479-6c2e-40dd-8b78-671138f31d9d@ideasonboard.com>

On Fri, Nov 08, 2024 at 11:34:09AM +0200, Tomi Valkeinen wrote:
> On 10/10/2024 17:04, Andy Shevchenko wrote:
> > On Fri, Oct 04, 2024 at 05:46:43PM +0300, Tomi Valkeinen wrote:
> > > Add error handling to ub913_hw_init() using a new helper function,
> > > ub913_update_bits().

...

> > > +	ret = ub913_update_bits(priv, UB913_REG_GENERAL_CFG,
> > > +				UB913_REG_GENERAL_CFG_PCLK_RISING,
> > > +				priv->pclk_polarity_rising ?
> > > +					UB913_REG_GENERAL_CFG_PCLK_RISING :
> > > +					0);
> > 
> > So, you can use regmap_set_bits() / regmap_clear_bits() instead of this
> > ternary. It also gives one parameter less to the regmap calls.
> 
> True... But is it better?

In my opinion yes, because it's clearer on what's going on.
It has no (semi-)hidden choice, so code wise it most likely
will be the same at the end. So we are speaking only about
C-level of readability.

> if (priv->pclk_polarity_rising)
> 	ret = regmap_set_bits(priv->regmap, UB913_REG_GENERAL_CFG,
> 			      UB913_REG_GENERAL_CFG_PCLK_RISING);
> else
> 	ret = regmap_clear_bits(priv->regmap, UB913_REG_GENERAL_CFG,
> 				UB913_REG_GENERAL_CFG_PCLK_RISING);
> 
> The call itself is more readable there, but then again, as we're setting the
> value of a bit, I dislike having if/else with two calls for a single
> assignment.

FTR, there was an attempt to add _assign() in similar way how it's done with
bitops (set/clear/assign) to regmap, but had been rejected by Mark. I don't
remember detail why, though.

> Using FIELD_PREP is perhaps a bit better than the ternary:
> 
> ret = ub913_update_bits(priv, UB913_REG_GENERAL_CFG,
> 			UB913_REG_GENERAL_CFG_PCLK_RISING,
> 			FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
> 				   priv->pclk_polarity_rising));
> 
> I think I'd like best a function to set/clear a bitmask with a boolean:
> 
> ret = regmap_toggle_bits(priv->regmap, UB913_REG_GENERAL_CFG,
> 			 UB913_REG_GENERAL_CFG_PCLK_RISING,
> 			 priv->pclk_polarity_rising);
> 
> For now, I think I'll go with the FIELD_PREP() version. It's perhaps a bit
> better than the ternary.

Okay.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2024-11-08 11:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-04 14:46 [PATCH 00/13] media: i2c: ds90ub9xx: Misc fixes and improvements Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 01/13] media: i2c: ds90ub9x3: Fix extra fwnode_handle_put() Tomi Valkeinen
2024-10-10 14:02   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 02/13] media: i2c: ds90ub960: Fix UB9702 refclk register access Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 03/13] media: i2c: ds90ub960: Fix use of non-existing registers on UB9702 Tomi Valkeinen
2024-10-10 13:55   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 04/13] media: i2c: ds90ub960: Fix logging SP & EQ status only for UB9702 Tomi Valkeinen
2024-10-10 13:58   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 05/13] media: i2c: ds90ub960: Fix UB9702 VC map Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 06/13] media: i2c: ds90ub960: Add support for I2C_RX_ID Tomi Valkeinen
2024-10-10 13:59   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 07/13] media: i2c: ds90ub960: Add RGB24, RAW8 and RAW10 formats Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 08/13] media: i2c: ds90ub953: Clear CRC errors in ub953_log_status() Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 09/13] media: i2c: ds90ub960: Drop unused indirect block define Tomi Valkeinen
2024-10-04 14:46 ` [PATCH 10/13] media: i2c: ds90ub960: Reduce sleep in ub960_rxport_wait_locks() Tomi Valkeinen
2024-10-10 14:00   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 11/13] media: i2c: ds90ub960: Handle errors in ub960_log_status_ub960_sp_eq() Tomi Valkeinen
2024-10-10 14:02   ` Andy Shevchenko
2024-10-04 14:46 ` [PATCH 12/13] media: i2c: ds90ub913: Add error handling to ub913_hw_init() Tomi Valkeinen
2024-10-10 14:04   ` Andy Shevchenko
2024-11-08  9:34     ` Tomi Valkeinen
2024-11-08 11:27       ` Andy Shevchenko [this message]
2024-10-04 14:46 ` [PATCH 13/13] media: i2c: ds90ub953: Add error handling for i2c reads/writes Tomi Valkeinen
2024-10-10 14:06   ` Andy Shevchenko
2024-11-08  9:34     ` Tomi Valkeinen

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=Zy31nf_B-O_UTXSo@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jai.luthra@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tomi.valkeinen@ideasonboard.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