[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130719212432.GC29404@logfs.org>
Date: Fri, 19 Jul 2013 17:24:32 -0400
From: Jörn Engel <joern@...fs.org>
To: Vaughan Cao <vaughan.cao@...cle.com>
Cc: dgilbert@...erlog.com, JBottomley@...allels.com,
linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 3/4] [SCSI] sg: checking sdp->detached isn't
protected when open
On Wed, 17 July 2013 23:34:05 +0800, Vaughan Cao wrote:
>
> -static Sg_fd *sg_add_sfp(Sg_device * sdp, int dev);
> +static Sg_fd *sg_add_sfp(Sg_device * sdp, int dev, int * reason);
You can use ERR_PTR and friends instead of adding another parameter.
> static void sg_remove_sfp(struct kref *);
> static Sg_request *sg_get_rq_mark(Sg_fd * sfp, int pack_id);
> static Sg_request *sg_add_request(Sg_fd * sfp);
> @@ -295,21 +295,14 @@ sg_open(struct inode *inode, struct file *filp)
> if (flags & O_EXCL)
> sdp->exclude = 1; /* used by release lock */
>
> - if (sdp->detached) {
> - retval = -ENODEV;
> - goto sem_out;
> - }
> if (sfds_list_empty(sdp)) { /* no existing opens on this device */
> sdp->sgdebug = 0;
> q = sdp->device->request_queue;
> sdp->sg_tablesize = queue_max_segments(q);
> }
> - if ((sfp = sg_add_sfp(sdp, dev)))
> - filp->private_data = sfp;
> - else {
> - retval = -ENOMEM;
> + if (!(sfp = sg_add_sfp(sdp, dev, &retval)))
> goto sem_out;
> - }
sfp = sg_add_sfp(sdp, dev);
if (IS_ERR(sfp)) {
retval = PTR_ERR(sfp);
goto sem_out;
}
> + filp->private_data = sfp;
> retval = 0;
>
> if (retval) {
> @@ -2047,15 +2040,18 @@ sg_remove_request(Sg_fd * sfp, Sg_request * srp)
> }
>
> static Sg_fd *
> -sg_add_sfp(Sg_device * sdp, int dev)
> +sg_add_sfp(Sg_device * sdp, int dev, int * reason)
> {
> Sg_fd *sfp;
> unsigned long iflags;
> int bufflen;
>
> sfp = kzalloc(sizeof(*sfp), GFP_ATOMIC | __GFP_NOWARN);
> - if (!sfp)
> + if (!sfp) {
> + if (reason)
> + *reason = -ENOMEM;
> return NULL;
> + }
if (!sfp)
return ERR_PTR(-ENOMEM);
Jörn
--
Luck is when opportunity meets good preparation.
-- Chinese proverb
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists