linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* hci_ldisc: suspicious/buggy code
@ 2016-10-17 21:32 Pavel Machek
  2016-10-17 21:52 ` Pavel Machek
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Machek @ 2016-10-17 21:32 UTC (permalink / raw)
  To: ifaenson, marcel, kernel list, gustavo, johan.hedberg,
	linux-bluetooth, sre

[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]

Hi!

hci_uart_set_flow_control() contains some rather suspicious
code. AFAICT:

set = 0.

Then we do set &= (magic constant). But as set is 0, it stays zero. It
just does not make sense. [Nor does it make sense to do |= on known
value of zero just after else. But that's probably just some artifact
of editing.]

(And if you edit the code anyway, temporary variable to store
TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | TIOCM_OUT2 | TIOCM_LOOP would
make sense.)

Thanks,
								Pavel


/* Flow control or un-flow control the device */
void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
{
	...
	unsigned int set = 0;
	unsigned int clear = 0;

	if (enable) {
	   	...
		set &= ~(TIOCM_OUT2 | TIOCM_RTS);
		clear = ~set;
		set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
		       TIOCM_OUT2 | TIOCM_LOOP;
		clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
			 TIOCM_OUT2 | TIOCM_LOOP;
		status = tty->driver->ops->tiocmset(tty, set, clear);
		BT_DBG("Clearing RTS: %s", status ? "failed" : "success");
	} else {
	       ...	
		set |= (TIOCM_OUT2 | TIOCM_RTS);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: hci_ldisc: suspicious/buggy code
  2016-10-17 21:32 hci_ldisc: suspicious/buggy code Pavel Machek
@ 2016-10-17 21:52 ` Pavel Machek
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2016-10-17 21:52 UTC (permalink / raw)
  To: ifaenson, marcel, kernel list, gustavo, johan.hedberg,
	linux-bluetooth, sre

[-- Attachment #1: Type: text/plain, Size: 2058 bytes --]

On Mon 2016-10-17 23:32:06, Pavel Machek wrote:
> Hi!
> 
> hci_uart_set_flow_control() contains some rather suspicious
> code. AFAICT:
> 
> set = 0.
> 
> Then we do set &= (magic constant). But as set is 0, it stays zero. It
> just does not make sense. [Nor does it make sense to do |= on known
> value of zero just after else. But that's probably just some artifact
> of editing.]
> 
> (And if you edit the code anyway, temporary variable to store
> TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | TIOCM_OUT2 | TIOCM_LOOP would
> make sense.)

I think this might be the fix, but it breaks h4p protocol on n900...

  	     	      	       	      	     	 	  Pavel

diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 0506806..b549c47 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -271,8 +271,8 @@ void hci_uart_set_rts(struct hci_uart *hu, bool enable)
 		status = tty->driver->ops->tiocmget(tty);
 		BT_DBG("Current tiocm 0x%x", status);
 
-		set &= ~(TIOCM_OUT2 | TIOCM_RTS);
-		clear = ~set;
+		clear |= (TIOCM_OUT2 | TIOCM_RTS);
+		set = ~clear;
 		set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
 		       TIOCM_OUT2 | TIOCM_LOOP;
 		clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |

> /* Flow control or un-flow control the device */
> void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
> {
> 	...
> 	unsigned int set = 0;
> 	unsigned int clear = 0;
> 
> 	if (enable) {
> 	   	...
> 		set &= ~(TIOCM_OUT2 | TIOCM_RTS);
> 		clear = ~set;
> 		set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> 		       TIOCM_OUT2 | TIOCM_LOOP;
> 		clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> 			 TIOCM_OUT2 | TIOCM_LOOP;
> 		status = tty->driver->ops->tiocmset(tty, set, clear);
> 		BT_DBG("Clearing RTS: %s", status ? "failed" : "success");
> 	} else {
> 	       ...	
> 		set |= (TIOCM_OUT2 | TIOCM_RTS);
> 



-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-17 21:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-17 21:32 hci_ldisc: suspicious/buggy code Pavel Machek
2016-10-17 21:52 ` Pavel Machek

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).