From: Marcel Holtmann <marcel@holtmann.org>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCHv2] Bluetooth: Fix registering hci with duplicate name
Date: Wed, 11 Apr 2012 12:48:37 +0200 [thread overview]
Message-ID: <1334141317.16897.111.camel@aeonflux> (raw)
In-Reply-To: <20120411103103.GF17779@aemeltch-MOBL1>
Hi Andrei,
> > > > > @@ -1755,16 +1756,17 @@ int hci_register_dev(struct hci_dev *hdev)
> > > > >
> > > > > write_lock(&hci_dev_list_lock);
> > > > >
> > > > > - /* Find first available device id */
> > > > > - list_for_each(p, &hci_dev_list) {
> > > > > - if (list_entry(p, struct hci_dev, list)->id != id)
> > > > > - break;
> > > > > - head = p; id++;
> > > > > - }
> > > > I am now a little bit confused. Is it not enough to just replace head
> > > > with &hci_dev_list to get this fixed? Or why is this failing in the
> > > > first place actually.
> > >
> > > You can see actual code above. If you have hci0 and hci1 adding third AMP
> > > will fail since it just checks 0!=1 => break and trying to create hci1
> > > again.
> >
> > I see a problem when you having only AMPs (no BR/EDR controller). Then
> > hci0 will be skipped and keep trying to create hci1 over and over again.
> >
> > However in the case we have BR/EDR controller on hci0 and hci1 as AMP,
> > then this should just work.
> >
> > So we need to fix the case where we have no BR/EDR controller on hci0
> > and trying to fix something else. Or did I get confused?
>
> I think you got confused.
>
> We have hci0 (BREDR) and hci1 (AMP)
>
> so list_for_each would give us first entry with id=0; Adding third (AMP)
> would compare 1 (as given by id = (hdev->dev_type == HCI_BREDR) ? 0 : 1)
> and 0 (id for BREDR) => break from the loop and tries to use id=1 again
> for third controller.
>
> Actually I do not know how the current code works at all, it is really
> broken.
so it is broken on two levels actually. The case where we have no
BR/EDRI controller as hci0 is also broken.
Can you try to come up with a different solution that is not using a bit
mask. That one might overflow actually. Something like this:
min_id = (hdev->dev_type == HCI_BREDR) ? 0 : 1)
for each (...) {
if (id >= min_id && hdev->id != id)
break;
...
}
Regards
Marcel
next prev parent reply other threads:[~2012-04-11 10:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-11 8:23 [PATCH] Bluetooth: Fix registering hci with duplicate name Andrei Emeltchenko
2012-04-11 9:18 ` Marcel Holtmann
2012-04-11 9:51 ` Andrei Emeltchenko
2012-04-11 9:47 ` [PATCHv2] " Andrei Emeltchenko
2012-04-11 9:52 ` Marcel Holtmann
2012-04-11 10:05 ` Andrei Emeltchenko
2012-04-11 10:20 ` Marcel Holtmann
2012-04-11 10:31 ` Andrei Emeltchenko
2012-04-11 10:48 ` Marcel Holtmann [this message]
2012-04-11 11:07 ` Andrei Emeltchenko
2012-04-11 15:33 ` Marcel Holtmann
2012-04-11 12:01 ` [PATCHv3] " Andrei Emeltchenko
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=1334141317.16897.111.camel@aeonflux \
--to=marcel@holtmann.org \
--cc=Andrei.Emeltchenko.news@gmail.com \
--cc=linux-bluetooth@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).