driver/mtd_config: just query when data is null or len is zero

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
This commit is contained in:
xucheng5 2023-07-12 14:51:18 +08:00 committed by Xiang Xiao
parent da9b05cc33
commit 23d4263207
1 changed files with 9 additions and 6 deletions

View File

@ -1423,14 +1423,17 @@ static int mtdconfig_getconfig(FAR struct mtdconfig_struct_s *dev,
/* Perform the read */
ret = mtdconfig_readbytes(dev, offset + sizeof(hdr), pdata->configdata,
bytes_to_read);
if (ret != OK)
if (pdata->configdata && bytes_to_read)
{
/* Error reading the data */
ret = mtdconfig_readbytes(dev, offset + sizeof(hdr),
pdata->configdata, bytes_to_read);
if (ret != OK)
{
/* Error reading the data */
ret = -EIO;
goto errout;
ret = -EIO;
goto errout;
}
}
/* Set return data length to match the config item length */