From: Julia Lawall Date: Wed, 10 Mar 2010 23:20:42 +0000 (-0800) Subject: drivers/scsi/ses.c: eliminate double free X-Git-Tag: v2.6.34-rc2~269 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b3a6549b2602ca30f58715a0071e29f9898cae9;p=platform%2Fkernel%2Flinux-stable.git drivers/scsi/ses.c: eliminate double free The few lines below the kfree of hdr_buf may go to the label err_free which will also free hdr_buf. The most straightforward solution seems to be to just move the kfree of hdr_buf after these gotos. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @r@ identifier E; expression E1; iterator I; statement S; @@ *kfree(E); ... when != E = E1 when != I(E,...) S when != &E *kfree(E); // Signed-off-by: Julia Lawall Cc: James Bottomley Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c index 1d7a878..0d9d6f7 100644 --- a/drivers/scsi/ses.c +++ b/drivers/scsi/ses.c @@ -595,8 +595,6 @@ static int ses_intf_add(struct device *cdev, ses_dev->page10_len = len; buf = NULL; } - kfree(hdr_buf); - scomp = kzalloc(sizeof(struct ses_component) * components, GFP_KERNEL); if (!scomp) goto err_free; @@ -608,6 +606,8 @@ static int ses_intf_add(struct device *cdev, goto err_free; } + kfree(hdr_buf); + edev->scratch = ses_dev; for (i = 0; i < components; i++) edev->component[i].scratch = scomp + i;