hd44780: Add keystring array boundary check. Have all subdrivers close

previously opened devices.
This commit is contained in:
mmdolze
2010-01-10 17:07:48 +00:00
parent 97a2b20b0d
commit 6fba5cef68
5 changed files with 43 additions and 5 deletions
+14
View File
@@ -75,6 +75,7 @@
void i2c_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void i2c_HD44780_backlight(PrivateData *p, unsigned char state);
void i2c_HD44780_close(PrivateData *p);
#define RS 0x10
#define RW 0x20
@@ -163,6 +164,7 @@ hd_init_i2c(Driver *drvthis)
hd44780_functions->senddata = i2c_HD44780_senddata;
hd44780_functions->backlight = i2c_HD44780_backlight;
hd44780_functions->close = i2c_HD44780_close;
// powerup the lcd now
/* We'll now send 0x03 a couple of times,
@@ -216,6 +218,18 @@ hd_init_i2c(Driver *drvthis)
}
/**
* Close the device.
* \param p Pointer to driver's private data structure.
*/
void
i2c_HD44780_close(PrivateData *p) {
if (p->fd >= 0) {
close(p->fd);
}
}
/**
* Send data or commands to the display.
* \param p Pointer to driver's private data structure.
+14
View File
@@ -48,6 +48,7 @@ extern unsigned int **bitrate_conversion;
extern int convert_bitrate(unsigned int conf_bitrate, size_t *bitrate);
void lis2_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lis2_HD44780_close(PrivateData *p);
static void clearScreen(int fd);
static void gotoXY(int fd, unsigned char x, unsigned char y);
@@ -131,6 +132,7 @@ int hd_init_lis2(Driver *drvthis)
tcsetattr(p->fd, TCSANOW, &portset);
p->hd44780_functions->senddata = lis2_HD44780_senddata;
p->hd44780_functions->close = lis2_HD44780_close;
common_init(p, IF_8BIT);
@@ -138,6 +140,18 @@ int hd_init_lis2(Driver *drvthis)
}
/**
* Close the device.
* \param p Pointer to driver's private data structure.
*/
void
lis2_HD44780_close(PrivateData *p) {
if (p->fd >= 0) {
close(p->fd);
}
}
/**
* Send data or commands to the display.
* \param p Pointer to driver's private data structure.
+5 -3
View File
@@ -334,7 +334,9 @@ serial_HD44780_scankeypad(PrivateData *p)
void
serial_HD44780_close(PrivateData *p)
{
if (SERIAL_IF.end_code)
write(p->fd, &SERIAL_IF.end_code, 1);
close(p->fd);
if (p->fd >= 0) {
if (SERIAL_IF.end_code)
write(p->fd, &SERIAL_IF.end_code, 1);
close(p->fd);
}
}
+2 -1
View File
@@ -168,7 +168,8 @@ usblcd_HD44780_backlight(PrivateData *p, unsigned char state)
void
usblcd_HD44780_close(PrivateData *p)
{
close(p->fd);
if (p->fd >= 0)
close(p->fd);
}
/* EOF */
+8 -1
View File
@@ -164,6 +164,7 @@ HD44780_init(Driver *drvthis)
p->cellwidth = 5;
p->ccmode = standard;
p->backlightstate = -1; // Init to invalid value
p->fd = -1;
//// READ THE CONFIG FILE
@@ -1250,7 +1251,13 @@ HD44780_get_key(Driver *drvthis)
scancode = p->hd44780_functions->scankeypad(p);
if (scancode != '\0') {
// TODO: check if arrays are large enough
// Check if arrays are large enough
if ((scancode&0x0F) > KEYPAD_MAXX || ((scancode&0xF0)>>4) > KEYPAD_MAXY) {
report(RPT_WARNING, "HD44780_get_key: Scancode out of range: %d",
scancode);
return NULL;
}
keystr = (scancode & 0xF0)
? p->keyMapMatrix[((scancode&0xF0)>>4)-1][(scancode&0x0F)-1]
: p->keyMapDirect[scancode - 1];