All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-i2c@vger.kernel.org
Cc: Tero Kristo <t-kristo@ti.com>,
	preid@electromag.com.au, Keerthy <j-keerthy@ti.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-renesas-soc@vger.kernel.org,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Stefan Lengfeld <contact@stefanchrist.eu>,
	linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH 3/4] i2c: core: use I2C locking behaviour also for SMBUS
Date: Thu, 20 Sep 2018 19:31:19 +0200	[thread overview]
Message-ID: <e31d69ed-d849-db98-00c2-27d489a2dac1@axentia.se> (raw)
In-Reply-To: <20180920161423.13990-4-wsa+renesas@sang-engineering.com>

On 2018-09-20 18:14, Wolfram Sang wrote:
> If I2C transfers are executed in atomic contexts, trylock is used
> instead of lock. This behaviour was missing for SMBUS, although a lot of
> transfers are of SMBUS type, either emulated or direct. So, factor out
> the locking routine into a helper and use it for I2C and SMBUS.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Is it ok with static analyzers to "hide" the locking in helpers like
this? Will it not be harder for them to "see" what's going on? But I
don't think we have any annotations anyway, so...

Acked-by: Peter Rosin <peda@axentia.se>


> ---
>  drivers/i2c/i2c-core-base.c  | 11 +++--------
>  drivers/i2c/i2c-core-smbus.c |  7 ++++++-
>  drivers/i2c/i2c-core.h       | 12 ++++++++++++
>  3 files changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 799776c6d421..904b4d2ebefa 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1943,14 +1943,9 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
>  	 *    one (discarding status on the second message) or errno
>  	 *    (discarding status on the first one).
>  	 */
> -	if (in_atomic() || irqs_disabled()) {
> -		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
> -		if (!ret)
> -			/* I2C activity is ongoing. */
> -			return -EAGAIN;
> -	} else {
> -		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> -	}
> +	ret = __i2c_lock_bus_helper(adap);
> +	if (ret)
> +		return ret;
>  
>  	ret = __i2c_transfer(adap, msgs, num);
>  	i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
> index 9cd66cabb84f..dbb46edb8e02 100644
> --- a/drivers/i2c/i2c-core-smbus.c
> +++ b/drivers/i2c/i2c-core-smbus.c
> @@ -20,6 +20,8 @@
>  #include <linux/i2c-smbus.h>
>  #include <linux/slab.h>
>  
> +#include "i2c-core.h"
> +
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/smbus.h>
>  
> @@ -530,7 +532,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  {
>  	s32 res;
>  
> -	i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
> +	res = __i2c_lock_bus_helper(adapter);
> +	if (res)
> +		return res;
> +
>  	res = __i2c_smbus_xfer(adapter, addr, flags, read_write,
>  			       command, protocol, data);
>  	i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
> index 37576f50fe20..6e98aa811980 100644
> --- a/drivers/i2c/i2c-core.h
> +++ b/drivers/i2c/i2c-core.h
> @@ -29,6 +29,18 @@ extern int		__i2c_first_dynamic_bus_num;
>  
>  int i2c_check_7bit_addr_validity_strict(unsigned short addr);
>  
> +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
> +{
> +	int ret = 0;
> +
> +	if (in_atomic() || irqs_disabled())
> +		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN;
> +	else
> +		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> +
> +	return ret;
> +}
> +
>  #ifdef CONFIG_ACPI
>  const struct acpi_device_id *
>  i2c_acpi_match_device(const struct acpi_device_id *matches,
> 

WARNING: multiple messages have this Message-ID (diff)
From: Peter Rosin <peda@axentia.se>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-i2c@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	Stefan Lengfeld <contact@stefanchrist.eu>,
	preid@electromag.com.au, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Keerthy <j-keerthy@ti.com>,
	Tero Kristo <t-kristo@ti.com>,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [RFC PATCH 3/4] i2c: core: use I2C locking behaviour also for SMBUS
Date: Thu, 20 Sep 2018 19:31:19 +0200	[thread overview]
Message-ID: <e31d69ed-d849-db98-00c2-27d489a2dac1@axentia.se> (raw)
In-Reply-To: <20180920161423.13990-4-wsa+renesas@sang-engineering.com>

On 2018-09-20 18:14, Wolfram Sang wrote:
> If I2C transfers are executed in atomic contexts, trylock is used
> instead of lock. This behaviour was missing for SMBUS, although a lot of
> transfers are of SMBUS type, either emulated or direct. So, factor out
> the locking routine into a helper and use it for I2C and SMBUS.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Is it ok with static analyzers to "hide" the locking in helpers like
this? Will it not be harder for them to "see" what's going on? But I
don't think we have any annotations anyway, so...

Acked-by: Peter Rosin <peda@axentia.se>


> ---
>  drivers/i2c/i2c-core-base.c  | 11 +++--------
>  drivers/i2c/i2c-core-smbus.c |  7 ++++++-
>  drivers/i2c/i2c-core.h       | 12 ++++++++++++
>  3 files changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 799776c6d421..904b4d2ebefa 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1943,14 +1943,9 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
>  	 *    one (discarding status on the second message) or errno
>  	 *    (discarding status on the first one).
>  	 */
> -	if (in_atomic() || irqs_disabled()) {
> -		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
> -		if (!ret)
> -			/* I2C activity is ongoing. */
> -			return -EAGAIN;
> -	} else {
> -		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> -	}
> +	ret = __i2c_lock_bus_helper(adap);
> +	if (ret)
> +		return ret;
>  
>  	ret = __i2c_transfer(adap, msgs, num);
>  	i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
> index 9cd66cabb84f..dbb46edb8e02 100644
> --- a/drivers/i2c/i2c-core-smbus.c
> +++ b/drivers/i2c/i2c-core-smbus.c
> @@ -20,6 +20,8 @@
>  #include <linux/i2c-smbus.h>
>  #include <linux/slab.h>
>  
> +#include "i2c-core.h"
> +
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/smbus.h>
>  
> @@ -530,7 +532,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  {
>  	s32 res;
>  
> -	i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
> +	res = __i2c_lock_bus_helper(adapter);
> +	if (res)
> +		return res;
> +
>  	res = __i2c_smbus_xfer(adapter, addr, flags, read_write,
>  			       command, protocol, data);
>  	i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
> index 37576f50fe20..6e98aa811980 100644
> --- a/drivers/i2c/i2c-core.h
> +++ b/drivers/i2c/i2c-core.h
> @@ -29,6 +29,18 @@ extern int		__i2c_first_dynamic_bus_num;
>  
>  int i2c_check_7bit_addr_validity_strict(unsigned short addr);
>  
> +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
> +{
> +	int ret = 0;
> +
> +	if (in_atomic() || irqs_disabled())
> +		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN;
> +	else
> +		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> +
> +	return ret;
> +}
> +
>  #ifdef CONFIG_ACPI
>  const struct acpi_device_id *
>  i2c_acpi_match_device(const struct acpi_device_id *matches,
> 

WARNING: multiple messages have this Message-ID (diff)
From: peda@axentia.se (Peter Rosin)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 3/4] i2c: core: use I2C locking behaviour also for SMBUS
Date: Thu, 20 Sep 2018 19:31:19 +0200	[thread overview]
Message-ID: <e31d69ed-d849-db98-00c2-27d489a2dac1@axentia.se> (raw)
In-Reply-To: <20180920161423.13990-4-wsa+renesas@sang-engineering.com>

On 2018-09-20 18:14, Wolfram Sang wrote:
> If I2C transfers are executed in atomic contexts, trylock is used
> instead of lock. This behaviour was missing for SMBUS, although a lot of
> transfers are of SMBUS type, either emulated or direct. So, factor out
> the locking routine into a helper and use it for I2C and SMBUS.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Is it ok with static analyzers to "hide" the locking in helpers like
this? Will it not be harder for them to "see" what's going on? But I
don't think we have any annotations anyway, so...

Acked-by: Peter Rosin <peda@axentia.se>


> ---
>  drivers/i2c/i2c-core-base.c  | 11 +++--------
>  drivers/i2c/i2c-core-smbus.c |  7 ++++++-
>  drivers/i2c/i2c-core.h       | 12 ++++++++++++
>  3 files changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 799776c6d421..904b4d2ebefa 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1943,14 +1943,9 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
>  	 *    one (discarding status on the second message) or errno
>  	 *    (discarding status on the first one).
>  	 */
> -	if (in_atomic() || irqs_disabled()) {
> -		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
> -		if (!ret)
> -			/* I2C activity is ongoing. */
> -			return -EAGAIN;
> -	} else {
> -		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> -	}
> +	ret = __i2c_lock_bus_helper(adap);
> +	if (ret)
> +		return ret;
>  
>  	ret = __i2c_transfer(adap, msgs, num);
>  	i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
> index 9cd66cabb84f..dbb46edb8e02 100644
> --- a/drivers/i2c/i2c-core-smbus.c
> +++ b/drivers/i2c/i2c-core-smbus.c
> @@ -20,6 +20,8 @@
>  #include <linux/i2c-smbus.h>
>  #include <linux/slab.h>
>  
> +#include "i2c-core.h"
> +
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/smbus.h>
>  
> @@ -530,7 +532,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  {
>  	s32 res;
>  
> -	i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
> +	res = __i2c_lock_bus_helper(adapter);
> +	if (res)
> +		return res;
> +
>  	res = __i2c_smbus_xfer(adapter, addr, flags, read_write,
>  			       command, protocol, data);
>  	i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
> diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
> index 37576f50fe20..6e98aa811980 100644
> --- a/drivers/i2c/i2c-core.h
> +++ b/drivers/i2c/i2c-core.h
> @@ -29,6 +29,18 @@ extern int		__i2c_first_dynamic_bus_num;
>  
>  int i2c_check_7bit_addr_validity_strict(unsigned short addr);
>  
> +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
> +{
> +	int ret = 0;
> +
> +	if (in_atomic() || irqs_disabled())
> +		ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN;
> +	else
> +		i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
> +
> +	return ret;
> +}
> +
>  #ifdef CONFIG_ACPI
>  const struct acpi_device_id *
>  i2c_acpi_match_device(const struct acpi_device_id *matches,
> 

  reply	other threads:[~2018-09-20 17:31 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 16:14 [RFC PATCH 0/4] i2c: core: introduce master_xfer_irqless Wolfram Sang
2018-09-20 16:14 ` Wolfram Sang
2018-09-20 16:14 ` Wolfram Sang
2018-09-20 16:14 ` [RFC PATCH 1/4] i2c: core: remove outdated DEBUG output Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 17:23   ` Peter Rosin
2018-09-20 17:23     ` Peter Rosin
2018-09-20 17:23     ` Peter Rosin
2018-10-05 16:14   ` Wolfram Sang
2018-10-05 16:14     ` Wolfram Sang
2018-10-05 16:14     ` Wolfram Sang
2018-09-20 16:14 ` [RFC PATCH 2/4] i2c: core: remove level of indentation in i2c_transfer Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 17:26   ` Peter Rosin
2018-09-20 17:26     ` Peter Rosin
2018-09-20 17:26     ` Peter Rosin
2018-09-20 22:46     ` Wolfram Sang
2018-09-20 22:46       ` Wolfram Sang
2018-09-20 22:46       ` Wolfram Sang
2018-10-05 16:15   ` Wolfram Sang
2018-10-05 16:15     ` Wolfram Sang
2018-10-05 16:15     ` Wolfram Sang
2018-09-20 16:14 ` [RFC PATCH 3/4] i2c: core: use I2C locking behaviour also for SMBUS Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 17:31   ` Peter Rosin [this message]
2018-09-20 17:31     ` Peter Rosin
2018-09-20 17:31     ` Peter Rosin
2018-09-20 22:48     ` Wolfram Sang
2018-09-20 22:48       ` Wolfram Sang
2018-09-20 22:48       ` Wolfram Sang
2018-09-20 16:14 ` [RFC PATCH 4/4] i2c: core: introduce master_xfer_irqless callback Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 16:14   ` Wolfram Sang
2018-09-20 17:41   ` Peter Rosin
2018-09-20 17:41     ` Peter Rosin
2018-09-20 17:41     ` Peter Rosin
2018-09-20 22:55     ` Wolfram Sang
2018-09-20 22:55       ` Wolfram Sang
2018-09-20 22:55       ` Wolfram Sang
2018-10-18 10:44   ` Russell King - ARM Linux
2018-10-18 10:44     ` Russell King - ARM Linux
2018-10-18 10:44     ` Russell King - ARM Linux
2019-02-09 18:03     ` Wolfram Sang
2019-02-09 18:03       ` Wolfram Sang
2018-09-20 22:02 ` [RFC PATCH 0/4] i2c: core: introduce master_xfer_irqless Tony Lindgren
2018-09-20 22:02   ` Tony Lindgren
2018-09-20 22:02   ` Tony Lindgren
2018-09-20 22:56   ` Wolfram Sang
2018-09-20 22:56     ` Wolfram Sang
2018-09-20 22:56     ` Wolfram Sang
2018-10-18 10:35     ` Keerthy
2018-10-18 10:35       ` Keerthy
2018-10-18 10:35       ` Keerthy
2018-09-20 23:01 ` Wolfram Sang
2018-09-20 23:01   ` Wolfram Sang
2018-09-20 23:01   ` Wolfram Sang
2018-09-23 20:20 ` Stefan Lengfeld
2018-09-23 20:20   ` Stefan Lengfeld
2018-09-23 20:20   ` Stefan Lengfeld
2018-10-07 15:39   ` [RFC PATCH 0/3] " Stefan Lengfeld
2018-10-07 15:39     ` [RFC PATCH 1/3] i2c: imx: implement master_xfer_irqless callback Stefan Lengfeld
2018-10-08 10:06       ` Andy Shevchenko
2018-10-07 15:39     ` [RFC PATCH 2/3] watchdog: da9062: avoid regmap in restart handler Stefan Lengfeld
2018-10-08 10:07       ` Andy Shevchenko
2018-10-07 15:39     ` [RFC PATCH 3/3] ARM: dts: phyboard-mira-dl: rely on PMIC for reboot and watchdog Stefan Lengfeld

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=e31d69ed-d849-db98-00c2-27d489a2dac1@axentia.se \
    --to=peda@axentia.se \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=contact@stefanchrist.eu \
    --cc=grygorii.strashko@ti.com \
    --cc=j-keerthy@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=preid@electromag.com.au \
    --cc=t-kristo@ti.com \
    --cc=wsa+renesas@sang-engineering.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 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.