Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1482137
| From | Manfred Spraul <manfred@colorfullife.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/5] ipc/sem: do not call wake_sem_queue_do() prematurely |
| Date | 2016-09-13 06:20 +0200 |
| Message-ID | <sgNmq-4WR-3@gated-at.bofh.it> (permalink) |
| References | <sgy41-2Jz-5@gated-at.bofh.it> <sgy41-2Jz-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Hi Davidlohr,
On 09/12/2016 01:53 PM, Davidlohr Bueso wrote:
> ... as this call should obviously be paired with its _prepare()
> counterpart. At least whenever possible, as there is no harm in
> calling it bogusly as we do now in a few places.
I would define the interface differently:
WAKE_Q creates an initialized wake queue. There is no need to track if
any tasks were added to the wake queue, it is safe to call wake_up_q().
So especially for error paths, there is no need to optimize out calls to
wake_up_q()
> Immediate error
> semop(2) paths that are far from ever having the task block can
> be simplified and avoid a few unnecessary loads on their way out
> of the call as it is not deeply nested.
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
> ---
> ipc/sem.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/ipc/sem.c b/ipc/sem.c
> index 5e318c5f749d..a4e8bb2fae38 100644
> --- a/ipc/sem.c
> +++ b/ipc/sem.c
> @@ -1887,16 +1887,22 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
> }
>
> error = -EFBIG;
> - if (max >= sma->sem_nsems)
> - goto out_rcu_wakeup;
> + if (max >= sma->sem_nsems) {
> + rcu_read_unlock();
> + goto out_free;
> + }
>
> error = -EACCES;
> - if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO))
> - goto out_rcu_wakeup;
> + if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO)) {
> + rcu_read_unlock();
> + goto out_free;
> + }
>
Is this really better/simpler?
You replace "if (error) goto cleanup" with "if (error) {cleanup_1();
goto cleanup_2()}".
From my point of view, this just increases the risks that some cleanup
steps are forgotten.
--
Manfred
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/5] ipc/sem: do not call wake_sem_queue_do() prematurely Davidlohr Bueso <dave@stgolabs.net> - 2016-09-12 14:00 +0200
Re: [PATCH 1/5] ipc/sem: do not call wake_sem_queue_do() prematurely Manfred Spraul <manfred@colorfullife.com> - 2016-09-13 06:20 +0200
Re: [PATCH 1/5] ipc/sem: do not call wake_sem_queue_do() prematurely Davidlohr Bueso <dave@stgolabs.net> - 2016-09-13 10:20 +0200
csiph-web