linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5/9] drivers/s390/block/dasd_ioctl.c: add missing kfree
@ 2011-08-08 11:17 Julia Lawall
  2011-08-08 14:32 ` Heiko Carstens
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2011-08-08 11:17 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: kernel-janitors, Heiko Carstens, linux390, Stefan Weinhuber,
	Arnd Bergmann, linux-s390, linux-kernel

From: Julia Lawall <julia@diku.dk>

Data is only used to temporarily hold information to be copied to the user
level, so it should be freed before leaving the function.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@exists@
local idexpression x;
statement S,S1;
expression E;
identifier fl;
expression *ptr != NULL;
@@

x = \(kmalloc\|kzalloc\|kcalloc\)(...);
...
if (x == NULL) S
<... when != x
     when != if (...) { <+...kfree(x)...+> }
     when any
     when != true x == NULL
x->fl
...>
(
if (x == NULL) S1
|
if (...) { ... when != x
               when forall
(
 return \(0\|<+...x...+>\|ptr\);
|
* return ...;
)
}
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/s390/block/dasd_ioctl.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index eb4e034..753636f 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -249,6 +249,7 @@ static int dasd_ioctl_reset_profile(struct dasd_block *block)
 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
 {
 	struct dasd_profile_info_t *data;
+	int ret = 0;
 
 	data = kmalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -279,11 +280,14 @@ static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
 		spin_unlock_bh(&block->profile.lock);
 	} else {
 		spin_unlock_bh(&block->profile.lock);
-		return -EIO;
+		ret = -EIO;
+		goto out;
 	}
 	if (copy_to_user(argp, data, sizeof(*data)))
-		return -EFAULT;
-	return 0;
+		ret = -EFAULT;
+out:
+	kfree(data);
+	return ret;
 }
 #else
 static int dasd_ioctl_reset_profile(struct dasd_block *block)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5/9] drivers/s390/block/dasd_ioctl.c: add missing kfree
  2011-08-08 11:17 [PATCH 5/9] drivers/s390/block/dasd_ioctl.c: add missing kfree Julia Lawall
@ 2011-08-08 14:32 ` Heiko Carstens
  0 siblings, 0 replies; 2+ messages in thread
From: Heiko Carstens @ 2011-08-08 14:32 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Martin Schwidefsky, kernel-janitors, linux390, Stefan Weinhuber,
	Arnd Bergmann, linux-s390, linux-kernel

On Mon, Aug 08, 2011 at 01:17:59PM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Data is only used to temporarily hold information to be copied to the user
> level, so it should be freed before leaving the function.
> 
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)

[...]

> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
>  drivers/s390/block/dasd_ioctl.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)

Applied. Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-08 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-08 11:17 [PATCH 5/9] drivers/s390/block/dasd_ioctl.c: add missing kfree Julia Lawall
2011-08-08 14:32 ` Heiko Carstens

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).