mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
gd32f4xx_at24: Fix uninitialized use of local variables i2c and at24
Prior to this commit, i2c and at24 may be used uninitialized on line 113, 117, 129, and 143 when gd32_at24_wr_test() is called the second time because these two variables are not static. I don't think making them static is the correct fix because i2c is released at the end of this function. Fixed by removing the `if (!initialized)` condition surrounding the initialization of i2c and at24, making them initialized at every call to this function. Signed-off-by: Mingjie Shen <shen497@purdue.edu>
This commit is contained in:
@@ -73,39 +73,29 @@ int gd32_at24_wr_test(int minor)
|
|||||||
{
|
{
|
||||||
struct i2c_master_s *i2c;
|
struct i2c_master_s *i2c;
|
||||||
struct mtd_dev_s *at24;
|
struct mtd_dev_s *at24;
|
||||||
static bool initialized = false;
|
|
||||||
int ret;
|
int ret;
|
||||||
ssize_t nblocks;
|
ssize_t nblocks;
|
||||||
uint8_t *read_buf;
|
uint8_t *read_buf;
|
||||||
|
|
||||||
/* Have we already initialized? */
|
/* Get the I2C port driver */
|
||||||
|
|
||||||
if (!initialized)
|
finfo("Initialize TWI%d\n", AT24_BUS);
|
||||||
|
i2c = gd32_i2cbus_initialize(AT24_BUS);
|
||||||
|
if (!i2c)
|
||||||
{
|
{
|
||||||
/* No.. Get the I2C port driver */
|
ferr("ERROR: Failed to initialize TWI%d\n", AT24_BUS);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
finfo("Initialize TWI%d\n", AT24_BUS);
|
/* Now bind the I2C interface to the AT24 I2C EEPROM driver */
|
||||||
i2c = gd32_i2cbus_initialize(AT24_BUS);
|
|
||||||
if (!i2c)
|
|
||||||
{
|
|
||||||
ferr("ERROR: Failed to initialize TWI%d\n", AT24_BUS);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now bind the I2C interface to the AT24 I2C EEPROM driver */
|
finfo("Bind the AT24 EEPROM driver to TWI%d\n", AT24_BUS);
|
||||||
|
at24 = at24c_initialize(i2c);
|
||||||
finfo("Bind the AT24 EEPROM driver to TWI%d\n", AT24_BUS);
|
if (!at24)
|
||||||
at24 = at24c_initialize(i2c);
|
{
|
||||||
if (!at24)
|
ferr("ERROR: Failed to bind TWI%d to the AT24 EEPROM driver\n",
|
||||||
{
|
AT24_BUS);
|
||||||
ferr("ERROR: Failed to bind TWI%d to the AT24 EEPROM driver\n",
|
return -ENODEV;
|
||||||
AT24_BUS);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now we are initializeed */
|
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write start block is START_BLOCK, number of block is 2 */
|
/* Write start block is START_BLOCK, number of block is 2 */
|
||||||
|
|||||||
Reference in New Issue
Block a user