From: "Geyslan G. Bem" <geyslan@gmail.com>
To: matthew.garrett@nebula.com, jk@ozlabs.org, matt.fleming@intel.com
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-br@googlegroups.com, "Geyslan G. Bem" <geyslan@gmail.com>
Subject: [PATCH] efivarfs: 'efivarfs_file_write' function reorganization
Date: Mon, 14 Oct 2013 15:37:17 -0300 [thread overview]
Message-ID: <1381775837-26023-1-git-send-email-geyslan@gmail.com> (raw)
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
next reply other threads:[~2013-10-14 18:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-14 18:37 Geyslan G. Bem [this message]
[not found] ` <1381775837-26023-1-git-send-email-geyslan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-10-30 12:38 ` [PATCH] efivarfs: 'efivarfs_file_write' function reorganization 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1381775837-26023-1-git-send-email-geyslan@gmail.com \
--to=geyslan@gmail.com \
--cc=jk@ozlabs.org \
--cc=kernel-br@googlegroups.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.fleming@intel.com \
--cc=matthew.garrett@nebula.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).