mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: columbus@hit.handshake.de (Christoph Bartelmus)
To: linux-kernel@vger.kernel.org
Subject: PROBLEM: serial port driver grabs occupied port
Date: 02 Feb 2002 23:21:00 GMT	[thread overview]
Message-ID: <8IBS9f7Xz9B@hit-columbus.hit.handshake.de> (raw)

Hi,

there's a problem with linux/drivers/char/serial.c that appears when using  
the LIRC serial port drivers (see http://www.lirc.org). Here's how to  
reproduce the problem:

1. Load the lirc_serial module (included in the LIRC package). This module  
uses request_region() for the used serial port's IO space.

2. Load the kernel serial module. In rs_init() the available serial ports  
are initialized. For the port already claimed by the lirc_serial module  
check_region() fails and state->type for this port stays PORT_UNKNOWN.

Now the problem:
3. Open the /dev/ttySx for the port that is occupied by the lirc_serial  
module. rs_open() does not check the state of the serial port and returns  
no error. Now you can use setserial to hijack the port... lirc_serial  
stops working.

The patch below fixes the problem for me (tested with 2.2.19 and 2.2.20).  
There's one problem with this patch though. Once state->type ist  
PORT_UNKNOWN for a port there's no way to reclaim the port with e.g.  
setserial unless you remove the serial port module and load it again.

Christoph

PS: I'm not subscribed, cc me if replying.

--- Schnipp ---
--- linux/drivers/char/serial.c	Sun Mar 25 18:37:31 2001
+++ serial.c	Tue Jan 15 18:20:59 2002
@@ -928,6 +928,11 @@
 	unsigned short ICP;
 #endif

+	if(state->type == PORT_UNKNOWN)
+	{
+		return -ENODEV;
+	}
+
 	page = get_free_page(GFP_KERNEL);
 	if (!page)
 		return -ENOMEM;
@@ -1738,7 +1743,10 @@
 	info->xmit_fifo_size = state->xmit_fifo_size =
 		new_serial.xmit_fifo_size;

-	release_region(state->port,8);
+	if(old_state.type != PORT_UNKNOWN)
+	{
+		release_region(state->port,8);
+	}
 	if (change_port || change_irq) {
 		/*
 		 * We need to shutdown the serial port at the old
@@ -1750,8 +1758,14 @@
 		info->hub6 = state->hub6 = new_serial.hub6;
 	}
 	if (state->type != PORT_UNKNOWN)
+	{
+		retval=check_region(state->port,8);
+		if(retval<0)
+		{
+			return retval;
+		}
 		request_region(state->port,8,"serial(set)");
-
+	}
 	
 check_and_exit:
 	if (!state->port || !state->type)
@@ -3586,3 +3600,4 @@
 	return kmem_start;
 }
 #endif
+
--- Schnipp ---

             reply	other threads:[~2002-02-02 23:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-02 23:21 Christoph Bartelmus [this message]
2002-02-03  0:33 ` Russell King

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=8IBS9f7Xz9B@hit-columbus.hit.handshake.de \
    --to=columbus@hit.handshake.de \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®