Merge patch series "fs: ext4fs: Fix some issues found by Smatch"

Andrew Goodbody <andrew.goodbody@linaro.org> says:

Smatch reported some issues in the ext4fs code. This includes a
suggestion to use an unwind goto, to not negate a return value and to
ensure that a NULL check happens before the pointer is dereferenced.

Link: https://lore.kernel.org/r/20250704-ext4fs_fix-v1-0-5c6acf4bf839@linaro.org
This commit is contained in:
Tom Rini
2025-07-11 10:44:38 -06:00
3 changed files with 10 additions and 8 deletions

View File

@@ -198,16 +198,18 @@ void put_ext4(uint64_t off, const void *buf, uint32_t size)
uint64_t remainder;
unsigned char *temp_ptr = NULL;
struct ext_filesystem *fs = get_fs();
int log2blksz = fs->dev_desc->log2blksz;
int log2blksz;
if (!fs->dev_desc)
return;
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, fs->dev_desc->blksz);
log2blksz = fs->dev_desc->log2blksz;
startblock = off >> log2blksz;
startblock += part_offset;
remainder = off & (uint64_t)(fs->dev_desc->blksz - 1);
if (fs->dev_desc == NULL)
return;
if ((startblock + (size >> log2blksz)) >
(part_offset + fs->total_sect)) {
printf("part_offset is " LBAFU "\n", part_offset);

View File

@@ -877,19 +877,19 @@ int ext4fs_write(const char *fname, const char *buffer,
if (ext4fs_init() != 0) {
printf("error in File System init\n");
return -1;
goto fail;
}
missing_feat = le32_to_cpu(fs->sb->feature_incompat) & ~EXT4_FEATURE_INCOMPAT_SUPP;
if (missing_feat) {
log_err("Unsupported features found %08x, not writing.\n", missing_feat);
return -1;
goto fail;
}
missing_feat = le32_to_cpu(fs->sb->feature_ro_compat) & ~EXT4_FEATURE_RO_COMPAT_SUPP;
if (missing_feat) {
log_err("Unsupported RO compat features found %08x, not writing.\n", missing_feat);
return -1;
goto fail;
}
inodes_per_block = fs->blksz / fs->inodesz;

View File

@@ -277,7 +277,7 @@ int ext4fs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp)
sizeof(struct ext2_dirent),
(char *)&dirent, &actread);
if (ret < 0)
return -ret;
return ret;
if (!dirent.direntlen)
return -EIO;