* [PATCH 09/14] staging: westbridge: improve error path
@ 2010-09-05 18:32 Kulikov Vasiliy
2010-09-06 7:51 ` walter harms
0 siblings, 1 reply; 5+ messages in thread
From: Kulikov Vasiliy @ 2010-09-05 18:32 UTC (permalink / raw)
To: kernel-janitors
Cc: Vasiliy Kulikov, Greg Kroah-Hartman, David Cross, devel,
linux-kernel
From: Vasiliy Kulikov <segooon@gmail.com>
kmalloc() may fail, check for it.
Allocated memory is not freed.
Use IS_ERR() instead of strict checking.
Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
---
I couldn't compile this driver at all, so it is not tested.
.../staging/westbridge/astoria/gadget/cyasgadget.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c b/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
index ced239d..48080b3 100644
--- a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
+++ b/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
@@ -1123,6 +1123,8 @@ static int cyasgadget_ioctl(
/* better use fixed size buff*/
alloc_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL);
+ if (alloc_filename == NULL)
+ return -ENOMEM;
/* get the filename */
if (copy_from_user(alloc_filename, k_d.file_name,
@@ -1132,12 +1134,13 @@ static int cyasgadget_ioctl(
"copy file name from user space failed\n",
__func__);
#endif
+ kfree(alloc_filename);
return -EFAULT;
}
file_to_allocate = filp_open(alloc_filename, O_RDWR, 0);
- if ((int)file_to_allocate != 0xfffffffe) {
+ if (!IS_ERR(file_to_allocate)) {
struct address_space *mapping =
file_to_allocate->f_mapping;
@@ -1379,6 +1382,7 @@ static int cyasgadget_ioctl(
__func__, alloc_filename);
} /* end if (file_to_allocate)*/
#endif
+ kfree(alloc_filename);
initsoj_safe_exit:
ret_stat = 0;
retval = __put_user(ret_stat,
@@ -1410,12 +1414,15 @@ initsoj_safe_exit:
return -EFAULT;
map_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL);
+ if (map_filename == NULL)
+ return -ENOMEM;
if (copy_from_user(map_filename, k_d.file_name,
k_d.name_length + 1)) {
#ifndef WESTBRIDGE_NDEBUG
cy_as_hal_print_message("%s: copy file name from "
"user space failed\n", __func__);
#endif
+ kfree(map_filename);
return -EFAULT;
}
@@ -1561,6 +1568,7 @@ initsoj_safe_exit:
__func__, map_filename);
}
#endif
+ kfree(map_filename);
ret_stat = 0;
retval = __put_user(ret_stat, (uint32_t __user *)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 09/14] staging: westbridge: improve error path
2010-09-05 18:32 [PATCH 09/14] staging: westbridge: improve error path Kulikov Vasiliy
@ 2010-09-06 7:51 ` walter harms
2010-09-06 20:33 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: walter harms @ 2010-09-06 7:51 UTC (permalink / raw)
To: Kulikov Vasiliy
Cc: kernel-janitors, Greg Kroah-Hartman, David Cross, devel,
linux-kernel
Kulikov Vasiliy schrieb:
> From: Vasiliy Kulikov <segooon@gmail.com>
>
> kmalloc() may fail, check for it.
> Allocated memory is not freed.
> Use IS_ERR() instead of strict checking.
>
> Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
> ---
> I couldn't compile this driver at all, so it is not tested.
>
> .../staging/westbridge/astoria/gadget/cyasgadget.c | 10 +++++++++-
> 1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c b/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
> index ced239d..48080b3 100644
> --- a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
> +++ b/drivers/staging/westbridge/astoria/gadget/cyasgadget.c
> @@ -1123,6 +1123,8 @@ static int cyasgadget_ioctl(
>
> /* better use fixed size buff*/
> alloc_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL);
> + if (alloc_filename == NULL)
> + return -ENOMEM;
>
> /* get the filename */
> if (copy_from_user(alloc_filename, k_d.file_name,
> @@ -1132,12 +1134,13 @@ static int cyasgadget_ioctl(
> "copy file name from user space failed\n",
> __func__);
> #endif
> + kfree(alloc_filename);
> return -EFAULT;
> }
>
> file_to_allocate = filp_open(alloc_filename, O_RDWR, 0);
>
> - if ((int)file_to_allocate != 0xfffffffe) {
> + if (!IS_ERR(file_to_allocate)) {
>
> struct address_space *mapping =
> file_to_allocate->f_mapping;
> @@ -1379,6 +1382,7 @@ static int cyasgadget_ioctl(
> __func__, alloc_filename);
> } /* end if (file_to_allocate)*/
> #endif
> + kfree(alloc_filename);
> initsoj_safe_exit:
> ret_stat = 0;
> retval = __put_user(ret_stat,
> @@ -1410,12 +1414,15 @@ initsoj_safe_exit:
> return -EFAULT;
>
> map_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL);
> + if (map_filename == NULL)
> + return -ENOMEM;
> if (copy_from_user(map_filename, k_d.file_name,
> k_d.name_length + 1)) {
> #ifndef WESTBRIDGE_NDEBUG
> cy_as_hal_print_message("%s: copy file name from "
> "user space failed\n", __func__);
> #endif
> + kfree(map_filename);
> return -EFAULT;
> }
the indention should be fixed also.
re,
wh
> @@ -1561,6 +1568,7 @@ initsoj_safe_exit:
> __func__, map_filename);
> }
> #endif
> + kfree(map_filename);
>
> ret_stat = 0;
> retval = __put_user(ret_stat, (uint32_t __user *)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 09/14] staging: westbridge: improve error path
2010-09-06 7:51 ` walter harms
@ 2010-09-06 20:33 ` Greg KH
2010-09-07 7:16 ` walter harms
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2010-09-06 20:33 UTC (permalink / raw)
To: walter harms
Cc: Kulikov Vasiliy, kernel-janitors, David Cross, devel,
linux-kernel
On Mon, Sep 06, 2010 at 09:51:20AM +0200, walter harms wrote:
> the indention should be fixed also.
Yes, the indentation for the whole file should be fixed, but that's not
what this patch was doing.
Remember, a patch should only do one thing at a time.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 09/14] staging: westbridge: improve error path
2010-09-06 20:33 ` Greg KH
@ 2010-09-07 7:16 ` walter harms
2010-09-08 0:23 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: walter harms @ 2010-09-07 7:16 UTC (permalink / raw)
To: Greg KH; +Cc: Kulikov Vasiliy, kernel-janitors, David Cross, devel,
linux-kernel
Greg KH schrieb:
> On Mon, Sep 06, 2010 at 09:51:20AM +0200, walter harms wrote:
>> the indention should be fixed also.
>
> Yes, the indentation for the whole file should be fixed, but that's not
> what this patch was doing.
>
> Remember, a patch should only do one thing at a time.
>
that is true,
but in this special case i nearly missed the #if because it is so hidden
in the code. IMHO that is enough for an exception.
re,
wh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 09/14] staging: westbridge: improve error path
2010-09-07 7:16 ` walter harms
@ 2010-09-08 0:23 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2010-09-08 0:23 UTC (permalink / raw)
To: walter harms
Cc: Kulikov Vasiliy, kernel-janitors, David Cross, devel,
linux-kernel
On Tue, Sep 07, 2010 at 09:16:46AM +0200, walter harms wrote:
>
>
> Greg KH schrieb:
> > On Mon, Sep 06, 2010 at 09:51:20AM +0200, walter harms wrote:
> >> the indention should be fixed also.
> >
> > Yes, the indentation for the whole file should be fixed, but that's not
> > what this patch was doing.
> >
> > Remember, a patch should only do one thing at a time.
> >
>
> that is true,
> but in this special case i nearly missed the #if because it is so hidden
> in the code. IMHO that is enough for an exception.
This whole driver needs major help. But again, one thing at a time
please.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-09-08 0:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-05 18:32 [PATCH 09/14] staging: westbridge: improve error path Kulikov Vasiliy
2010-09-06 7:51 ` walter harms
2010-09-06 20:33 ` Greg KH
2010-09-07 7:16 ` walter harms
2010-09-08 0:23 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox