What does it mean when i2c_smbus_read_byte() returns 0

i2c_smbus_read_byte() returns a negative value when there is an error in reading data. But what if it returns 0?

Following is the code from adt7316-i2c driver

static int adt7316_i2c_read(void *client, u8 reg, u8 *data)
{
struct i2c_client *cl = client;
int ret;

ret = i2c_smbus_write_byte(cl, reg);
if (ret < 0) {
dev_err(&cl->dev, "I2C fail to select reg\n");
return ret;
}

if (ret < 0) {
return ret;
}

*data = ret;

return 0;
}


Even if i2c_smbus_read_byte() returns 0 here then the driver will successfully probe. So my main concern is to know whether returing of 0 from i2c_smbus_read_byte() is a valid case or not for a driver to probe.

I am not sure but maybe it means that there is no error and also no data has been read. If this is the case then under what situation does this happen?

• You should specify what platform this is, but I would assume it's reading a value of zero. – Hearth Dec 5 '18 at 22:52
• @Hearth so you mean that a byte was read with a value of 0. For instance, if the input to the adc is 0V. Right? – Shreeya Patel Dec 5 '18 at 22:59
• Yes, that is what I mean. – Hearth Dec 5 '18 at 23:00
• You should post your function code. Otherwise we can never be sure what function you are using. If this is based on a library, there must be some documentation which tells you about the return codes of the function. – A.R.C. Dec 6 '18 at 14:47
• @A.R.C., ok I am posting the code. Please check it out. – Shreeya Patel Dec 7 '18 at 18:12