mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: "Elliott, Robert (Server Storage)" <Elliott@hp.com>
Cc: Himangi Saraogi <himangi774@gmail.com>,
	Vikas Chaudhary <vikas.chaudhary@qlogic.com>,
	"iscsi-driver@qlogic.com" <iscsi-driver@qlogic.com>,
	"James E.J. Bottomley" <JBottomley@parallels.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] qla4xxx: Return -ENOMEM on memory allocation failure
Date: Fri, 4 Jul 2014 22:37:26 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1407042235390.1984@localhost6.localdomain6> (raw)
In-Reply-To: <94D0CD8314A33A4D9D801C0FE68B402958B866EB@G9W0745.americas.hpqcorp.net>



On Fri, 4 Jul 2014, Elliott, Robert (Server Storage) wrote:

> 
> 
> > -----Original Message-----
> > From: linux-scsi-owner@vger.kernel.org [mailto:linux-scsi-
> > owner@vger.kernel.org] On Behalf Of Himangi Saraogi
> > Sent: Friday, 04 July, 2014 1:28 PM
> > To: Vikas Chaudhary; iscsi-driver@qlogic.com; James E.J. Bottomley; linux-
> > scsi@vger.kernel.org; linux-kernel@vger.kernel.org
> > Cc: julia.lawall@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 <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;
> >  	}
> > 
> 
> 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);

Maybe that is intentional?  If get_host_stats fails, eg because of a lack 
of memory, the worst that will happen is that a region of the buffer will 
be 0.  If the loop is done again, there seems to be a risk of an infinite 
loop.

julia

  reply	other threads:[~2014-07-04 20:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-04 18:27 Himangi Saraogi
2014-07-04 20:03 ` Elliott, Robert (Server Storage)
2014-07-04 20:37   ` Julia Lawall [this message]
2014-07-04 20:38     ` Julia Lawall
2014-07-07 16:31     ` Mike Christie
2014-07-07 17:46       ` Vikas Chaudhary

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1407042235390.1984@localhost6.localdomain6 \
    --to=julia.lawall@lip6.fr \
    --cc=Elliott@hp.com \
    --cc=JBottomley@parallels.com \
    --cc=himangi774@gmail.com \
    --cc=iscsi-driver@qlogic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vikas.chaudhary@qlogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®