Skip to content

Commit

Permalink
fix(driver/kmod): avoid mixed declarations and code error
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
  • Loading branch information
Andreagit97 committed Jul 23, 2024
1 parent 8b3c688 commit 1aded82
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions driver/ppm_fillers.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ static uint32_t ppm_get_tty(void)

static bool ppm_is_upper_layer(struct file *file)
{
// 3.18 is the Kernel version where overlayfs was introduced
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
return false;
#else
Expand Down Expand Up @@ -884,24 +885,29 @@ static bool ppm_is_upper_layer(struct file *file)
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)
struct ovl_entry *oe = (struct ovl_entry*)(dentry->d_fsdata);
if(!oe)
// New scope to avoid `ISO C90 forbids mixed declarations and code` error
{
return false;
struct ovl_entry *oe = (struct ovl_entry*)(dentry->d_fsdata);
if(!oe)
{
return false;
}
upper_dentry = oe->__upperdentry;
}
upper_dentry = oe->__upperdentry;
#else
char *vfs_inode = (char*)dentry->d_inode;
if(!vfs_inode)
{
return false;
}
char *vfs_inode = (char*)dentry->d_inode;
if(!vfs_inode)
{
return false;
}

// Pointer arithmetics due to unexported ovl_inode struct
// warning: this works if and only if the dentry pointer
// is placed right after the inode struct
// todo!: this is dangerous we should find a way to check it at compile time.
upper_dentry = *(struct dentry **)(vfs_inode + sizeof(struct inode));
// Pointer arithmetics due to unexported ovl_inode struct
// warning: this works if and only if the dentry pointer
// is placed right after the inode struct
// todo!: this is dangerous we should find a way to check it at compile time.
upper_dentry = *(struct dentry **)(vfs_inode + sizeof(struct inode));
}
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)
if(!upper_dentry)
{
Expand Down

0 comments on commit 1aded82

Please sign in to comment.