Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] bfa: don't leak mem in bfad_im_bsg_els_ct_request()

If 'drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);' fails
and returns NULL, then we'll leak the memory allocated to 'bsg_fcpt'
when we jump to 'out:' and the variable subsequently goes out of
scope.

Also remove the cast of the kzalloc() return value. kzalloc() returns
a void* which is implicitly converted, so the explicit cast is
pointless.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Krishna Gudipati <kgudipat@brocade.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

authored by

Jesper Juhl and committed by
James Bottomley
64b8aa75 e5cc6aa4

+2 -2
+2 -2
drivers/scsi/bfa/bfad_bsg.c
··· 3047 3047 * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload 3048 3048 * buffer of size bsg_data->payload_len 3049 3049 */ 3050 - bsg_fcpt = (struct bfa_bsg_fcpt_s *) 3051 - kzalloc(bsg_data->payload_len, GFP_KERNEL); 3050 + bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL); 3052 3051 if (!bsg_fcpt) 3053 3052 goto out; 3054 3053 ··· 3059 3060 3060 3061 drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL); 3061 3062 if (drv_fcxp == NULL) { 3063 + kfree(bsg_fcpt); 3062 3064 rc = -ENOMEM; 3063 3065 goto out; 3064 3066 }