lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfvSWuXVJFsq7ZdWj3-XrpPXnFSV1Bk_oW9oS6Gm7msuA@mail.gmail.com>
Date:   Mon, 15 Apr 2019 15:39:07 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Wolfram Sang <wsa+renesas@...g-engineering.com>
Cc:     linux-i2c <linux-i2c@...r.kernel.org>,
        Linux-Renesas <linux-renesas-soc@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>,
        Peter Rosin <peda@...ntia.se>,
        Stefan Lengfeld <contact@...fanchrist.eu>,
        Linux OMAP Mailing List <linux-omap@...r.kernel.org>,
        linux-tegra@...r.kernel.org,
        Linus Walleij <linus.walleij@...aro.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [PATCH 02/12] i2c: core: use I2C locking behaviour also for SMBUS

On Wed, Apr 3, 2019 at 3:43 PM Wolfram Sang
<wsa+renesas@...g-engineering.com> 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.
>

Reviewed-by Andy Shevchenko <andriy.shevchenko@...ux.intel.com>


> Signed-off-by: Wolfram Sang <wsa+renesas@...g-engineering.com>
> ---
>  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 f8502064cd6b..ad14f38a67e4 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1946,14 +1946,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 (i2c_in_atomic_xfer_mode()) {
> -               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 132119112596..357e083e8f45 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 9d8526415b26..deea47c576e5 100644
> --- a/drivers/i2c/i2c-core.h
> +++ b/drivers/i2c/i2c-core.h
> @@ -39,6 +39,18 @@ static inline bool i2c_in_atomic_xfer_mode(void)
>         return system_state > SYSTEM_RUNNING && irqs_disabled();
>  }
>
> +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
> +{
> +       int ret = 0;
> +
> +       if (i2c_in_atomic_xfer_mode())
> +               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,
> --
> 2.11.0
>


-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ