gfs2: Remove duplicate i_nlink check from gfs2_link()

The duplication is:

    struct gfs2_inode *ip = GFS2_I(inode);
    [...]
    error = -ENOENT;
    if (inode->i_nlink == 0)
        goto out_gunlock;
    [...]
    error = -EINVAL;
    if (!ip->i_inode.i_nlink)
        goto out_gunlock;

The second check is removed. ENOENT is the correct error code for
attempts to link a deleted inode (ref: link(2)).

If we support O_TMPFILE in future the check will need to be updated with
an exception for inodes flagged I_LINKABLE so sorting out this
duplication now will make it a slightly cleaner change.

Signed-off-by: Andrew Price <anprice@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
This commit is contained in:
Andrew Price 2023-03-14 13:18:27 +00:00 committed by Andreas Gruenbacher
parent 1e760fa359
commit 8dc14966ca

View File

@ -992,9 +992,6 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
error = -EPERM;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
goto out_gunlock;
error = -EINVAL;
if (!ip->i_inode.i_nlink)
goto out_gunlock;
error = -EMLINK;
if (ip->i_inode.i_nlink == (u32)-1)
goto out_gunlock;