From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758685AbcH3RKm (ORCPT ); Tue, 30 Aug 2016 13:10:42 -0400 Received: from down.free-electrons.com ([37.187.137.238]:37055 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758086AbcH3RKk (ORCPT ); Tue, 30 Aug 2016 13:10:40 -0400 Date: Tue, 30 Aug 2016 19:10:08 +0200 From: Boris Brezillon To: Marcel Holtmann Cc: "Gustavo F. Padovan" , Johan Hedberg , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, jason.abele@gmail.com Subject: Re: [PATCH 4/4] Bluetooth: hci_ldisc: make sure we don't loose HCI_UART_TX_WAKEUP events Message-ID: <20160830191008.7d9d3612@bbrezillon> In-Reply-To: <23C61632-54CF-43DD-8F99-B18176DF6C07@holtmann.org> References: <1471592327-14133-1-git-send-email-boris.brezillon@free-electrons.com> <1471592327-14133-5-git-send-email-boris.brezillon@free-electrons.com> <23C61632-54CF-43DD-8F99-B18176DF6C07@holtmann.org> Organization: Free Electrons X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 30 Aug 2016 09:53:53 -0700 Marcel Holtmann wrote: > Hi Boris, > > > The HCI_UART_TX_WAKEUP flag checking is racy and some HCI_UART_TX_WAKEUP > > events can be lost. > > > > Signed-off-by: Boris Brezillon > > --- > > drivers/bluetooth/hci_ldisc.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c > > index 27f73294edcb..ee7b25f1c6ce 100644 > > --- a/drivers/bluetooth/hci_ldisc.c > > +++ b/drivers/bluetooth/hci_ldisc.c > > @@ -172,6 +172,17 @@ restart: > > goto restart; > > > > clear_bit(HCI_UART_SENDING, &hu->tx_state); > > + > > + /* > > + * One last check to make sure hci_uart_tx_wakeup() did not set > > + * HCI_UART_TX_WAKEUP while we where clearing HCI_UART_SENDING. > > + * The work might have been scheduled by someone else in the > > + * meantime, in this case we return directly. > > + */ > > + if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state) && > > + !test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) > > + goto restart; > > + > > I know this is correct, but I would actually make it visually different. > > if (test_bit(UART_TX_WAKEUP, ..) { > /* comment goes here > */ > if (!test_and_set_bit(UART_SENDING, ..) > goto restart; > } > > For me with a proper comment that is a lot easier to read and grok that it is correct. Sure, I'll address that.