Skip to contentSkip to conversation

fs/ntfs3: Fix minor things in ntfs_get_acl_ex()

PATCH In review Kari Argillander 1 participant 4 messages Aug 26, 2021 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

cover fs/ntfs3: Fix minor things in ntfs_get_acl_ex()

First patch fix Smatch warning.

Second one add missing default path. This is not necessarylly needed, but will not make any harm and other filesystems have it and it is also checked some places in ntfs3. So let's be consistent.

Kari Argillander (2):
fs/ntfs3: Fix pass zero to ERR_PTR() in ntfs_get_acl_ex fs/ntfs3: Fix missing type checking in ntfs_get_acl_ex

 fs/ntfs3/xattr.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 fs/ntfs3: Fix pass zero to ERR_PTR() in ntfs_get_acl_ex

Fix smatch warning:

	fs/ntfs3/xattr.c:529 ntfs_get_acl_ex()
	warn: passing zero to 'ERR_PTR'
Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
---
 fs/ntfs3/xattr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ntfs3/xattr.c +3 -1
index 98871c895e77..944557d3a769 100644
@@ -525,8 +525,10 @@ static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns,
 		acl = posix_acl_from_xattr(mnt_userns, buf, err);
 		if (!IS_ERR(acl))
 			set_cached_acl(inode, type, acl);
+	} else if (!err || err == -ENODATA) {
+		acl = NULL;
 	} else {
-		acl = err == -ENODATA ? NULL : ERR_PTR(err);
+		acl = ERR_PTR(err);
 	}
 
 	__putname(buf);
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] fs/ntfs3: Fix pass zero to ERR_PTR() in ntfs_get_acl_ex

Quoted 16 lines · Kari Argillander

Fix smatch warning:

	fs/ntfs3/xattr.c:529 ntfs_get_acl_ex()
	warn: passing zero to 'ERR_PTR'
Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
---
 fs/ntfs3/xattr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ntfs3/xattr.c +0 -0
index 98871c895e77..944557d3a769 100644
@@ -525,8 +525,10 @@ static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns,
 		acl = posix_acl_from_xattr(mnt_userns, buf, err);

fs/ntfs3/xattr.c static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns, · line 534

Quoted 10 lines
fs/ntfs3/xattr.c +3 -1
 		if (!IS_ERR(acl))
 			set_cached_acl(inode, type, acl);
+	} else if (!err || err == -ENODATA) {
+		acl = NULL;
 	} else {
-		acl = err == -ENODATA ? NULL : ERR_PTR(err);
+		acl = ERR_PTR(err);
 	}
 
 	__putname(buf);

I just notice that this is same as Dan already has sended:
https://lore.kernel.org/ntfs3/20210824114858.GH31143@kili/

You can choose if you prefer this or that. Sorry for double patch.

#3 lore raw

PATCH 2/2 fs/ntfs3: Fix missing type checking in ntfs_get_acl_ex

In reply to Kari Argillander

Add default path for type checking. Comment says that this is checked above, but for fast eyes I do not find it. We have this check also in ntfs_set_acl_ex() so let's be consistent. Also other fs driver had implemented default path. Some are even throwing BUG(), but that feels little too harsh.

Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
---
 fs/ntfs3/xattr.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
fs/ntfs3/xattr.c +12 -8
index 944557d3a769..5e86bea7e0ab 100644
@@ -498,20 +498,24 @@ static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns,
 	int err;
 	void *buf;
 
-	/* allocate PATH_MAX bytes */
-	buf = __getname();
-	if (!buf)
-		return ERR_PTR(-ENOMEM);
-
-	/* Possible values of 'type' was already checked above */
-	if (type == ACL_TYPE_ACCESS) {
+	switch (type) {
+	case ACL_TYPE_ACCESS:
 		name = XATTR_NAME_POSIX_ACL_ACCESS;
 		name_len = sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1;
-	} else {
+		break;
+	case ACL_TYPE_DEFAULT:
 		name = XATTR_NAME_POSIX_ACL_DEFAULT;
 		name_len = sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1;
+		break;
+	default:
+		return ERR_PTR(-EINVAL);
 	}
 
+	/* allocate PATH_MAX bytes */
+	buf = __getname();
+	if (!buf)
+		return ERR_PTR(-ENOMEM);
+
 	if (!locked)
 		ni_lock(ni);
 
Signature · 1 line
2.25.1