From: Jan Kiszka <jan.kiszka@domain.hid>
To: Anders Blomdell <anders.blomdell@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] [PATCH] Fix to RTDM open problems
Date: Fri, 27 Jan 2006 13:03:56 +0100 [thread overview]
Message-ID: <43DA0C2C.5040208@domain.hid> (raw)
In-Reply-To: <43D9F603.8000505@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 2706 bytes --]
Anders Blomdell wrote:
> When RTDM is exposed to code like this:
>
> device1 = rt_dev_open("some_device", O_RDWR);
> device2 = rt_dev_open("some_device", O_RDWR);
>
> I get a SEGFAULT, which I attribute to a missing assignment to
> context_ptr in the case when the device is already busy, the lack of
> this assignment leads to a segfault in cleanup_instance.
>
>
> --- xenomai-2.1-rc2/ksrc/skins/rtdm/core.c~ 2006-01-07
> 18:08:34.000000000 +0100
> +++ xenomai-2.1-rc2/ksrc/skins/rtdm/core.c 2006-01-27
> 11:14:43.000000000 +0100
> @@ -136,6 +136,8 @@
>
> if (context->device) {
> xnlock_put_irqrestore(&rt_dev_lock, s);
> +
> + *context_ptr = NULL;
> return -EBUSY;
> }
> context->device = device;
>
Yep, correct. Don't know, I must have smoked something while trying to
fix this bug some weeks ago. Thanks for reporting and also providing a
patch.
I just gave it another try, also re-organising the involved function
create_instance() slightly. Please checkout latest SVN or try the
following patch and let me know if this works now, really.
Thanks again,
Jan
Index: core.c
===================================================================
--- core.c (revision 475)
+++ core.c (working copy)
@@ -116,13 +116,13 @@
spl_t s;
+ *context_ptr = NULL;
+
xnlock_get_irqsave(&rt_fildes_lock, s);
*fildes_ptr = fildes = free_fildes;
- if (!fildes) {
+ if (unlikely(!fildes)) {
xnlock_put_irqrestore(&rt_fildes_lock, s);
-
- *context_ptr = NULL;
return -ENFILE;
}
free_fildes = fildes->next;
@@ -134,15 +134,13 @@
if (context) {
xnlock_get_irqsave(&rt_dev_lock, s);
- if (context->device) {
+ if (unlikely(context->device)) {
xnlock_put_irqrestore(&rt_dev_lock, s);
return -EBUSY;
}
context->device = device;
xnlock_put_irqrestore(&rt_dev_lock, s);
-
- *context_ptr = context;
} else {
if (nrt_mem)
context = kmalloc(sizeof(struct rtdm_dev_context) +
@@ -150,13 +148,14 @@
else
context = xnmalloc(sizeof(struct rtdm_dev_context) +
device->context_size);
- *context_ptr = context;
- if (!context)
+ if (unlikely(!context))
return -ENOMEM;
context->device = device;
}
+ *context_ptr = context;
+
context->fd = get_fd(fildes);
context->ops = &device->ops;
atomic_set(&context->close_lock_count, 0);
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
next prev parent reply other threads:[~2006-01-27 12:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-27 10:29 [Xenomai-core] [PATCH] Fix to RTDM open problems Anders Blomdell
2006-01-27 12:03 ` Jan Kiszka [this message]
2006-01-27 12:48 ` Luotao Fu
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=43DA0C2C.5040208@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=anders.blomdell@domain.hid \
--cc=xenomai@xenomai.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.