Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (max1619) Improve chip detection code

Bail out immediately if reading any of the registers used for chip
detection fails, or if it returns an unexpected value. Drop all log
messages from detection code.

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+14 -18
+14 -18
drivers/hwmon/max1619.c
··· 260 260 struct i2c_board_info *info) 261 261 { 262 262 struct i2c_adapter *adapter = client->adapter; 263 - u8 reg_config, reg_convrate, reg_status, man_id, chip_id; 263 + int regval; 264 264 265 265 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 266 266 return -ENODEV; 267 267 268 - /* detection */ 269 - reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG); 270 - reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE); 271 - reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS); 272 - if ((reg_config & 0x03) != 0x00 273 - || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) { 274 - dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n", 275 - client->addr); 268 + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG); 269 + if (regval < 0 || (regval & 0x03)) 276 270 return -ENODEV; 277 - } 271 + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE); 272 + if (regval < 0 || regval > 0x07) 273 + return -ENODEV; 274 + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS); 275 + if (regval < 0 || (regval & 0x61)) 276 + return -ENODEV; 278 277 279 - /* identification */ 280 - man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID); 281 - chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID); 282 - if (man_id != 0x4D || chip_id != 0x04) { 283 - dev_info(&adapter->dev, 284 - "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n", 285 - man_id, chip_id); 278 + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID); 279 + if (regval != 0x4d) 286 280 return -ENODEV; 287 - } 281 + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID); 282 + if (regval != 0x04) 283 + return -ENODEV; 288 284 289 285 strscpy(info->type, "max1619", I2C_NAME_SIZE); 290 286