Bug 188641

Summary: Function cm3232_reg_init() returns an improper value when the call to i2c_smbus_write_byte_data() fails
Product: Drivers Reporter: bianpan (bianpan2010)
Component: OtherAssignee: drivers_other
Status: RESOLVED CODE_FIX    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: linux-4.9-rc6 Subsystem:
Regression: No Bisected commit-id:
Attachments: The patch fixes the bug

Description bianpan 2016-11-25 10:44:15 UTC
The comment of function cm3232_reg_init() defined in file drivers/iio/light/cm3232.c says "Return: 0 for success; otherwise for error code". However, it returns 0 even when the call to i2c_smbus_write_byte_data() (at line 117) fails. Maybe it is better to use "return ret;" instead of "return 0" at line 122. Codes related to this bug are summarised as follows.

cm3232_reg_init @@ drivers/iio/light/cm3232.c
 79 /**
 80  * cm3232_reg_init() - Initialize CM3232
 81  * @chip:   pointer of struct cm3232_chip.
 82  *
 83  * Check and initialize CM3232 ambient light sensor.
 84  *
 85  * Return: 0 for success; otherwise for error code.
 86  */
 87 static int cm3232_reg_init(struct cm3232_chip *chip)
 88 {
 89     struct i2c_client *client = chip->client;
 90     s32 ret;
        ...
113     /* Register default value */
114     chip->regs_cmd = chip->als_info->regs_cmd_default;
115 
116     /* Configure register */
117     ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
118                     chip->regs_cmd);
119     if (ret < 0)
120         dev_err(&chip->client->dev, "Error writing reg_cmd\n");
121 
122     return 0;    // return ret?
123 }

Thanks very much!
Comment 1 bianpan 2017-05-11 09:39:16 UTC
Created attachment 256385 [details]
The patch fixes the bug

The patch has been merged into the latest version of the Linux kernel. So I will close it.