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] [day] [month] [year] [list]
Date:   Wed, 22 Apr 2020 15:46:09 +0300
From:   Ivan Mikhaylov <i.mikhaylov@...ro.com>
To:     Andy Shevchenko <andy.shevchenko@...il.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, 2020-04-21 at 23:23 +0300, Andy Shevchenko wrote:
> 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.

Andy, I'm planning to add more properties but not for now, this driver the
placeholder for upcoming work what I've. And I wanted something like:

rc = vcnl3020_get_and_apply_property(option1);
if (rc)
	return rc;

rc = vcnl3020_get_and_apply_property(option2);
if (rc)
	return rc;
etc.

And all other work about conversion will be hidden in get_and_apply_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);
> }
> 
> ?

I think your approach with wrapper is better, I'll think how I can do that
without additional 'div' param.

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ