Linux Kernels

apparmor: cleanup: simplify code to get ns symlink name

This change “apparmor: cleanup: simplify code to get ns symlink name” (commit a078120) in Linux kernel is authored by John Johansen <john.johansen [at] canonical.com> on Mon Feb 5 18:26:46 2018 +0100.

The change “apparmor: cleanup: simplify code to get ns symlink name” introduces changes as follows.

apparmor: cleanup: simplify code to get ns symlink name

ns_get_name() is called in only one place and can be folded in.

Signed-off-by: John Johansen <john.johansen@canonical.com>

Linux kernel releases containing commit a078120

The Linux kernel releases containing this commit are as follows.

There are 25 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 security/apparmor/apparmorfs.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)
 
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 8cdab3c5bc63..1e63ff2e5b85 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -119,9 +119,7 @@ static int aafs_count;
 
 static int aafs_show_path(struct seq_file *seq, struct dentry *dentry)
 {
-	struct inode *inode = d_inode(dentry);
-
-	seq_printf(seq, "%s:[%lu]", AAFS_NAME, inode->i_ino);
+	seq_printf(seq, "%s:[%lu]", AAFS_NAME, d_inode(dentry)->i_ino);
 	return 0;
 }
 
@@ -2392,29 +2390,18 @@ static const char *policy_get_link(struct dentry *dentry,
 	return NULL;
 }
 
-static int ns_get_name(char *buf, size_t size, struct aa_ns *ns,
-		       struct inode *inode)
-{
-	int res = snprintf(buf, size, "%s:[%lu]", AAFS_NAME, inode->i_ino);
-
-	if (res < 0 || res >= size)
-		res = -ENOENT;
-
-	return res;
-}
-
 static int policy_readlink(struct dentry *dentry, char __user *buffer,
 			   int buflen)
 {
-	struct aa_ns *ns;
 	char name[32];
 	int res;
 
-	ns = aa_get_current_ns();
-	res = ns_get_name(name, sizeof(name), ns, d_inode(dentry));
-	if (res >= 0)
+	res = snprintf(name, sizeof(name), "%s:[%lu]", AAFS_NAME,
+		       d_inode(dentry)->i_ino);
+	if (res > 0 && res < sizeof(name))
 		res = readlink_copy(buffer, buflen, name);
-	aa_put_ns(ns);
+	else
+		res = -ENOENT;
 
 	return res;
 }

The commit for this change in Linux stable tree is a078120 (patch).

Last modified: 2020/01/11 06:38