mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36: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
+53
-56
@@ -229,7 +229,7 @@ static void mmcsd_mediachange(FAR void *arg);
|
|||||||
static int mmcsd_widebus(FAR struct mmcsd_state_s *priv);
|
static int mmcsd_widebus(FAR struct mmcsd_state_s *priv);
|
||||||
#ifdef CONFIG_MMCSD_MMCSUPPORT
|
#ifdef CONFIG_MMCSD_MMCSUPPORT
|
||||||
static int mmcsd_mmcinitialize(FAR struct mmcsd_state_s *priv);
|
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
|
#endif
|
||||||
static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv);
|
static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv);
|
||||||
static int mmcsd_cardidentify(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)
|
static void mmcsd_hwuninitialize(FAR struct mmcsd_state_s *priv)
|
||||||
{
|
{
|
||||||
if (priv)
|
mmcsd_removed(priv);
|
||||||
{
|
SDIO_RESET(priv->dev);
|
||||||
mmcsd_removed(priv);
|
|
||||||
SDIO_RESET(priv->dev);
|
|
||||||
kmm_free(priv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -3715,74 +3711,76 @@ 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)
|
||||||
{
|
{
|
||||||
/* Initialize the MMC/SD state structure */
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
memset(priv, 0, sizeof(struct mmcsd_state_s));
|
/* Initialize the MMC/SD state structure */
|
||||||
nxsem_init(&priv->sem, 0, 1);
|
|
||||||
|
|
||||||
/* Bind the MMCSD driver to the MMCSD state structure */
|
memset(priv, 0, sizeof(struct mmcsd_state_s));
|
||||||
|
nxsem_init(&priv->sem, 0, 1);
|
||||||
|
|
||||||
priv->dev = dev;
|
/* Bind the MMCSD driver to the MMCSD state structure */
|
||||||
|
|
||||||
/* Initialize the hardware associated with the slot */
|
priv->dev = dev;
|
||||||
|
|
||||||
ret = mmcsd_hwinitialize(priv);
|
/* Initialize the hardware associated with the slot */
|
||||||
|
|
||||||
/* Was the slot initialized successfully? */
|
ret = mmcsd_hwinitialize(priv);
|
||||||
|
|
||||||
if (ret != OK)
|
/* Was the slot initialized successfully? */
|
||||||
|
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
/* No... But the error ENODEV is returned if hardware
|
||||||
|
* initialization succeeded but no card is inserted in the slot.
|
||||||
|
* In this case, the no error occurred, but the driver is still
|
||||||
|
* not ready.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ret == -ENODEV)
|
||||||
{
|
{
|
||||||
/* No... But the error ENODEV is returned if hardware
|
/* No card in the slot (or if there is, we could not recognize
|
||||||
* initialization succeeded but no card is inserted in the slot.
|
* it).. Setup to receive the media inserted event
|
||||||
* In this case, the no error occurred, but the driver is still
|
|
||||||
* not ready.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (ret == -ENODEV)
|
SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_INSERTED);
|
||||||
{
|
|
||||||
/* No card in the slot (or if there is, we could not recognize
|
|
||||||
* it).. Setup to receive the media inserted event
|
|
||||||
*/
|
|
||||||
|
|
||||||
SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_INSERTED);
|
finfo("MMC/SD slot is empty\n");
|
||||||
|
|
||||||
finfo("MMC/SD slot is empty\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Some other non-recoverable bad thing happened */
|
|
||||||
|
|
||||||
ferr("ERROR: Failed to initialize MMC/SD slot: %d\n", ret);
|
|
||||||
goto errout_with_alloc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Some other non-recoverable bad thing happened */
|
||||||
|
|
||||||
|
ferr("ERROR: Failed to initialize MMC/SD slot: %d\n", ret);
|
||||||
|
goto errout_with_alloc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_DRVR_WRITEBUFFER) || defined(CONFIG_DRVR_READAHEAD)
|
#if defined(CONFIG_DRVR_WRITEBUFFER) || defined(CONFIG_DRVR_READAHEAD)
|
||||||
/* Initialize buffering */
|
/* Initialize buffering */
|
||||||
|
|
||||||
#warning "Missing setup of rwbuffer"
|
#warning "Missing setup of rwbuffer"
|
||||||
ret = rwb_initialize(&priv->rwbuffer);
|
ret = rwb_initialize(&priv->rwbuffer);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ferr("ERROR: Buffer setup failed: %d\n", ret);
|
ferr("ERROR: Buffer setup failed: %d\n", ret);
|
||||||
goto errout_with_hwinit;
|
goto errout_with_hwinit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Create a MMCSD device name */
|
/* Create a MMCSD device name */
|
||||||
|
|
||||||
snprintf(devname, 16, "/dev/mmcsd%d", minor);
|
snprintf(devname, 16, "/dev/mmcsd%d", minor);
|
||||||
|
|
||||||
/* Inode private data is a reference to the MMCSD state structure */
|
/* Inode private data is a reference to the MMCSD state structure */
|
||||||
|
|
||||||
ret = register_blockdriver(devname, &g_bops, 0, priv);
|
ret = register_blockdriver(devname, &g_bops, 0, priv);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
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