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:
dongjiuzhu1
2022-10-13 16:47:28 +08:00
committed by Alan Carvalho de Assis
parent 224f53fe02
commit e02a5a70eb
+9 -3
View File
@@ -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;