Skip to contentSkip to conversation

Char: merge ip2main and ip2base

PATCH In review Jiri Slaby 3 participants 8 messages Jul 5, 2008 – Jul 22, 2008 Char and misc drivers

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/4 Char: merge ip2main and ip2base

It's pretty useless to have one setup() function separated along with module_init() which only calls a function from ip2main anyway. Get rid of ip2base.

Remove also checks of always-true now.

---
 drivers/char/ip2/Makefile  |    2 +-
 drivers/char/ip2/ip2base.c |  108 --------------------------------------------
 drivers/char/ip2/ip2main.c |   92 +++++++++++++++++++++++++++++++-------
 3 files changed, 77 insertions(+), 125 deletions(-)
 delete mode 100644 drivers/char/ip2/ip2base.c
drivers/char/ip2/Makefile +1 -1
index 939618f..bc397d9 100644
@@ -4,5 +4,5 @@
 
 obj-$(CONFIG_COMPUTONE)         += ip2.o
 
-ip2-objs			:= ip2base.o ip2main.o
+ip2-objs			:= ip2main.o
 
drivers/char/ip2/ip2base.c deleted +0 -108

108 lines not on this page · raw message

drivers/char/ip2/ip2main.c +76 -16

140 lines not on this page · raw message

Signature · 1 line
1.5.5.1
author
#1 lore raw

PATCH 2/4 Char: ip2, cleanup globals

- do not init .bss zeroed data to zero again (by memset or explicit assignment)
- use char [] instead of char * for string constants

---
 drivers/char/ip2/ip2main.c |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)
drivers/char/ip2/ip2main.c +7 -11
index 8ac1dfe..4174c65 100644
@@ -150,12 +150,12 @@ static int ip2_read_proc(char *, char **, off_t, int, int *, void * );
 /*************/
 
 /* String constants to identify ourselves */
-static char *pcName    = "Computone IntelliPort Plus multiport driver";
-static char *pcVersion = "1.2.14";
+static const char pcName[] = "Computone IntelliPort Plus multiport driver";
+static const char pcVersion[] = "1.2.14";
 
 /* String constants for port names */
-static char *pcDriver_name   = "ip2";
-static char *pcIpl    		 = "ip2ipl";
+static const char pcDriver_name[] = "ip2";
+static const char pcIpl[] = "ip2ipl";
 
 /***********************/
 /* Function Prototypes */
@@ -237,8 +237,8 @@ static const struct file_operations ip2_ipl = {
 	.open		= ip2_ipl_open,
 }; 
 
-static unsigned long irq_counter = 0;
-static unsigned long bh_counter = 0;
+static unsigned long irq_counter;
+static unsigned long bh_counter;
 
 // Use immediate queue to service interrupts
 #define USE_IQI
@@ -286,7 +286,7 @@ MODULE_AUTHOR("Doug McNash");
 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
 MODULE_LICENSE("GPL");
 
-static int poll_only = 0;
+static int poll_only;
 
 static int Eisa_irq;
 static int Eisa_slot;
@@ -613,10 +613,6 @@ static int ip2_loadmain(void)
 	/* Initialise the iiEllis subsystem. */
 	iiEllisInit();
 
-	/* Initialize arrays. */
-	memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
-	memset( DevTable, 0, sizeof DevTable );
-
 	/* Initialise all the boards we can find (up to the maximum). */
 	for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
 		switch ( ip2config.addr[i] ) { 
Signature · 1 line
1.5.5.1
author
#2 lore raw

PATCH 3/4 Char: ip2, fix sparse warnings

---
 drivers/char/ip2/ip2main.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
drivers/char/ip2/ip2main.c +5 -9
index 4174c65..d9b30ab 100644
@@ -375,9 +375,7 @@ have_requested_irq( char irq )
 /* handle subsequent installations of the driver. All memory allocated by the */
 /* driver should be returned since it may be unloaded from memory.            */
 /******************************************************************************/
-#ifdef MODULE
-void __exit
-ip2_cleanup_module(void)
+static void __exit ip2_cleanup_module(void)
 {
 	int err;
 	int i;
@@ -431,7 +429,8 @@ ip2_cleanup_module(void)
 			ip2config.pci_dev[i] = NULL;
 		}
 #endif
-		if ((pB = i2BoardPtrTable[i]) != 0 ) {
+		pB = i2BoardPtrTable[i];
+		if (pB != NULL) {
 			kfree ( pB );
 			i2BoardPtrTable[i] = NULL;
 		}
@@ -448,7 +447,6 @@ ip2_cleanup_module(void)
 #endif
 }
 module_exit(ip2_cleanup_module);
-#endif /* MODULE */
 
 static const struct tty_operations ip2_ops = {
 	.open            = ip2_open,
@@ -1253,9 +1251,8 @@ ip2_polled_interrupt(void)
 {
 	int i;
 	i2eBordStrPtr  pB;
-	const int irq = 0;
 
-	ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
+	ip2trace(ITRC_NO_PORT, ITRC_INTR, 99, 1, 0);
 
 	/* Service just the boards on the list using this irq */
 	for( i = 0; i < i2nBoards; ++i ) {
@@ -1264,9 +1261,8 @@ ip2_polled_interrupt(void)
 //		Only process those boards which match our IRQ.
 //			IRQ = 0 for polled boards, we won't poll "IRQ" boards
 
-		if ( pB && (pB->i2eUsingIrq == irq) ) {
+		if (pB && pB->i2eUsingIrq == 0)
 			ip2_irq_work(pB);
-		}
 	}
 
 	++irq_counter;
Signature · 1 line
1.5.5.1
author
#3 lore raw

PATCH 4/4 Char: ip2, init/deinit cleanup

Cleanup of module_init/exit:
- mostly whitespace
- remove empty functions
- replace c++ comments
- remove useless prints (module loaded, unloaded)
- mark the calls as __exit and __init
- use break; and return; to save some indent levels after it
- note resource leakage

It's still mess, but now it's readable.

---
 drivers/char/ip2/i2ellis.c |   32 ----
 drivers/char/ip2/i2ellis.h |    2 -
 drivers/char/ip2/ip2main.c |  419 +++++++++++++++++++++-----------------------
 3 files changed, 200 insertions(+), 253 deletions(-)
drivers/char/ip2/i2ellis.c +0 -32
index 3601017..29db44d 100644
@@ -69,38 +69,6 @@ static DEFINE_RWLOCK(Dl_spinlock);
 //=======================================================
 
 //******************************************************************************
-// Function:   iiEllisInit()
-// Parameters: None
-//
-// Returns:    Nothing
-//
-// Description:
-//
-// This routine performs any required initialization of the iiEllis subsystem.
-//
-//******************************************************************************
-static void
-iiEllisInit(void)
-{
-}
-
-//******************************************************************************
-// Function:   iiEllisCleanup()
-// Parameters: None
-//
-// Returns:    Nothing
-//
-// Description:
-//
-// This routine performs any required cleanup of the iiEllis subsystem.
-//
-//******************************************************************************
-static void
-iiEllisCleanup(void)
-{
-}
-
-//******************************************************************************
 // Function:   iiSetAddress(pB, address, delay)
 // Parameters: pB      - pointer to the board structure
 //             address - the purported I/O address of the board
drivers/char/ip2/i2ellis.h +0 -2
index c88a64e..fb6df24 100644
@@ -511,7 +511,6 @@ typedef void (*delayFunc_t)(unsigned int);
 //
 // Initialization of a board & structure is in four (five!) parts:
 //
-// 0) iiEllisInit()  - Initialize iiEllis subsystem.
 // 1) iiSetAddress() - Define the board address & delay function for a board.
 // 2) iiReset()      - Reset the board   (provided it exists)
 //       -- Note you may do this to several boards --
@@ -523,7 +522,6 @@ typedef void (*delayFunc_t)(unsigned int);
 // loadware.  To change loadware, you must begin again with step 2, resetting
 // the board again (step 1 not needed).
 
-static void iiEllisInit(void);
 static int iiSetAddress(i2eBordStrPtr, int, delayFunc_t );
 static int iiReset(i2eBordStrPtr);
 static int iiResetDelay(i2eBordStrPtr);
drivers/char/ip2/ip2main.c +198 -217

585 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#4 lore raw
In reply to Jiri Slaby
Quoted 6 lines · On Sat, 5 Jul 2008 15:28:23 +0200 Jiri Slaby <[email protected]> wrote:

It's pretty useless to have one setup() function separated along with module_init() which only calls a function from ip2main anyway. Get rid of ip2base.

Remove also checks of always-true now.

<catching up>

I applied these four, but there's a fly in our ointment.

On 14 July, Akinobu Mita <[email protected]> sent a patch titled "ip2: avoid add_timer() with pending timer" which Alan acked and then claimed was "Queued for ttydev tree". But afaict he then lost it.

If it gets unlost, it will conflict with these changes and I might need to drop these four (I didn't check).

Perhaps you could review this patch and maybe merge this change on top of these four?

Thanks.

Date: Mon, 14 Jul 2008 11:49:55 +0900
From: Akinobu Mita <[email protected]>
To: [email protected]
Cc: "Michael H. Warfield" <[email protected]>
Subject: [PATCH] ip2: avoid add_timer() with pending timer

add_timer() is not suppose to be called when the timer is pending. ip2 driver attempts to avoid that condition by setting and resetting a flag (TimerOn) in timer function. But there is some gap between add_timer() and setting TimerOn.

This patch fix this problem by using mod_timer() and remove TimerOn which has been unnecessary by this change.

Cc Michael H. Warfield <[email protected]>
---
 drivers/char/ip2/ip2main.c |   18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/char/ip2/ip2main.c +4 -14
Index: 2.6-mmotm/drivers/char/ip2/ip2main.c
===================================================================
@@ -252,7 +252,6 @@ static unsigned long bh_counter = 0;
  */
 #define  POLL_TIMEOUT   (jiffies + 1)
 static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
-static char  TimerOn;
 
 #ifdef IP2DEBUG_TRACE
 /* Trace (debug) buffer data */
@@ -372,10 +371,7 @@ ip2_cleanup_module(void)
 	printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
 #endif
 	/* Stop poll timer if we had one. */
-	if ( TimerOn ) {
-		del_timer ( &PollTimer );
-		TimerOn = 0;
-	}
+	del_timer_sync(&PollTimer);
 
 	/* Reset the boards we have. */
 	for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
@@ -746,10 +742,8 @@ ip2_loadmain(int *iop, int *irqp)
 			}
 			if ( ip2config.irq[i] == CIR_POLL ) {
 retry:
-				if (!TimerOn) {
-					PollTimer.expires = POLL_TIMEOUT;
-					add_timer ( &PollTimer );
-					TimerOn = 1;
+				if (!timer_pending(&PollTimer)) {
+					mod_timer(&PollTimer, POLL_TIMEOUT);
 					printk( KERN_INFO "IP2: polling\n");
 				}
 			} else {
@@ -1250,16 +1244,12 @@ ip2_poll(unsigned long arg)
 {
 	ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
 
-	TimerOn = 0; // it's the truth but not checked in service
-
 	// Just polled boards, IRQ = 0 will hit all non-interrupt boards.
 	// It will NOT poll boards handled by hard interrupts.
 	// The issue of queued BH interrupts is handled in ip2_interrupt().
 	ip2_polled_interrupt();
 
-	PollTimer.expires = POLL_TIMEOUT;
-	add_timer( &PollTimer );
-	TimerOn = 1;
+	mod_timer(&PollTimer, POLL_TIMEOUT);
 
 	ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
 }

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw
Quoted 5 lines

I applied these four, but there's a fly in our ointment.

On 14 July, Akinobu Mita <[email protected]> sent a patch titled "ip2: avoid add_timer() with pending timer" which Alan acked and then claimed was "Queued for ttydev tree". But afaict he then lost it.

Its queued but I can unqueue it as it isn't in the pile pending for Linus yet.

#6 lore raw
Quoted 8 lines · On Tue, 22 Jul 2008 10:44:41 +0100 Alan Cox <[email protected]> wrote:
Quoted 5 lines

I applied these four, but there's a fly in our ointment.

On 14 July, Akinobu Mita <[email protected]> sent a patch titled "ip2: avoid add_timer() with pending timer" which Alan acked and then claimed was "Queued for ttydev tree". But afaict he then lost it.

Its queued but I can unqueue it as it isn't in the pile pending for Linus yet.

You've had it queued longer than I've had Jiri's sent-earlier patches queued :(

I guess if Jiri can redo that patch for us then I can slip all five into 2.6.27-rc1?

#7 lore raw
Quoted 8 lines · On Tue, 22 Jul 2008 03:06:55 -0700 Andrew Morton <[email protected]>…
Quoted 6 lines · On Tue, 22 Jul 2008 10:44:41 +0100 Alan Cox <[email protected]> wrote:
Quoted 5 lines

I applied these four, but there's a fly in our ointment.

On 14 July, Akinobu Mita <[email protected]> sent a patch titled "ip2: avoid add_timer() with pending timer" which Alan acked and then claimed was "Queued for ttydev tree". But afaict he then lost it.

Quoted 8 lines
Quoted 2 lines

Its queued but I can unqueue it as it isn't in the pile pending for Linus yet.

You've had it queued longer than I've had Jiri's sent-earlier patches queued :(

I guess if Jiri can redo that patch for us then I can slip all five into 2.6.27-rc1?

Fine by me

Alan