> -----Original Message----- > From: linux-scsi-ow...@vger.kernel.org [mailto:linux-scsi- > ow...@vger.kernel.org] On Behalf Of Himangi Saraogi > Sent: Friday, 04 July, 2014 1:28 PM > To: Vikas Chaudhary; iscsi-dri...@qlogic.com; James E.J. Bottomley; linux- > s...@vger.kernel.org; linux-ker...@vger.kernel.org > Cc: julia.law...@lip6.fr > Subject: [PATCH] qla4xxx: Return -ENOMEM on memory allocation failure > > In this code, 0 is returned on memory allocation failure, even though > other failures return -ENOMEM or other similar values. > > A simplified version of the Coccinelle semantic match that finds this > problem is as follows: > > // <smpl> > @@ > expression ret; > expression x,e1,e2,e3; > identifier alloc; > @@ > > ret = 0 > ... when != ret = e1 > *x = alloc(...) > ... when != ret = e2 > if (x == NULL) { ... when != ret = e3 > return ret; > } > // </smpl> > > Signed-off-by: Himangi Saraogi <himangi...@gmail.com> > Acked-by: Julia Lawall <julia.law...@lip6.fr> > --- > drivers/scsi/qla4xxx/ql4_os.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c > index c5d9564..72ba671 100644 > --- a/drivers/scsi/qla4xxx/ql4_os.c > +++ b/drivers/scsi/qla4xxx/ql4_os.c > @@ -1050,6 +1050,7 @@ static int qla4xxx_get_host_stats(struct Scsi_Host > *shost, char *buf, int len) > if (!ql_iscsi_stats) { > ql4_printk(KERN_ERR, ha, > "Unable to allocate memory for iscsi stats\n"); > + ret = -ENOMEM; > goto exit_host_stats; > } >
Also, the only caller of this function doesn't use the return value - it's overwritten by another function call: drivers/scsi/scsi_transport_iscsi.c: err = transport->get_host_stats(shost, buf, host_stats_size); actual_size = nlmsg_total_size(sizeof(*ev) + host_stats_size); skb_trim(skbhost_stats, NLMSG_ALIGN(actual_size)); nlhhost_stats->nlmsg_len = actual_size; err = iscsi_multicast_skb(skbhost_stats, ISCSI_NL_GRP_ISCSID, GFP_KERNEL); --- Rob Elliott HP Server Storage -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html