Bug 188641 - Function cm3232_reg_init() returns an improper value when the call to i2c_smbus_write_byte_data() fails
Summary: Function cm3232_reg_init() returns an improper value when the call to i2c_smb...
Status: RESOLVED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: drivers_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-25 10:44 UTC by bianpan
Modified: 2017-05-11 09:39 UTC (History)
0 users

See Also:
Kernel Version: linux-4.9-rc6
Tree: Mainline
Regression: No


Attachments
The patch fixes the bug (1.05 KB, patch)
2017-05-11 09:39 UTC, bianpan
Details | Diff

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.

Note You need to log in before you can comment on or make changes to this bug.