mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 04:16:35 +08:00
fs/partiton: add sanity check
mmcsd_spi don't support ioctl when blocksize is zero, will cause crash. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
224f53fe02
commit
e02a5a70eb
@@ -155,10 +155,12 @@ int parse_block_partition(FAR const char *path,
|
||||
|
||||
state.mtd = NULL;
|
||||
|
||||
ret = state.blk->u.i_bops->ioctl(
|
||||
state.blk, MTDIOC_GEOMETRY, (unsigned long)(uintptr_t)&mgeo);
|
||||
if (ret >= 0)
|
||||
if (state.blk->u.i_bops->ioctl != NULL &&
|
||||
state.blk->u.i_bops->ioctl(state.blk, MTDIOC_GEOMETRY,
|
||||
(unsigned long)(uintptr_t)&mgeo) >= 0)
|
||||
{
|
||||
DEBUGASSERT(mgeo.blocksize);
|
||||
|
||||
state.blocksize = mgeo.blocksize;
|
||||
state.erasesize = mgeo.erasesize;
|
||||
state.nblocks = mgeo.neraseblocks;
|
||||
@@ -171,6 +173,8 @@ int parse_block_partition(FAR const char *path,
|
||||
ret = state.blk->u.i_bops->geometry(state.blk, &geo);
|
||||
if (ret >= 0)
|
||||
{
|
||||
DEBUGASSERT(geo.geo_sectorsize);
|
||||
|
||||
state.blocksize = geo.geo_sectorsize;
|
||||
state.erasesize = geo.geo_sectorsize;
|
||||
state.nblocks = geo.geo_nsectors;
|
||||
@@ -213,6 +217,8 @@ int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEBUGASSERT(mgeo.blocksize);
|
||||
|
||||
state.blk = NULL;
|
||||
state.mtd = mtd;
|
||||
state.blocksize = mgeo.blocksize;
|
||||
|
||||
Reference in New Issue
Block a user