Check return from nxsem_wait_uninterruptible()

Resolution of Issue 619 will require multiple steps, this part of the first step in that resolution:  Every call to nxsem_wait_uninterruptible() must handle the return value from nxsem_wait_uninterruptible properly.  This commit is for all remaining drivers in the LC823450 architectures.
This commit is contained in:
Gregory Nutt 2020-04-05 10:09:30 -06:00 committed by Abdelatif Guettouche
parent 89578b3a89
commit 5d123098b8
4 changed files with 165 additions and 65 deletions

View File

@ -239,8 +239,10 @@ static inline void imxrt_lpi2c_modifyreg(FAR struct imxrt_lpi2c_priv_s *priv,
uint16_t offset, uint32_t clearbits,
uint32_t setbits);
static inline int imxrt_lpi2c_sem_wait(FAR struct imxrt_lpi2c_priv_s *priv);
#ifdef CONFIG_I2C_RESET
static int
imxrt_lpi2c_sem_wait_noncancelable(FAR struct imxrt_lpi2c_priv_s *priv);
#endif
#ifdef CONFIG_IMXRT_LPI2C_DYNTIMEO
static useconds_t imxrt_lpi2c_tousecs(int msgc, FAR struct i2c_msg_s *msgs);
@ -543,11 +545,13 @@ static inline int imxrt_lpi2c_sem_wait(FAR struct imxrt_lpi2c_priv_s *priv)
*
****************************************************************************/
#ifdef CONFIG_I2C_RESET
static int
imxrt_lpi2c_sem_wait_noncancelable(FAR struct imxrt_lpi2c_priv_s *priv)
{
return nxsem_wait_uninterruptible(&priv->sem_excl);
}
#endif
/****************************************************************************
* Name: imxrt_lpi2c_tousecs

View File

@ -138,9 +138,9 @@ static struct lc823450_partinfo_s partinfo[LC823450_NPARTS] =
* Name: mtd_semtake
****************************************************************************/
static void mtd_semtake(FAR sem_t *sem)
static int mtd_semtake(FAR sem_t *sem)
{
nxsem_wait_uninterruptible(sem);
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
@ -196,7 +196,8 @@ static ssize_t lc823450_bread(FAR struct mtd_dev_s *dev, off_t startblock,
type = SDDR_RW_INC_BYTE;
}
finfo("startblockr=%d, nblocks=%d buf=0x%08p type=%x\n", startblock, nblocks, buf, type);
finfo("startblockr=%d, nblocks=%d buf=0x%08p type=%x\n",
startblock, nblocks, buf, type);
DEBUGASSERT(dev && buf);
@ -205,7 +206,11 @@ static ssize_t lc823450_bread(FAR struct mtd_dev_s *dev, off_t startblock,
return -EINVAL;
}
mtd_semtake(&priv->sem);
ret = mtd_semtake(&priv->sem);
if (ret < 0)
{
return ret;
}
if (!g_mtdmaster[priv->channel])
{
@ -226,7 +231,8 @@ static ssize_t lc823450_bread(FAR struct mtd_dev_s *dev, off_t startblock,
if (ret != OK)
{
finfo("ERROR: Failed to read sector, ret=%d startblock=%d nblocks=%d\n",
finfo("ERROR: Failed to read sector, ret=%d startblock=%d "
"nblocks=%d\n",
ret, startblock, nblocks);
return ret;
}
@ -263,7 +269,8 @@ static ssize_t lc823450_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
type = SDDR_RW_INC_BYTE;
}
finfo("startblockr=%d, nblocks=%d buf=0x%08p type=%x\n", startblock, nblocks, buf, type);
finfo("startblockr=%d, nblocks=%d buf=0x%08p type=%x\n",
startblock, nblocks, buf, type);
DEBUGASSERT(dev && buf);
@ -272,7 +279,11 @@ static ssize_t lc823450_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
return -EINVAL;
}
mtd_semtake(&priv->sem);
ret = mtd_semtake(&priv->sem);
if (ret < 0)
{
return ret;
}
if (!g_mtdmaster[priv->channel])
{
@ -293,7 +304,8 @@ static ssize_t lc823450_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
if (ret != OK)
{
finfo("ERROR: Failed to write sector, ret=%d startblock=%d nblocks=%d\n",
finfo("ERROR: Failed to write sector, ret=%d startblock=%d "
"nblocks=%d\n",
ret, startblock, nblocks);
return ret;
}
@ -305,16 +317,23 @@ static ssize_t lc823450_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
* Name: lc823450_ioctl
****************************************************************************/
static int lc823450_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
static int lc823450_ioctl(FAR struct mtd_dev_s *dev, int cmd,
unsigned long arg)
{
int ret = -EINVAL;
int ret;
FAR struct lc823450_mtd_dev_s *priv = (FAR struct lc823450_mtd_dev_s *)dev;
FAR struct mtd_geometry_s *geo;
FAR void **ppv;
finfo("cmd=%xh, arg=%xh\n", cmd, arg);
mtd_semtake(&priv->sem);
ret = mtd_semtake(&priv->sem);
if (ret < 0)
{
return ret;
}
ret = -EINVAL;
if (!g_mtdmaster[priv->channel])
{
@ -330,8 +349,8 @@ static int lc823450_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
geo = (FAR struct mtd_geometry_s *)arg;
if (geo)
{
/* Populate the geometry structure with information needed to know
* the capacity and how to access the device.
/* Populate the geometry structure with information needed to
* know the capacity and how to access the device.
*/
geo->blocksize = priv->blocksize;
@ -395,14 +414,18 @@ static int lc823450_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
static int mtd_mediainitialize(FAR struct lc823450_mtd_dev_s *dev)
{
int ret = 0;
int ret;
unsigned long nblocks;
unsigned long blocksize;
uint32_t sysclk = lc823450_get_ahb();
finfo("enter\n");
mtd_semtake(&dev->sem);
ret = mtd_semtake(&dev->sem);
if (ret < 0)
{
return ret;
}
ret = lc823450_sdc_initialize(dev->channel);
DEBUGASSERT(ret == OK);
@ -443,6 +466,7 @@ static int mtd_mediainitialize(FAR struct lc823450_mtd_dev_s *dev)
goto get_card_size;
}
#endif
/* Try to change to High Speed mode */
ret = lc823450_sdc_changespeedmode(dev->channel, 1);
@ -479,7 +503,8 @@ get_card_size:
lc823450_sdc_cachectl(dev->channel, 1);
}
finfo("ch=%d size=%lld \n", dev->channel, (uint64_t)blocksize * (uint64_t)nblocks);
finfo("ch=%d size=%lld \n",
dev->channel, (uint64_t)blocksize * (uint64_t)nblocks);
exit_with_error:
mtd_semgive(&dev->sem);
@ -569,7 +594,8 @@ int lc823450_mtd_initialize(uint32_t devno)
#if CONFIG_MTD_DEV_MAX == 1
DEBUGASSERT(devno == CONFIG_MTD_DEVNO_EMMC);
#else
DEBUGASSERT(devno == CONFIG_MTD_DEVNO_EMMC || devno == CONFIG_MTD_DEVNO_SDC);
DEBUGASSERT(devno == CONFIG_MTD_DEVNO_EMMC ||
devno == CONFIG_MTD_DEVNO_SDC);
#endif
/* Following block devices are created.
@ -581,7 +607,11 @@ int lc823450_mtd_initialize(uint32_t devno)
* /dev/mtdblock0pN : Nth child partition
*/
mtd_semtake(&g_sem);
ret = mtd_semtake(&g_sem);
if (ret < 0)
{
return ret;
}
if (g_mtdmaster[ch])
{
@ -603,7 +633,8 @@ int lc823450_mtd_initialize(uint32_t devno)
ret = mmcl_initialize(devno, g_mtdmaster[ch]);
if (ret != OK)
{
finfo("Failed to create block device on master partition: ch=%d\n", ch);
finfo("Failed to create block device on master partition: ch=%d\n",
ch);
kmm_free(g_mtdmaster[ch]);
g_mtdmaster[ch] = NULL;
mtd_semgive(&g_sem);
@ -637,7 +668,8 @@ int lc823450_mtd_initialize(uint32_t devno)
{
DEBUGASSERT(partinfo[i].startblock < partinfo[i + 1].startblock);
DEBUGASSERT(partinfo[i].startblock + partinfo[i].nblocks <= maxblock);
DEBUGASSERT(partinfo[i + 1].startblock + partinfo[i + 1].nblocks <= maxblock);
DEBUGASSERT(partinfo[i + 1].startblock + partinfo[i + 1].nblocks <=
maxblock);
}
#endif
@ -649,8 +681,10 @@ int lc823450_mtd_initialize(uint32_t devno)
{
if (partinfo[i].nblocks == 0)
{
partinfo[i].nblocks = (i == 0)? maxblock - partinfo[i].startblock :
maxblock - (partinfo[i - 1].startblock + partinfo[i - 1].nblocks);
partinfo[i].nblocks = (i == 0) ?
maxblock - partinfo[i].startblock :
maxblock - (partinfo[i - 1].startblock +
partinfo[i - 1].nblocks);
}
}
@ -743,7 +777,6 @@ exit_with_error:
return ret;
}
/****************************************************************************
* Name: lc823450_mtd_uninitialize
****************************************************************************/
@ -758,7 +791,11 @@ int lc823450_mtd_uninitialize(uint32_t devno)
DEBUGASSERT(devno == CONFIG_MTD_DEVNO_SDC);
mtd_semtake(&g_sem);
ret = mtd_semtake(&g_sem);
if (ret < 0)
{
return ret;
}
priv = (FAR struct lc823450_mtd_dev_s *)g_mtdmaster[ch];
if (!priv)
@ -774,7 +811,12 @@ int lc823450_mtd_uninitialize(uint32_t devno)
mtd_unregister(g_mtdmaster[ch]);
#endif
mtd_semtake(&priv->sem);
ret = mtd_semtake(&priv->sem);
if (ret < 0)
{
mtd_semgive(&g_sem);
return ret;
}
ret = lc823450_sdc_clearcardinfo(ch);
DEBUGASSERT(ret == OK);

View File

@ -136,9 +136,9 @@ extern SINT_T sddep_write(void *src, void *dst, UI_32 size, SINT_T type,
* Name: _sdc_semtake
****************************************************************************/
static void _sdc_semtake(FAR sem_t *sem)
static int _sdc_semtake(FAR sem_t *sem)
{
nxsem_wait_uninterruptible(sem);
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
@ -200,7 +200,12 @@ int lc823450_sdc_clearcardinfo(uint32_t ch)
int ret;
mcinfo("++++ start \n");
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
ret = SdDrClearCardInfo(_cfg[ch]);
@ -270,10 +275,14 @@ int lc823450_sdc_initialize(uint32_t ch)
}
mcinfo("++++ start \n");
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrInitialize(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrInitialize(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
return ret;
}
@ -287,10 +296,14 @@ int lc823450_sdc_finalize(uint32_t ch)
int ret;
mcinfo("++++ start ch=%ld \n", ch);
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrFinalize(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrFinalize(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
return ret;
}
@ -304,7 +317,12 @@ int lc823450_sdc_identifycard(uint32_t ch)
int ret;
mcinfo("++++ start \n");
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
ret = SdDrIdentifyCard(_cfg[ch]);
@ -330,10 +348,14 @@ int lc823450_sdc_setclock(uint32_t ch, uint32_t limitclk, uint32_t sysclk)
int ret;
mcinfo("++++ start ch=%ld limitClk=%ld sysClk=%ld\n", ch, limitClk, sysClk);
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrSetClock(limitclk, sysclk, _cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrSetClock(limitclk, sysclk, _cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
return ret;
}
@ -351,10 +373,14 @@ int lc823450_sdc_refmediatype(uint32_t ch)
int ret;
mcinfo("++++ start \n");
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrRefMediaType(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrRefMediaType(_cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
return ret;
}
@ -369,12 +395,16 @@ int lc823450_sdc_getcardsize(uint32_t ch,
int ret;
mcinfo("++++ start \n");
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrGetCardSize(psecnum, psecsize, _cfg[ch]);
ret =_sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrGetCardSize(psecnum, psecsize, _cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
return ret;
}
@ -386,10 +416,14 @@ int lc823450_sdc_readsector(uint32_t ch,
unsigned long addr, unsigned short cnt,
void *pbuf, unsigned long type)
{
int ret = 0;
int ret;
int i = 0;
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
#ifdef CONFIG_LC823450_SDC_LOG
mcinfo("++++ start ch=%d, addr=%ld, cnt=%d \n", ch, addr, cnt);
@ -470,7 +504,11 @@ int lc823450_sdc_writesector(uint32_t ch,
{
int ret;
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
#ifdef CONFIG_LC823450_SDC_LOG
mcinfo("++++ start ch=%d, addr=%ld, cnt=%d \n", ch, addr, cnt);
@ -519,7 +557,11 @@ int lc823450_sdc_trimsector(uint32_t ch, unsigned long addr, unsigned short cnt)
{
int ret;
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
#ifdef CONFIG_LC823450_SDC_LOG
mcinfo("++++ start ch=%d, addr=%ld, cnt=%d \n", ch, addr, cnt);
@ -552,12 +594,16 @@ int lc823450_sdc_cachectl(uint32_t ch, int ctrl)
int ret;
mcinfo("++++ ch=%d, ctrl=%d \n", ch, ctrl);
_sdc_semtake(&_sdc_sem[ch]);
ret = SdDrCacheCtrl(ctrl, _cfg[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret >= 0)
{
ret = SdDrCacheCtrl(ctrl, _cfg[ch]);
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
}
_sdc_semgive(&_sdc_sem[ch]);
mcinfo("---- end ret=%d \n", ret);
return ret;
}
@ -570,7 +616,12 @@ int lc823450_sdc_changespeedmode(uint32_t ch, int mode)
int ret;
mcinfo("++++ ch=%d, mode=%d \n", ch, mode);
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
ret = SdDrChangeSpeedMode(mode, _cfg[ch]);
@ -607,7 +658,12 @@ int lc823450_sdc_getcid(uint32_t ch, char *cidstr, int length)
int ret;
mcinfo("++++ ch=%d \n", ch);
_sdc_semtake(&_sdc_sem[ch]);
ret = _sdc_semtake(&_sdc_sem[ch]);
if (ret < 0)
{
return ret;
}
ret = SdDrGetCid((UI_32 *)cid, _cfg[ch]);

View File

@ -131,9 +131,9 @@ static void dma_callback(DMA_HANDLE hdma, void *arg, int result)
* Name: _sddep_semtake
****************************************************************************/
static void _sddep_semtake(FAR sem_t *sem)
static int _sddep_semtake(FAR sem_t *sem)
{
nxsem_wait_uninterruptible(sem);
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
@ -421,8 +421,7 @@ SINT_T sddep_read(void *src, void *dst, UI_32 size, SINT_T type,
}
lc823450_dmastart(_hrdma[ch], dma_callback, &_sem_rwait[ch]);
_sddep_semtake(&_sem_rwait[ch]);
return 0;
return _sddep_semtake(&_sem_rwait[ch]);
#else
SINT_T i;
UI_32 *p = (UI_32 *)src;
@ -510,8 +509,7 @@ SINT_T sddep_write(void *src, void *dst, UI_32 size, SINT_T type,
}
lc823450_dmastart(_hwdma[ch], dma_callback, &_sem_wwait[ch]);
_sddep_semtake(&_sem_wwait[ch]);
return 0;
return _sddep_semtake(&_sem_wwait[ch]);
#else
SINT_T i;