fs/fhandle.c: 'handle_to_path' function reorganization
Subsystems (2)
PATCH 1/1 fs/fhandle.c: 'handle_to_path' function reorganization
This reorganization:
Removes the exiting labels and adds direct return, once that there is only one cleanup necessity.
Removes 'retval' and 'file_handle' prior assignments due this new approach.
Adds 'size' and 'byte' variables to make the code cleaner and more understandable.
Uses 'memdup_user' instead 'kmalloc' + 'copy_from_user'.
Signed-off-by Geyslan G. Bem <[email protected]>
--- fs/fhandle.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-)
fs/fhandle.c +18 -30
@@ -166,47 +166,35 @@ out_err:static int handle_to_path (int mountdirfd,struct file_handle __user *ufh,struct path *path) { -int retval =0 ; +int retval;struct file_handle f_handle; -struct file_handle *handle =NULL ; +struct file_handle *handle; +unsigned int size, bytes;/* * With handle we don't look at the execute bit on the * the directory. Ideally we would like CAP_DAC_SEARCH. * But we don't have that */ -if (!capable (CAP_DAC_READ_SEARCH )) { - retval = -EPERM ; - goto out_err; - } -if (copy_from_user (&f_handle, ufh,sizeof (struct file_handle ))) { - retval = -EFAULT ; - goto out_err; - } -if ((f_handle.handle_bytes >MAX_HANDLE_SZ ) || - (f_handle.handle_bytes ==0 )) { - retval = -EINVAL ; - goto out_err; - } - handle =kmalloc (sizeof (struct file_handle ) + f_handle.handle_bytes, -GFP_KERNEL ); -if (!handle) { - retval = -ENOMEM ; - goto out_err; - } -/* copy the full handle */ -if (copy_from_user (handle, ufh, -sizeof (struct file_handle ) + - f_handle.handle_bytes)) { - retval = -EFAULT ; - goto out_handle; - } +if (!capable (CAP_DAC_READ_SEARCH )) +return -EPERM ; + + size =sizeof (struct file_handle ); +if (copy_from_user (&f_handle, ufh, size)) +return -EFAULT ; + + bytes = f_handle.handle_bytes; +if ((bytes >MAX_HANDLE_SZ ) || (bytes ==0 )) +return -EINVAL ; + + size += bytes; + handle =memdup_user (ufh, size); +if (IS_ERR (handle)) +return PTR_ERR (handle); retval =do_handle_to_path (mountdirfd, handle, path); -out_handle:kfree (handle); -out_err:return retval; }
Signature · 1 line
1.8.4