Re: [PATCH v1 05/13] iio: chemical: bme680: refactorize set_mode() mode

From: Vasileios Aoiridis
Date: Fri Oct 11 2024 - 14:56:12 EST


On Fri, Oct 11, 2024 at 01:02:28PM +0300, Andy Shevchenko wrote:
> On Thu, Oct 10, 2024 at 11:00:22PM +0200, vamoirid wrote:
> > From: Vasileios Amoiridis <vassilisamir@xxxxxxxxx>
> >
> > Refactorize the set_mode() function to use an external enum that
> > describes the possible modes of the BME680 device instead of using
> > true/false variables for selecting SLEEPING/FORCED mode.
>
> ...
>
> > - if (mode) {
> > - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
> > - BME680_MODE_MASK, BME680_MODE_FORCED);
> > - if (ret < 0)
> > - dev_err(dev, "failed to set forced mode\n");
> > -
> > - } else {
> > - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
> > - BME680_MODE_MASK, BME680_MODE_SLEEP);
> > - if (ret < 0)
> > - dev_err(dev, "failed to set sleep mode\n");
> > -
> > + switch (mode) {
> > + case BME680_SLEEP:
> > + case BME680_FORCED:
> > + break;
> > + default:
> > + return -EINVAL;
> > }
> >
> > + ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
> > + BME680_MODE_MASK, mode);
> > + if (ret < 0)
> > + dev_err(dev, "failed to set ctrl_meas register\n");
>
> This is an information loss. You shuld probably still have a value of mode to
> be printed.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

You are right, I missed a return here.

Cheers,
Vasilis