diff --git a/fs/namei.c b/fs/namei.c
index 5a9291c318815..ffab2e06e1472 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3077,7 +3077,7 @@ static int do_last(struct nameidata *nd, struct path *path,
 	error = -ENOTDIR;
 	if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
 		goto out;
-	if (!S_ISREG(nd->inode->i_mode))
+	if (!d_is_reg(nd->path.dentry))
 		will_truncate = false;
 
 	if (will_truncate) {