diff options
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index d0e3d8495165..5e83e7246788 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -301,9 +301,8 @@ static int check_perm(struct inode * inode, struct file * file) | |||
301 | /* No error? Great, allocate a buffer for the file, and store it | 301 | /* No error? Great, allocate a buffer for the file, and store it |
302 | * it in file->private_data for easy access. | 302 | * it in file->private_data for easy access. |
303 | */ | 303 | */ |
304 | buffer = kmalloc(sizeof(struct sysfs_buffer),GFP_KERNEL); | 304 | buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL); |
305 | if (buffer) { | 305 | if (buffer) { |
306 | memset(buffer,0,sizeof(struct sysfs_buffer)); | ||
307 | init_MUTEX(&buffer->sem); | 306 | init_MUTEX(&buffer->sem); |
308 | buffer->needs_read_fill = 1; | 307 | buffer->needs_read_fill = 1; |
309 | buffer->ops = ops; | 308 | buffer->ops = ops; |
@@ -362,10 +361,12 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type) | |||
362 | { | 361 | { |
363 | struct sysfs_dirent * parent_sd = dir->d_fsdata; | 362 | struct sysfs_dirent * parent_sd = dir->d_fsdata; |
364 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; | 363 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; |
365 | int error = 0; | 364 | int error = -EEXIST; |
366 | 365 | ||
367 | mutex_lock(&dir->d_inode->i_mutex); | 366 | mutex_lock(&dir->d_inode->i_mutex); |
368 | error = sysfs_make_dirent(parent_sd, NULL, (void *) attr, mode, type); | 367 | if (!sysfs_dirent_exist(parent_sd, attr->name)) |
368 | error = sysfs_make_dirent(parent_sd, NULL, (void *)attr, | ||
369 | mode, type); | ||
369 | mutex_unlock(&dir->d_inode->i_mutex); | 370 | mutex_unlock(&dir->d_inode->i_mutex); |
370 | 371 | ||
371 | return error; | 372 | return error; |