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:
parent
7312a553bb
commit
c1f9d2c2d5
@ -229,7 +229,7 @@ static void mmcsd_mediachange(FAR void *arg);
|
||||
static int mmcsd_widebus(FAR struct mmcsd_state_s *priv);
|
||||
#ifdef CONFIG_MMCSD_MMCSUPPORT
|
||||
static int mmcsd_mmcinitialize(FAR struct mmcsd_state_s *priv);
|
||||
static int mmcsd_read_csd (FAR struct mmcsd_state_s *priv);
|
||||
static int mmcsd_read_csd(FAR struct mmcsd_state_s *priv);
|
||||
#endif
|
||||
static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv);
|
||||
static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv);
|
||||
@ -3668,12 +3668,8 @@ static int mmcsd_hwinitialize(FAR struct mmcsd_state_s *priv)
|
||||
|
||||
static void mmcsd_hwuninitialize(FAR struct mmcsd_state_s *priv)
|
||||
{
|
||||
if (priv)
|
||||
{
|
||||
mmcsd_removed(priv);
|
||||
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 *)
|
||||
kmm_malloc(sizeof(struct mmcsd_state_s));
|
||||
if (priv)
|
||||
if (priv == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Initialize the MMC/SD state structure */
|
||||
|
||||
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);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@ -3792,10 +3790,9 @@ errout_with_buffers:
|
||||
rwb_uninitialize(&priv->rwbuffer);
|
||||
errout_with_hwinit:
|
||||
#endif
|
||||
mmcsd_hwuninitialize(priv); /* This will free the private data structure */
|
||||
return ret;
|
||||
|
||||
mmcsd_hwuninitialize(priv);
|
||||
errout_with_alloc:
|
||||
nxsem_destroy(&priv->sem);
|
||||
kmm_free(priv);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user