MXT Driver: Make sure that all return values are checked: Fix worker thread -- it must hold the MXT device semaphore to access I2C

This commit is contained in:
Gregory Nutt 2014-07-08 08:55:43 -06:00
parent 4f60bfb485
commit 25f419d487
2 changed files with 189 additions and 156 deletions

View File

@ -756,6 +756,15 @@ static void mxt_worker(FAR void *arg)
lower = priv->lower; lower = priv->lower;
DEBUGASSERT(lower != NULL); DEBUGASSERT(lower != NULL);
/* Get exclusive access to the MXT driver data structure */
do
{
ret = sem_wait(&priv->devsem);
DEBUGASSERT(ret == 0 || errno == EINTR);
}
while (ret < 0);
/* Loop, processing each message from the maXTouch */ /* Loop, processing each message from the maXTouch */
do do
@ -766,7 +775,7 @@ static void mxt_worker(FAR void *arg)
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: mxt_getmessage failed: %d\n", ret); idbg("ERROR: mxt_getmessage failed: %d\n", ret);
return; goto errout_with_semaphore;
} }
id = msg.id; id = msg.id;
@ -816,6 +825,11 @@ static void mxt_worker(FAR void *arg)
} }
while (id != 0x00 && id != 0xff); while (id != 0x00 && id != 0xff);
errout_with_semaphore:
/* Release our lock on the MXT device */
sem_post(&priv->devsem);
/* Acknowledge and re-enable maXTouch interrupts */ /* Acknowledge and re-enable maXTouch interrupts */
MXT_CLEAR(lower); MXT_CLEAR(lower);
@ -894,6 +908,7 @@ static int mxt_open(FAR struct file *filep)
{ {
/* More than 255 opens; uint8_t overflows to zero */ /* More than 255 opens; uint8_t overflows to zero */
idbg("ERROR: Too many opens: %d\n", priv->crefs);
ret = -EMFILE; ret = -EMFILE;
goto errout_with_sem; goto errout_with_sem;
} }
@ -906,7 +921,12 @@ static int mxt_open(FAR struct file *filep)
{ {
/* Touch enable */ /* Touch enable */
mxt_putobject(priv, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83); ret = mxt_putobject(priv, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
if (ret < 0)
{
idbg("ERROR: Failed to enable touch: %d\n", ret);
goto errout_with_sem;
}
} }
/* Save the new open count on success */ /* Save the new open count on success */
@ -956,7 +976,11 @@ static int mxt_close(FAR struct file *filep)
{ {
/* Touch disable */ /* Touch disable */
mxt_putobject(priv, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); ret = mxt_putobject(priv, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
if (ret < 0)
{
idbg("ERROR: Failed to disable touch: %d\n", ret);
}
} }
} }
@ -1393,6 +1417,7 @@ static int mxt_getobjtab(FAR struct mxt_dev_s *priv)
tabsize); tabsize);
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: Failed to object table size: %d\n", ret);
return ret; return ret;
} }
@ -1532,7 +1557,13 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv)
/* Perform a soft reset */ /* Perform a soft reset */
mxt_putobject(priv, MXT_GEN_COMMAND_T6, MXT_COMMAND_RESET, 1); ret = mxt_putobject(priv, MXT_GEN_COMMAND_T6, MXT_COMMAND_RESET, 1);
if (ret < 0)
{
idbg("ERROR: Soft reset failed: %d\n", ret);
goto errout_with_objtab;
}
usleep(MXT_RESET_TIME); usleep(MXT_RESET_TIME);
/* Update matrix size in the info structure */ /* Update matrix size in the info structure */
@ -1540,6 +1571,7 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv)
ret = mxt_getreg(priv, MXT_MATRIX_X_SIZE, (FAR uint8_t *)&regval, 1); ret = mxt_getreg(priv, MXT_MATRIX_X_SIZE, (FAR uint8_t *)&regval, 1);
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: Failed to get X size: %d\n", ret);
goto errout_with_objtab; goto errout_with_objtab;
} }
@ -1548,6 +1580,7 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv)
ret = mxt_getreg(priv, MXT_MATRIX_Y_SIZE, (FAR uint8_t *)&regval, 1); ret = mxt_getreg(priv, MXT_MATRIX_Y_SIZE, (FAR uint8_t *)&regval, 1);
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: Failed to get Y size: %d\n", ret);
goto errout_with_objtab; goto errout_with_objtab;
} }

View File

@ -72,33 +72,33 @@
/* Object types */ /* Object types */
#define MXT_DEBUG_DIAGNOSTIC_T37 37
#define MXT_GEN_MESSAGE_T5 5 #define MXT_GEN_MESSAGE_T5 5
#define MXT_GEN_COMMAND_T6 6 #define MXT_GEN_COMMAND_T6 6
#define MXT_GEN_POWER_T7 7 #define MXT_GEN_POWER_T7 7
#define MXT_GEN_ACQUIRE_T8 8 #define MXT_GEN_ACQUIRE_T8 8
#define MXT_GEN_DATASOURCE_T53 53
#define MXT_TOUCH_MULTI_T9 9 #define MXT_TOUCH_MULTI_T9 9
#define MXT_TOUCH_KEYARRAY_T15 15 #define MXT_TOUCH_KEYARRAY_T15 15
#define MXT_TOUCH_PROXIMITY_T23 23 #define MXT_SPT_COMMSCONFIG_T18 18
#define MXT_TOUCH_PROXKEY_T52 52 #define MXT_SPT_GPIOPWM_T19 19
#define MXT_PROCI_GRIPFACE_T20 20 #define MXT_PROCI_GRIPFACE_T20 20
#define MXT_PROCG_NOISE_T22 22 #define MXT_PROCG_NOISE_T22 22
#define MXT_TOUCH_PROXIMITY_T23 23
#define MXT_PROCI_ONETOUCH_T24 24 #define MXT_PROCI_ONETOUCH_T24 24
#define MXT_SPT_SELFTEST_T25 25
#define MXT_PROCI_TWOTOUCH_T27 27 #define MXT_PROCI_TWOTOUCH_T27 27
#define MXT_SPT_CTECONFIG_T28 28
#define MXT_DEBUG_DIAGNOSTIC_T37 37
#define MXT_SPT_USERDATA_T38 38
#define MXT_PROCI_GRIP_T40 40 #define MXT_PROCI_GRIP_T40 40
#define MXT_PROCI_PALM_T41 41 #define MXT_PROCI_PALM_T41 41
#define MXT_PROCI_TOUCHSUPPRESSION_T42 42 #define MXT_PROCI_TOUCHSUPPRESSION_T42 42
#define MXT_PROCI_STYLUS_T47 47
#define MXT_PROCG_NOISESUPPRESSION_T48 48
#define MXT_SPT_COMMSCONFIG_T18 18
#define MXT_SPT_GPIOPWM_T19 19
#define MXT_SPT_SELFTEST_T25 25
#define MXT_SPT_CTECONFIG_T28 28
#define MXT_SPT_USERDATA_T38 38
#define MXT_SPT_DIGITIZER_T43 43 #define MXT_SPT_DIGITIZER_T43 43
#define MXT_SPT_MESSAGECOUNT_T44 44 #define MXT_SPT_MESSAGECOUNT_T44 44
#define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_CTECONFIG_T46 46
#define MXT_PROCI_STYLUS_T47 47
#define MXT_PROCG_NOISESUPPRESSION_T48 48
#define MXT_TOUCH_PROXKEY_T52 52
#define MXT_GEN_DATASOURCE_T53 53
/* MXT_GEN_COMMAND_T6 field */ /* MXT_GEN_COMMAND_T6 field */