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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 19 Dec 2019 13:02:28 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Dan Robertson <dan@...obertson.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        linux-iio <linux-iio@...r.kernel.org>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>,
        devicetree <devicetree@...r.kernel.org>,
        Hartmut Knaack <knaack.h@....de>,
        Rob Herring <robh+dt@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Randy Dunlap <rdunlap@...radead.org>,
        Joe Perches <joe@...ches.com>,
        Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400

On Thu, Dec 19, 2019 at 6:27 AM Dan Robertson <dan@...obertson.com> wrote:
> Add a IIO driver for the Bosch BMA400 3-axes ultra-low power accelerometer.
> The driver supports reading from the acceleration and temperature
> registers. The driver also supports reading and configuring the output data
> rate, oversampling ratio, and scale.

...

> +static int bma400_set_accel_output_data_rate(struct bma400_data *data,
> +                                            int hz, int uhz)
> +{
> +       unsigned int idx;
> +       unsigned int odr;
> +       unsigned int val;
> +       int ret;
> +
> +       if (hz >= BMA400_ACC_ODR_MIN_WHOLE_HZ) {
> +               if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ)
> +                       return -EINVAL;
> +
> +               val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ;

Again, AFAICS division may be avoided in both cases (% and / above)
because of is_power_of_2() check below.
Can you revisit this?

> +               if (!is_power_of_2(val))
> +                       return -EINVAL;
> +
> +               idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1;
> +       } else if (hz == BMA400_ACC_ODR_MIN_HZ && uhz == 500000) {
> +               idx = BMA400_ACC_ODR_MIN_RAW;
> +       } else {
> +               return -EINVAL;
> +       }
> +
> +       ret = regmap_read(data->regmap, BMA400_ACC_CONFIG1_REG, &val);
> +       if (ret)
> +               return ret;
> +
> +       /* preserve the range and normal mode osr */

> +       odr = idx | (~BMA400_ACC_ODR_MASK & val);

Yoda style?

> +
> +       ret = regmap_write(data->regmap, BMA400_ACC_CONFIG1_REG, odr);
> +       if (ret)
> +               return ret;
> +
> +       bma400_output_data_rate_from_raw(idx, &data->sample_freq.hz,
> +                                        &data->sample_freq.uhz);
> +       return 0;
> +}
...

> +int bma400_accel_scale_to_raw(struct bma400_data *data, unsigned int val)
> +{
> +       int scale = val / BMA400_SCALE_MIN;
> +       int raw;
> +
> +       if (scale == 0)
> +               return -EINVAL;
> +
> +       raw = __ffs(scale);
> +
> +       if (val % BMA400_SCALE_MIN || !is_power_of_2(scale))
> +               return -EINVAL;

Ditto.

> +
> +       return raw;
> +}

...

> +out:

Make a little sense. Why not return directly?

> +       return ret;

...

> +       ret = bma400_init(data);
> +       if (ret < 0)

May it be positive value returned?

> +               return ret;

...

> +static int bma400_i2c_probe(struct i2c_client *client,
> +                           const struct i2c_device_id *id)
> +{
> +       struct regmap *regmap;
> +
> +       regmap = devm_regmap_init_i2c(client, &bma400_regmap_config);

> +

Redundant blank line.

> +       if (IS_ERR(regmap)) {
> +               dev_err(&client->dev, "failed to create regmap\n");
> +               return PTR_ERR(regmap);
> +       }
> +
> +       return bma400_probe(&client->dev, regmap, id->name);
> +}

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ