* [PATCH] efivarfs: 'efivarfs_file_write' function reorganization
@ 2013-10-14 18:37 Geyslan G. Bem
[not found] ` <1381775837-26023-1-git-send-email-geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Geyslan G. Bem @ 2013-10-14 18:37 UTC (permalink / raw)
To: matthew.garrett, jk, matt.fleming
Cc: linux-efi, linux-kernel, kernel-br, Geyslan G. Bem
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'.
Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
fs/efivarfs/file.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c
index 8dd524f..e190aa0 100644
--- a/fs/efivarfs/file.c
+++ b/fs/efivarfs/file.c
@@ -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);
}
--
1.8.4
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1381775837-26023-1-git-send-email-geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization [not found] ` <1381775837-26023-1-git-send-email-geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2013-10-30 12:38 ` Matt Fleming [not found] ` <20131030123850.GA8193-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Matt Fleming @ 2013-10-30 12:38 UTC (permalink / raw) To: Geyslan G. Bem Cc: matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA, jk-mnsaURCQ41sdnm+yROfE0A, matt.fleming-ral2JQCrhuEAvxtiuMwx3w, linux-efi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, kernel-br-/JYPxA39Uh5TLH3MbocFFw On Mon, 14 Oct, at 03:37:17PM, Geyslan G. Bem wrote: > 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'. > > Signed-off-by: Geyslan G. Bem <geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- > 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. -- Matt Fleming, Intel Open Source Technology Center ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20131030123850.GA8193-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>]
* Re: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization [not found] ` <20131030123850.GA8193-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> @ 2013-10-30 12:44 ` Geyslan Gregório Bem [not found] ` <CAGG-pUQZ2R0JMZuGi07cL5q4EABYouZJfMpkO6YPy+ry2WkbNw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Geyslan Gregório Bem @ 2013-10-30 12:44 UTC (permalink / raw) To: Matt Fleming Cc: matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA, Jeremy Kerr, matt.fleming-ral2JQCrhuEAvxtiuMwx3w, linux-efi-u79uwXL29TY76Z2rM5mHXA, LKML, kernel-br 2013/10/30 Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>: > On Mon, 14 Oct, at 03:37:17PM, Geyslan G. Bem wrote: >> 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'. >> >> Signed-off-by: Geyslan G. Bem <geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> --- >> 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. > > -- > 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. -- Regards, Geyslan G. Bem hackingbits.com ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <CAGG-pUQZ2R0JMZuGi07cL5q4EABYouZJfMpkO6YPy+ry2WkbNw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization [not found] ` <CAGG-pUQZ2R0JMZuGi07cL5q4EABYouZJfMpkO6YPy+ry2WkbNw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2013-10-30 14:39 ` Matt Fleming [not found] ` <20131030143923.GA9996-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Matt Fleming @ 2013-10-30 14:39 UTC (permalink / raw) To: Geyslan Gregório Bem Cc: matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA, Jeremy Kerr, matt.fleming-ral2JQCrhuEAvxtiuMwx3w, linux-efi-u79uwXL29TY76Z2rM5mHXA, LKML, kernel-br On Wed, 30 Oct, at 10:44:16AM, Geyslan Gregório Bem wrote: > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20131030143923.GA9996-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>]
* Re: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization [not found] ` <20131030143923.GA9996-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org> @ 2013-10-30 19:13 ` Geyslan Gregório Bem 0 siblings, 0 replies; 5+ messages in thread From: Geyslan Gregório Bem @ 2013-10-30 19:13 UTC (permalink / raw) To: Matt Fleming Cc: matthew.garrett-05XSO3Yj/JvQT0dZR+AlfA, Jeremy Kerr, matt.fleming-ral2JQCrhuEAvxtiuMwx3w, linux-efi-u79uwXL29TY76Z2rM5mHXA, LKML, kernel-br 2013/10/30 Matt Fleming <matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>: > On Wed, 30 Oct, at 10:44:16AM, Geyslan Gregório Bem wrote: >> 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 -- Regards, Geyslan G. Bem hackingbits.com ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-10-30 19:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-14 18:37 [PATCH] efivarfs: 'efivarfs_file_write' function reorganization Geyslan G. Bem
[not found] ` <1381775837-26023-1-git-send-email-geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-10-30 12:38 ` Matt Fleming
[not found] ` <20131030123850.GA8193-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-10-30 12:44 ` Geyslan Gregório Bem
[not found] ` <CAGG-pUQZ2R0JMZuGi07cL5q4EABYouZJfMpkO6YPy+ry2WkbNw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-30 14:39 ` Matt Fleming
[not found] ` <20131030143923.GA9996-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org>
2013-10-30 19:13 ` Geyslan Gregório Bem
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).