public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qla4xxx: Return -ENOMEM on memory allocation failure
@ 2014-07-04 18:27 Himangi Saraogi
  2014-07-04 20:03 ` Elliott, Robert (Server Storage)
  0 siblings, 1 reply; 6+ messages in thread
From: Himangi Saraogi @ 2014-07-04 18:27 UTC (permalink / raw)
  To: Vikas Chaudhary, iscsi-driver, James E.J. Bottomley, linux-scsi,
	linux-kernel
  Cc: julia.lawall

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 <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@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;
 	}
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-07 17:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-04 18:27 [PATCH] qla4xxx: Return -ENOMEM on memory allocation failure Himangi Saraogi
2014-07-04 20:03 ` Elliott, Robert (Server Storage)
2014-07-04 20:37   ` Julia Lawall
2014-07-04 20:38     ` Julia Lawall
2014-07-07 16:31     ` Mike Christie
2014-07-07 17:46       ` Vikas Chaudhary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox