* [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure
@ 2010-10-15 13:00 Julia Lawall
2010-10-15 13:48 ` Samuel Ortiz
0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2010-10-15 13:00 UTC (permalink / raw)
To: Samuel Ortiz; +Cc: kernel-janitors, netdev, linux-kernel
From: Julia Lawall <julia@diku.dk>
In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.
The initial value of ret as 0 is never used, so drop the initialization.
A simplified version of the semantic match that finds the first problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@
ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
return ret;
}
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/net/irda/irtty-sir.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff -u -p a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -426,7 +426,7 @@ static int irtty_open(struct tty_struct
{
struct sir_dev *dev;
struct sirtty_cb *priv;
- int ret = 0;
+ int ret;
/* Module stuff handled via irda_ldisc.owner - Jean II */
@@ -459,8 +459,10 @@ static int irtty_open(struct tty_struct
/* allocate private device info block */
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (!priv)
+ if (!priv) {
+ ret = -ENOMEM;
goto out_put;
+ }
priv->magic = IRTTY_MAGIC;
priv->tty = tty;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure
2010-10-15 13:00 [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure Julia Lawall
@ 2010-10-15 13:48 ` Samuel Ortiz
0 siblings, 0 replies; 2+ messages in thread
From: Samuel Ortiz @ 2010-10-15 13:48 UTC (permalink / raw)
To: Julia Lawall; +Cc: kernel-janitors, netdev, linux-kernel
Hi Julia,
On Fri, 2010-10-15 at 15:00 +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> In this code, 0 is returned on memory allocation failure, even though other
> failures return -ENOMEM or other similar values.
>
> The initial value of ret as 0 is never used, so drop the initialization.
Thanks, patch applied to my irda-2.6 tree.
Cheers,
Samuel.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-10-15 13:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-15 13:00 [PATCH 1/7] drivers/net/irda/irtty-sir.c: Return -ENOMEM on memory allocation failure Julia Lawall
2010-10-15 13:48 ` Samuel Ortiz
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).