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: <CAHp75VcZk_Brin=K7ofHkq9CV90LoqKm2k_ULrXLMCxWVWv9Nw@mail.gmail.com>
Date:   Sat, 1 May 2021 21:48:01 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Ivan Mikhaylov <i.mikhaylov@...ro.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>,
        Jean Delvare <jdelvare@...e.com>,
        Guenter Roeck <linux@...ck-us.net>,
        linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
        linux-hwmon@...r.kernel.org
Subject: Re: [PATCH 1/4] iio: proximity: vcnl3020: add periodic mode

On Fri, Apr 30, 2021 at 6:17 PM Ivan Mikhaylov <i.mikhaylov@...ro.com> wrote:
>
> Add the possibility to run proximity sensor in periodic measurement
> mode.

...

> +static int vcnl3020_config_threshold(struct iio_dev *indio_dev, bool state)
> +{
> +       struct vcnl3020_data *data = iio_priv(indio_dev);
> +       int rc;
> +       int icr;
> +       int cmd;
> +       int isr;
> +
> +       if (state) {
> +               rc = iio_device_claim_direct_mode(indio_dev);
> +               if (rc)
> +                       return rc;
> +
> +               /* Enable periodic measurement of proximity data. */
> +               cmd = VCNL_PS_EN | VCNL_PS_SELFTIMED_EN;
> +
> +               /*
> +                * Enable interrupts on threshold, for proximity data by
> +                * default.
> +                */
> +               icr = VCNL_ICR_THRES_EN;
> +       } else {
> +               if (!vcnl3020_is_thr_enabled(data))
> +                       return 0;
> +
> +               cmd = 0;
> +               icr = 0;
> +               isr = 0;
> +       }
> +
> +       rc = regmap_write(data->regmap, VCNL_COMMAND, cmd);
> +       if (rc)
> +               goto end;
> +
> +       rc = regmap_write(data->regmap, VCNL_PS_ICR, icr);
> +       if (rc)
> +               goto end;
> +
> +       if (!state)
> +               /* Clear interrupts */
> +               rc = regmap_write(data->regmap, VCNL_ISR, isr);
> +
> +end:
> +       if (state)
> +               iio_device_release_direct_mode(indio_dev);
> +
> +       return rc;
> +}

The code will benefit in case you split above to two helpers, i.e.
_on() and _off().
It will gain better readability.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ