mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
drivers/mmcsd: Handle the failure correctly in mmcsd_slotinitialize
1.Return -ENOMEM directly if kmm_malloc return NULL 2.Call nxsem_destroy if the initialization can't succeed Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
7312a553bb
commit
c1f9d2c2d5
@@ -3667,13 +3667,9 @@ static int mmcsd_hwinitialize(FAR struct mmcsd_state_s *priv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void mmcsd_hwuninitialize(FAR struct mmcsd_state_s *priv)
|
static void mmcsd_hwuninitialize(FAR struct mmcsd_state_s *priv)
|
||||||
{
|
|
||||||
if (priv)
|
|
||||||
{
|
{
|
||||||
mmcsd_removed(priv);
|
mmcsd_removed(priv);
|
||||||
SDIO_RESET(priv->dev);
|
SDIO_RESET(priv->dev);
|
||||||
kmm_free(priv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -3715,8 +3711,11 @@ int mmcsd_slotinitialize(int minor, FAR struct sdio_dev_s *dev)
|
|||||||
|
|
||||||
priv = (FAR struct mmcsd_state_s *)
|
priv = (FAR struct mmcsd_state_s *)
|
||||||
kmm_malloc(sizeof(struct mmcsd_state_s));
|
kmm_malloc(sizeof(struct mmcsd_state_s));
|
||||||
if (priv)
|
if (priv == NULL)
|
||||||
{
|
{
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the MMC/SD state structure */
|
/* Initialize the MMC/SD state structure */
|
||||||
|
|
||||||
memset(priv, 0, sizeof(struct mmcsd_state_s));
|
memset(priv, 0, sizeof(struct mmcsd_state_s));
|
||||||
@@ -3783,7 +3782,6 @@ int mmcsd_slotinitialize(int minor, FAR struct sdio_dev_s *dev)
|
|||||||
ferr("ERROR: register_blockdriver failed: %d\n", ret);
|
ferr("ERROR: register_blockdriver failed: %d\n", ret);
|
||||||
goto errout_with_buffers;
|
goto errout_with_buffers;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
@@ -3792,10 +3790,9 @@ errout_with_buffers:
|
|||||||
rwb_uninitialize(&priv->rwbuffer);
|
rwb_uninitialize(&priv->rwbuffer);
|
||||||
errout_with_hwinit:
|
errout_with_hwinit:
|
||||||
#endif
|
#endif
|
||||||
mmcsd_hwuninitialize(priv); /* This will free the private data structure */
|
mmcsd_hwuninitialize(priv);
|
||||||
return ret;
|
|
||||||
|
|
||||||
errout_with_alloc:
|
errout_with_alloc:
|
||||||
|
nxsem_destroy(&priv->sem);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user