linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Persistent problem with wait_until_sent timeout parameter type mismatch
@ 2009-08-21 20:03 Grant Edwards
  2009-08-28 14:33 ` Grant Edwards
  2009-09-16  5:57 ` Grant Edwards
  0 siblings, 2 replies; 3+ messages in thread
From: Grant Edwards @ 2009-08-21 20:03 UTC (permalink / raw)
  To: linux-serial

I seem to have run into a problem which people have been
pointing out for years, but never gets fixed.

In tty_driver.h, the low-level driver routine wait_until_set()
function takes an "int" as a timeout value:

   192	struct tty_operations {
   193		int  (*open)(struct tty_struct * tty, struct file * filp);
[...]
   214		void (*wait_until_sent)(struct tty_struct *tty, int timeout);
[...]
   228	};

But, in tty_ioclt.c in the tty_wait_unti_sent() function, the
timeout is a "long":

    98	void tty_wait_until_sent(struct tty_struct *tty, long timeout)
    99	{
   100	#ifdef TTY_DEBUG_WAIT_UNTIL_SENT
   101		char buf[64];
   102	
   103		printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf));
   104	#endif
   105		if (!timeout)
   106			timeout = MAX_SCHEDULE_TIMEOUT;
   107		if (wait_event_interruptible_timeout(tty->write_wait,
   108				!tty_chars_in_buffer(tty), timeout) >= 0) {
   109			if (tty->ops->wait_until_sent)
   110				tty->ops->wait_until_sent(tty, timeout);
   111		}
   112	}
   113	EXPORT_SYMBOL(tty_wait_until_sent);

This is fine on 32-bit systems, where "int" and "long" are
equivalent, but it results in breakage on 64-bit systems.  At
line 106, timeout is set to MAX_SCHEDULE_TIMEOUT which is 
7fffffffffffffff.  When that value is passed to the low-level
driver routine at line 110, it gets truncated to ffffffff --
which is -1.  That means that waiting until (jiffies+timeout)
returns immediately when the caller's intent was to wait as
long as possible.

People have been pointing out that type mismatch for many years
now.  What's the justification for the low-level driver routine
parameter being "int" instead of "long"?

Since this doesn't seem to be something that's going to be
fixed, I guess a work-around for those of us who maintain
serial drivers is to treat a timeout of -1 as a special value
that means "forever"?  Is that the intent?

-- 
Grant Edwards                   grante             Yow! I feel like a wet
                                  at               parking meter on Darvon!
                               visi.com            


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

end of thread, other threads:[~2009-09-16  5:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-21 20:03 Persistent problem with wait_until_sent timeout parameter type mismatch Grant Edwards
2009-08-28 14:33 ` Grant Edwards
2009-09-16  5:57 ` Grant Edwards

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