[lkml]   [2019]   [Jan]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] In function rt274_i2c_probe(), if the regmap_read fails. The variable "val" could leave uninitialized but used in if statement.
On Wed, Jan 02, 2019 at 06:38:39PM -0800, Yizhuo wrote:

> int ret;
> - unsigned int val;
> + unsigned int val = ~0;

This just shuts warnings up which may mask further problem, it is better
to just leave it and fix the users.

> - regmap_read(rt274->regmap,
> + ret = regmap_read(rt274->regmap,
> - if (val != RT274_VENDOR_ID) {
> + if (ret || val != RT274_VENDOR_ID) {
> dev_err(&i2c->dev,
> "Device with ID register %#x is not rt274\n", val);
> return -ENODEV;

If the read returned an error we should pass back the error code we got
from it, not mask it with another error code. This is especially true
here where the error message would be very misleading if there's a
problem with I/O.
[unhandled content-type:application/pgp-signature]
 \ /
  Last update: 2019-01-03 14:11    [W:0.044 / U:1.884 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site