Skip to contentSkip to conversation

apparmor/file: Removing unnecessary initial values for variable pointers

PATCH In review Li kunyu 3 participants 3 messages Sep 19, 2023 – Sep 28, 2023

Subsystems (2)
lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH v2 1/1 apparmor/file: Removing unnecessary initial values for variable pointers

These variable pointers are assigned during use and do not need to be initialized for assignment.

---
v2: Fix timestamp issues

 security/apparmor/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/apparmor/file.c +2 -2
index 698b124e649f..12eafdf18fc0 100644
@@ -264,7 +264,7 @@ int aa_path_perm(const char *op, struct aa_label *label,
 {
 	struct aa_perms perms = {};
 	struct aa_profile *profile;
-	char *buffer = NULL;
+	char *buffer;
 	int error;
 
 	flags |= PATH_DELEGATE_DELETED | (S_ISDIR(cond->mode) ? PATH_IS_DIR :
@@ -412,7 +412,7 @@ int aa_path_link(struct aa_label *label, struct dentry *old_dentry,
 		d_backing_inode(old_dentry)->i_uid,
 		d_backing_inode(old_dentry)->i_mode
 	};
-	char *buffer = NULL, *buffer2 = NULL;
+	char *buffer, *buffer2;
 	struct aa_profile *profile;
 	int error;
 
Signature · 1 line
2.18.2
maintainer
#1 lore raw
Quoted 15 lines · Li kunyu

These variable pointers are assigned during use and do not need to be initialized for assignment.

---
v2: Fix timestamp issues

  security/apparmor/file.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
security/apparmor/file.c +0 -0
index 698b124e649f..12eafdf18fc0 100644

security/apparmor/file.c int aa_path_perm(const char *op, struct aa_label *label, · line 267

Quoted 5 lines
security/apparmor/file.c +1 -1
@@ -264,7 +264,7 @@ int aa_path_perm(const char *op, struct aa_label *label,
  {
  	struct aa_perms perms = {};
  	struct aa_profile *profile;
-	char *buffer = NULL;
+	char *buffer;

this is okay

security/apparmor/file.c int aa_path_link(struct aa_label *label, struct dentry *old_dentry, · line 415

Quoted 9 lines
security/apparmor/file.c +1 -1
  	int error;
 
  	flags |= PATH_DELEGATE_DELETED | (S_ISDIR(cond->mode) ? PATH_IS_DIR :
@@ -412,7 +412,7 @@ int aa_path_link(struct aa_label *label, struct dentry *old_dentry,
  		d_backing_inode(old_dentry)->i_uid,
  		d_backing_inode(old_dentry)->i_mode
  	};
-	char *buffer = NULL, *buffer2 = NULL;
+	char *buffer, *buffer2;

this can cause an oops if buffer2 allocation fails. There are a couple of ways I can see to fix this, do you want to take a crack at it.

Quoted 3 lines
security/apparmor/file.c +0 -0
  	struct aa_profile *profile;
  	int error;
 
maintainer
#2 lore raw
Quoted 24 lines · John Johansen
Quoted 15 lines · Li kunyu

These variable pointers are assigned during use and do not need to be initialized for assignment.

---
v2: Fix timestamp issues

  security/apparmor/file.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
security/apparmor/file.c +0 -0
index 698b124e649f..12eafdf18fc0 100644

security/apparmor/file.c int aa_path_perm(const char *op, struct aa_label *label, · line 267

Quoted 5 lines
security/apparmor/file.c +1 -1
@@ -264,7 +264,7 @@ int aa_path_perm(const char *op, struct aa_label *label,
  {
  	struct aa_perms perms = {};
  	struct aa_profile *profile;
-	char *buffer = NULL;
+	char *buffer;

this is okay

Quoted 15 lines

security/apparmor/file.c int aa_path_link(struct aa_label *label, struct dentry *old_dentry, · line 415

Quoted 8 lines
security/apparmor/file.c +1 -1
  	int error;
  	flags |= PATH_DELEGATE_DELETED | (S_ISDIR(cond->mode) ? PATH_IS_DIR :
@@ -412,7 +412,7 @@ int aa_path_link(struct aa_label *label, struct dentry *old_dentry,
  		d_backing_inode(old_dentry)->i_uid,
  		d_backing_inode(old_dentry)->i_mode
  	};
-	char *buffer = NULL, *buffer2 = NULL;
+	char *buffer, *buffer2;

this can cause an oops if buffer2 allocation fails. There are a couple of ways I can see to fix this, do you want to take a crack at it.

Quoted 2 lines
security/apparmor/file.c +0 -0
  	struct aa_profile *profile;
  	int error;

I don't whether this kind of thing has become in vogue, but while indeed the first case is okay right now, it becomes more likely that a future patch to this function will inadvertently goto aa_put_buffer(buffer) before the aa_get_buffer call. I would not have NACKed an original version of this fn without the = NULL, but I'm not in favor of dropping it.

-serge