lkml.org 
[lkml]   [2013]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] sg: O_EXCL and other lock handling
> +	struct semaphore or_sem;  /* protect co-incident opens and releases */

Seems like this should be a mutex.

> sfds_list_empty(Sg_device *sdp)
> {
> unsigned long flags;
> int ret;
>
> + spin_lock_irqsave(&sdp->sfd_lock, flags);
> + ret = list_empty(&sdp->sfds);
> + spin_unlock_irqrestore(&sdp->sfd_lock, flags);
> return ret;

Protecting just a list_empty check with a local will give you racy
results. Seems like you should take the look over the check and the
resulting action that modifies the list. That'd also mean replacing the
wait_event* calls with open coded prepare_wait / finish_wait loops.

> + down(&sdp->or_sem);
> + alone = sfds_list_empty(sdp);
> + if ((flags & O_EXCL) && (O_RDONLY == (flags & O_ACCMODE))) {
> + retval = -EPERM; /* Don't allow O_EXCL with read only access */
> + goto error_out;
> + }

Seems like the pure flags check should move to the beginning of the
function before taking any locks.



\
 
 \ /
  Last update: 2013-10-31 17:21    [W:0.074 / U:0.316 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site