Skip to contentSkip to conversation

sysfs & dput.

PATCH In review Martin Schwidefsky 2 participants 2 messages Sep 11, 2003 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysfs & dput.

Hi Pat,
there is another, small bug in sysfs. In sysfs_create_bin_file dentry gets assigned the error value of the call to sysfs_create if the call failed. The subsequent call to dput will crash. The solution is to remove the assignment of the error to dentry.

blue skies,
Martin.

diffstat:

 fs/sysfs/file.c |    2 --
 1 files changed, 2 deletions(-)
fs/sysfs/file.c +0 -2
diff -urN linux-2.6/fs/sysfs/file.c linux-2.6-s390/fs/sysfs/file.c
@@ -356,8 +356,6 @@
 		error = sysfs_create(dentry,(attr->mode & S_IALLUGO) | S_IFREG,init_file);
 		if (!error)
 			dentry->d_fsdata = (void *)attr;
-		else
-			dentry = ERR_PTR(error);
 		dput(dentry);
 	} else
 		error = PTR_ERR(dentry);
#1 lore raw
Quoted 5 lines

there is another, small bug in sysfs. In sysfs_create_bin_file dentry gets assigned the error value of the call to sysfs_create if the call failed. The subsequent call to dput will crash. The solution is to remove the assignment of the error to dentry.

Thanks for the catch; Andrew Morton also posted a patch yesterday. However, your patch drops the error value, and his adds another variable. The patch below should be equivalent (and fixes the same problem for directories, too).

Please test it, if you get a chance.

Quoted 1 line

blue skies,

Heh, not today. :)

Thanks,

Pat

===== fs/sysfs/dir.c 1.11 vs edited =====

fs/sysfs/dir.c +1 -1
@@ -32,12 +32,12 @@
 		int error = sysfs_create(dentry,
 					 S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO,
 					 init_dir);
+		dput(dentry);
 		if (!error) {
 			dentry->d_fsdata = k;
 			p->d_inode->i_nlink++;
 		} else
 			dentry = ERR_PTR(error);
-		dput(dentry);
 	}
 	up(&p->d_inode->i_sem);
 	return dentry;

===== fs/sysfs/file.c 1.11 vs edited =====

fs/sysfs/file.c +4 -2
@@ -353,12 +353,14 @@
 	down(&dir->d_inode->i_sem);
 	dentry = sysfs_get_dentry(dir,attr->name);
 	if (!IS_ERR(dentry)) {
-		error = sysfs_create(dentry,(attr->mode & S_IALLUGO) | S_IFREG,init_file);
+		error = sysfs_create(dentry,
+				     (attr->mode & S_IALLUGO) | S_IFREG,
+				     init_file);
+		dput(dentry);
 		if (!error)
 			dentry->d_fsdata = (void *)attr;
 		else
 			dentry = ERR_PTR(error);
-		dput(dentry);
 	} else
 		error = PTR_ERR(dentry);
 	up(&dir->d_inode->i_sem);