Skip to content

Commit

Permalink
lcd_extern: driver defect clean up
Browse files Browse the repository at this point in the history
PD#150081: driver defect clean up:
torvalds#20
torvalds#38
torvalds#87
torvalds#468
torvalds#469
torvalds#470
torvalds#471
torvalds#613
torvalds#668
  

Change-Id: Ifa0756e25088599571761b33efaffb6c2c898dfc
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
  • Loading branch information
Evoke Zhang authored and akiernan committed Nov 3, 2022
1 parent 310a508 commit 69fc850
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 74 deletions.
33 changes: 21 additions & 12 deletions drivers/amlogic/media/vout/lcd/lcd_extern/ext_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int lcd_extern_power_cmd_dynamic_size(unsigned char *init_table,

switch (ext_config->type) {
case LCD_EXTERN_I2C:
while (i <= max_len) {
while ((i + 2) < max_len) {
type = init_table[i];
if (type == LCD_EXTERN_INIT_END)
break;
Expand All @@ -191,6 +191,9 @@ static int lcd_extern_power_cmd_dynamic_size(unsigned char *init_table,
init_table[i], init_table[i+1]);
}
cmd_size = init_table[i+1];
if ((i + 2 + cmd_size) > max_len)
break;

if (type == LCD_EXTERN_INIT_NONE) {
if (cmd_size < 1) {
EXTERR("step %d: invalid cmd_size %d\n",
Expand Down Expand Up @@ -238,7 +241,7 @@ static int lcd_extern_power_cmd_dynamic_size(unsigned char *init_table,
}
break;
case LCD_EXTERN_SPI:
while (i <= max_len) {
while ((i + 2) < max_len) {
type = init_table[i];
if (type == LCD_EXTERN_INIT_END)
break;
Expand All @@ -248,6 +251,9 @@ static int lcd_extern_power_cmd_dynamic_size(unsigned char *init_table,
init_table[i], init_table[i+1]);
}
cmd_size = init_table[i+1];
if ((i + 2 + cmd_size) > max_len)
break;

if (type == LCD_EXTERN_INIT_NONE) {
if (cmd_size < 1) {
EXTERR("step %d: invalid cmd_size %d\n",
Expand Down Expand Up @@ -311,7 +317,7 @@ static int lcd_extern_power_cmd_fixed_size(unsigned char *init_table, int flag)
cmd_size = ext_config->cmd_size;
switch (ext_config->type) {
case LCD_EXTERN_I2C:
while (i <= max_len) {
while ((i + cmd_size) <= max_len) {
type = init_table[i];
if (type == LCD_EXTERN_INIT_END)
break;
Expand Down Expand Up @@ -346,7 +352,7 @@ static int lcd_extern_power_cmd_fixed_size(unsigned char *init_table, int flag)
}
break;
case LCD_EXTERN_SPI:
while (i <= max_len) {
while ((i + cmd_size) <= max_len) {
type = init_table[i];
if (type == LCD_EXTERN_INIT_END)
break;
Expand Down Expand Up @@ -494,10 +500,12 @@ static int aml_default_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
EXTERR("%s: functionality check failed\n", __func__);
else
aml_default_i2c_client = client;
return -ENODEV;
}

aml_default_i2c_client = client;

EXTPR("%s OK\n", __func__);
return 0;
Expand Down Expand Up @@ -546,6 +554,7 @@ int aml_lcd_extern_default_probe(struct aml_lcd_extern_driver_s *ext_drv)
}

strncpy(i2c_info.type, ext_drv->config.name, I2C_NAME_SIZE);
i2c_info.type[I2C_NAME_SIZE-1] = '\0';
i2c_info.addr = ext_drv->config.i2c_addr;
i2c_info.platform_data = &ext_drv->config;
i2c_info.flags = 0;
Expand All @@ -558,11 +567,11 @@ int aml_lcd_extern_default_probe(struct aml_lcd_extern_driver_s *ext_drv)
if (!i2c_client) {
EXTERR("%s failed to new i2c device\n",
ext_drv->config.name);
} else {
if (lcd_debug_print_flag) {
EXTPR("%s new i2c device succeed\n",
ext_drv->config.name);
}
return -1;
}
if (lcd_debug_print_flag) {
EXTPR("%s new i2c device succeed\n",
ext_drv->config.name);
}

if (!aml_default_i2c_client) {
Expand Down
24 changes: 14 additions & 10 deletions drivers/amlogic/media/vout/lcd/lcd_extern/i2c_T5800Q.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int lcd_extern_power_cmd(unsigned char *init_table, int flag)
else
max_len = LCD_EXTERN_INIT_OFF_MAX;

while (i <= max_len) {
while ((i + cmd_size) <= max_len) {
if (init_table[i] == LCD_EXTERN_INIT_END)
break;
if (lcd_debug_print_flag) {
Expand Down Expand Up @@ -216,7 +216,10 @@ static int lcd_extern_driver_update(struct aml_lcd_extern_driver_s *ext_drv)
return 0;
}

/* debug function */
/* *********************************************************
* debug function
* *********************************************************
*/
static const char *lcd_extern_debug_usage_str = {
"Usage:\n"
" echo <reg> <> ... <> > write ; T5800Q i2c command write, 7 parameters without address\n"
Expand Down Expand Up @@ -301,10 +304,12 @@ static int aml_T5800Q_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
EXTERR("%s: functionality check failed\n", __func__);
else
aml_T5800Q_i2c_client = client;
return -ENODEV;
}

aml_T5800Q_i2c_client = client;

EXTPR("%s OK\n", __func__);
return 0;
Expand Down Expand Up @@ -348,6 +353,7 @@ int aml_lcd_extern_i2c_T5800Q_probe(struct aml_lcd_extern_driver_s *ext_drv)
}

strncpy(i2c_info.type, ext_drv->config.name, I2C_NAME_SIZE);
i2c_info.type[I2C_NAME_SIZE-1] = '\0';
i2c_info.addr = ext_drv->config.i2c_addr;
i2c_info.platform_data = &ext_drv->config;
i2c_info.flags = 0;
Expand All @@ -359,12 +365,10 @@ int aml_lcd_extern_i2c_T5800Q_probe(struct aml_lcd_extern_driver_s *ext_drv)
i2c_client = i2c_new_device(adapter, &i2c_info);
if (!i2c_client) {
EXTERR("%s failed to new i2c device\n", ext_drv->config.name);
} else {
if (lcd_debug_print_flag) {
EXTPR("%s new i2c device succeed\n",
ext_drv->config.name);
}
return -1;
}
if (lcd_debug_print_flag)
EXTPR("%s new i2c device succeed\n", ext_drv->config.name);

if (!aml_T5800Q_i2c_client) {
ret = i2c_add_driver(&aml_T5800Q_i2c_driver);
Expand Down
Loading

0 comments on commit 69fc850

Please sign in to comment.