[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.00.1108221632130.9774@swampdragon.chaosbits.net>
Date: Mon, 22 Aug 2011 16:34:43 +0200 (CEST)
From: Jesper Juhl <jj@...osbits.net>
To: Julia Lawall <julia@...u.dk>
cc: Robert Love <robert.w.love@...el.com>,
kernel-janitors@...r.kernel.org,
"James E.J. Bottomley" <JBottomley@...allels.com>,
devel@...n-fcoe.org, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/4] drivers/scsi/fcoe/fcoe.c: add missing test
On Mon, 22 Aug 2011, Julia Lawall wrote:
> From: Julia Lawall <julia@...u.dk>
>
> The initializations of both fcoe_nport_scsi_transport and
> fcoe_vport_scsi_transport can fail, so test both of them.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @r@
> identifier x,y,f!={PTR_ERR,ERR_PTR,ERR_CAST};
> statement S;
> @@
>
> x = f(...);
> (
> if (\(x == NULL\|IS_ERR(x)\)) S
> |
> *if (\(y == NULL\|IS_ERR(y)\))
> { ... when != x
> return ...; }
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@...u.dk>
>
> ---
> drivers/scsi/fcoe/fcoe.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
> index ba710e3..921b636 100644
> --- a/drivers/scsi/fcoe/fcoe.c
> +++ b/drivers/scsi/fcoe/fcoe.c
> @@ -1096,7 +1096,7 @@ static int __init fcoe_if_init(void)
> fcoe_vport_scsi_transport =
> fc_attach_transport(&fcoe_vport_fc_functions);
>
> - if (!fcoe_nport_scsi_transport) {
> + if (!fcoe_nport_scsi_transport || !fcoe_vport_scsi_transport) {
> printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
> return -ENODEV;
> }
>
I only took a quick look, so I may have overlooked something, so bear with
me.
fc_attach_transport() allocates memory with kzalloc. If either call fails
the other may have succeeded and we'll leak the memory allocated to one of
them.
Shouldn't we be kfree()'ing the two variables before the 'return -ENODEV'?
--
Jesper Juhl <jj@...osbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists