Re: [PATCH v4 3/4] [SCSI] sg: checking sdp->detached isn'tprotected when open

From: JÃrn Engel
Date: Fri Jul 19 2013 - 18:56:17 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/