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]
Date:   Tue, 21 Apr 2020 23:23:11 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Ivan Mikhaylov <i.mikhaylov@...ro.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        Hartmut Knaack <knaack.h@....de>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>,
        linux-iio <linux-iio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        devicetree <devicetree@...r.kernel.org>,
        Mark Rutland <mark.rutland@....com>,
        Rob Herring <robh+dt@...nel.org>
Subject: Re: [PATCH v10 2/2] iio: proximity: Add driver support for vcnl3020
 proximity sensor

On Tue, Apr 21, 2020 at 10:39 PM Ivan Mikhaylov <i.mikhaylov@...ro.com> wrote:
>
> Proximity sensor driver based on light/vcnl4000.c code.
> For now supports only the single on-demand measurement.
>
> The VCNL3020 is a fully integrated proximity sensor. Fully
> integrated means that the infrared emitter is included in the
> package. It has 16-bit resolution. It includes a signal
> processing IC and features standard I2C communication
> interface. It features an interrupt function.

...

> +static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
> +                                          const char *prop, u32 reg)
> +{
> +       int rc;
> +       u32 val;
> +
> +       rc = device_property_read_u32(data->dev, prop, &val);
> +       if (rc)
> +               return 0;
> +

> +       /* An example of conversion from uA to reg val:
> +        * 200000 uA == 200 mA == 20
> +        */
> +       if (!strcmp(prop, "vishay,led-current-microamp"))
> +               val /= 10000;

I probably missed the point why this function is needed at all, since
we always call only for a single property.

On top of that, why do we have this nasty strcmp()? Can't we simple do
something like

static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
const char *prop, u32 reg, u32 div)
{
...
  val /= div;
...
}

static int vcnl3020_get_and_apply_led_current_property(struct
vcnl3020_data *data)
{
  /*
   * An example of conversion from uA to reg val:
   * 200000 uA == 200 mA == 20
   */
// Note by the way comments style
  return vcnl3020_get_and_apply_property(data, "vishay,led-current-microamp",
                                              VCNL_LED_CURRENT, 10000);
}

?

> +       rc = regmap_write(data->regmap, reg, val);
> +       if (rc) {
> +               dev_err(data->dev, "Error (%d) setting property (%s)\n",
> +                       rc, prop);
> +       }
> +
> +       return rc;
> +}

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ