efivarfs: 'efivarfs_file_write' function reorganization
Subsystems (2)
PATCH 1/1 efivarfs: 'efivarfs_file_write' function reorganization
This reorganization:
Adds 'attrsize' variable to make the code cleaner and more understandable, replacing all 'sizeof(attributes)'.
Removes 'bytes' prior assignment due this new approach.
Uses 'memdup_user' instead 'kmalloc' + 'copy_from_user'.
--- fs/efivarfs/file.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
fs/efivarfs/file.c +9 -14
@@ -18,29 +18,24 @@ static ssize_t efivarfs_file_write(struct file *file, {struct efivar_entry *var = file->private_data;void *data; -u32 attributes; +u32 attributes, attrsize =sizeof (attributes);struct inode *inode = file->f_mapping->host; -unsigned long datasize = count -sizeof (attributes); -ssize_t bytes =0 ; +unsigned long datasize = count - attrsize; +ssize_t bytes;bool set = false; -if (count <sizeof (attributes)) +if (count < attrsize)return -EINVAL ; -if (copy_from_user (&attributes, userbuf,sizeof (attributes))) +if (copy_from_user (&attributes, userbuf, attrsize))return -EFAULT ;if (attributes & ~(EFI_VARIABLE_MASK ))return -EINVAL ; - data =kmalloc (datasize,GFP_KERNEL ); -if (!data) -return -ENOMEM ; - -if (copy_from_user (data, userbuf +sizeof (attributes), datasize)) { - bytes = -EFAULT ; - goto out; - } + data =memdup_user (userbuf + attrsize, datasize); +if (IS_ERR (data)) +return PTR_ERR (data); bytes =efivar_entry_set_get_size (var, attributes, &datasize, data, &set);
@@ -56,7 +51,7 @@ static ssize_t efivarfs_file_write(struct file *file,dput (file->f_dentry); }else {mutex_lock (&inode->i_mutex); -i_size_write (inode, datasize +sizeof (attributes)); +i_size_write (inode, datasize + attrsize);mutex_unlock (&inode->i_mutex); }
Signature · 1 line
1.8.4
Quoted 5 lines · Geyslan G. Bem
This reorganization:
Adds 'attrsize' variable to make the code cleaner and more understandable, replacing all 'sizeof(attributes)'.
Quoted 8 lines
Removes 'bytes' prior assignment due this new approach.
Uses '
memdup_user' instead 'kmalloc' + 'copy_from_user'.Signed-off-by Geyslan G. Bem <[email protected]>--- fs/efivarfs/file.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
Hmm.. I'm not convinced this is much of an improvement. I think removing 'sizeof(attributes)' actually makes the code harder to read.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
2013/10/30 Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/[email protected]>:
Quoted 15 lines · Geyslan G. Bem
Quoted 5 lines
This reorganization:
Adds 'attrsize' variable to make the code cleaner and more understandable, replacing all 'sizeof(attributes)'.
Quoted 8 lines
Removes 'bytes' prior assignment due this new approach.
Uses '
memdup_user' instead 'kmalloc' + 'copy_from_user'.Signed-off-by Geyslan G. Bem <[email protected]>--- fs/efivarfs/file.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
Quoted 5 lines
Hmm.. I'm not convinced this is much of an improvement. I think removing 'sizeof(attributes)' actually makes the code harder to read.
--
Matt Fleming, Intel Open Source Technology Center
Do you want that I undo that? I aggre that the variable use only reduces the line code.
Signature · 4 lines
Regards, Geyslan G. Bem hackingbits.com
Quoted 2 lines · Geyslan Gregório Bem
Do you want that I undo that? I aggre that the variable use only reduces the line code.
Yes please.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
2013/10/30 Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/[email protected]>:
Quoted 8 lines · Geyslan Gregório Bem
Quoted 2 lines
Do you want that I undo that? I aggre that the variable use only reduces the line code.
Yes please.
--
Matt Fleming, Intel Open Source Technology Center
Done:
[PATCH v2] efivarfs: 'efivarfs_file_write' function reorganization
Signature · 4 lines
Regards, Geyslan G. Bem hackingbits.com