Skip to contentSkip to conversation

sysfs: add necessary Null check in sysfs_do_create_link_sd

PATCH In review Rui Xiang 2 participants 3 messages Dec 3, 2013 Driver core

lore
Share & tools
lore

Rui Xiang

author
#0 lore raw

PATCH 1/1 sysfs: add necessary Null check in sysfs_do_create_link_sd

While target_sd or sd are null, it won't need sysfs_put and should return -ENOENT directly. Here add null check for target_sd and sd.

---
 fs/sysfs/symlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/sysfs/symlink.c +4 -2
index 3ae3f1b..d69b786 100644
@@ -83,8 +83,10 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
 	return 0;
 
  out_put:
-	sysfs_put(target_sd);
-	sysfs_put(sd);
+	if (target_sd)
+		sysfs_put(target_sd);
+	if (sd)
+		sysfs_put(sd);
 	return error;
 }
 
Signature · 1 line
1.8.2.2
#1 lore raw
Quoted 14 lines · Rui Xiang

While target_sd or sd are null, it won't need sysfs_put and should return -ENOENT directly. Here add null check for target_sd and sd.

---
 fs/sysfs/symlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/sysfs/symlink.c +0 -0
index 3ae3f1b..d69b786 100644

fs/sysfs/symlink.c static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, · line 89

Quoted 9 lines
fs/sysfs/symlink.c +4 -2
@@ -83,8 +83,10 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
 	return 0;
 
  out_put:
-	sysfs_put(target_sd);
-	sysfs_put(sd);
+	if (target_sd)
+		sysfs_put(target_sd);
+	if (sd)
+		sysfs_put(sd);

This change does nothing at all, why is it needed?

greg k-h

author
#2 lore raw
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Rui Xiang

While target_sd or sd are null, it won't need sysfs_put and should return -ENOENT directly. Here add null check for target_sd and sd.

---
 fs/sysfs/symlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/sysfs/symlink.c +0 -0
index 3ae3f1b..d69b786 100644
@@ -83,8 +83,10 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
 	return 0;
 
Quoted 10 lines

fs/sysfs/symlink.c static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, · line 89

Quoted 7 lines
fs/sysfs/symlink.c +4 -2
  out_put:
-	sysfs_put(target_sd);
-	sysfs_put(sd);
+	if (target_sd)
+		sysfs_put(target_sd);
+	if (sd)
+		sysfs_put(sd);

This change does nothing at all, why is it needed?

oh, I noted sysfs_put has a null check. So these are unnecessary. Sorry, please ignore it.

Thanks,
Rui