[PATCH v4 5/6] iio: light: stk3310: log error if reading the chip id fails

Aren Moynihan posted 6 patches 3 weeks ago
[PATCH v4 5/6] iio: light: stk3310: log error if reading the chip id fails
Posted by Aren Moynihan 3 weeks ago
If the chip isn't powered, this call is likely to return an error.
Without a log here the driver will silently fail to probe. Potential
errors include ENXIO (when the chip isn't powered) and ETIMEDOUT (when
the i2c bus isn't powered).

This function is only called from stk3310_probe, and this condition
should return an error, which fits what dev_err_probe is designed for.

Signed-off-by: Aren Moynihan <aren@peacevolution.org>
---

Notes:
    Changes in v4:
     - get a struct device ahead of time so it can be passed as "dev"
       instead of "&client->dev"
    
    Changes in v2:
     - use dev_err_probe

 drivers/iio/light/stk3310.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index c9a3f02bdd80..becd6901dfef 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -509,7 +509,7 @@ static int stk3310_init(struct iio_dev *indio_dev)
 
 	ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid);
 	if (ret < 0)
-		return ret;
+		return dev_err_probe(dev, ret, "failed to read chip id\n");
 
 	ret = stk3310_check_chip_id(chipid);
 	if (ret < 0)
-- 
2.47.0
Re: [PATCH v4 5/6] iio: light: stk3310: log error if reading the chip id fails
Posted by Andy Shevchenko 2 weeks, 6 days ago
On Sat, Nov 02, 2024 at 03:50:43PM -0400, Aren Moynihan wrote:
> If the chip isn't powered, this call is likely to return an error.
> Without a log here the driver will silently fail to probe. Potential
> errors include ENXIO (when the chip isn't powered) and ETIMEDOUT (when
> the i2c bus isn't powered).
> 
> This function is only called from stk3310_probe, and this condition
> should return an error, which fits what dev_err_probe is designed for.

...

> +		return dev_err_probe(dev, ret, "failed to read chip id\n");

Please, make sure you have consistent style in the messages. Most of what
I have seen use period at the end. This one doesn't.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v4 5/6] iio: light: stk3310: log error if reading the chip id fails
Posted by Aren 1 week, 6 days ago
On Mon, Nov 04, 2024 at 10:41:11AM +0200, Andy Shevchenko wrote:
> On Sat, Nov 02, 2024 at 03:50:43PM -0400, Aren Moynihan wrote:
> > If the chip isn't powered, this call is likely to return an error.
> > Without a log here the driver will silently fail to probe. Potential
> > errors include ENXIO (when the chip isn't powered) and ETIMEDOUT (when
> > the i2c bus isn't powered).
> > 
> > This function is only called from stk3310_probe, and this condition
> > should return an error, which fits what dev_err_probe is designed for.
> 
> ...
> 
> > +		return dev_err_probe(dev, ret, "failed to read chip id\n");
> 
> Please, make sure you have consistent style in the messages. Most of what
> I have seen use period at the end. This one doesn't.

All but two log messages in this driver don't have a period at the end.
I'll correct those two in the next revision.

 - Aren