staging:net:fixed to fit tty_driver's kref field
PATCH 1/1 staging:net:fixed to fit tty_driver's kref field
Fixed code to fix tty_driver's kref field
Coding style issues
--- drivers/staging/net/pc300_tty.c | 123 ++++++++++++++++++++------------------ 1 files changed, 65 insertions(+), 58 deletions(-)
drivers/staging/net/pc300_tty.c +65 -58
@@ -46,6 +46,8 @@#include <linux/slab.h> #include <linux/if.h> #include <linux/skbuff.h> +#include <linux/kref.h> +/* TTY includes */ #include <linux/tty.h> #include <linux/tty_flip.h>
@@ -134,12 +136,26 @@ static void cpc_tty_signal_on(pc300dev_t *pc300dev, unsigned char);static int pc300_tiocmset (struct tty_struct *,unsigned int ,unsigned int );static int pc300_tiocmget (struct tty_struct *); +static void cpc_tty_do_unreg_driver (struct kref *ref); +/* functions called by PC300 driver */ void cpc_tty_init (pc300dev_t *dev);void cpc_tty_unregister_service (pc300dev_t *pc300dev);void cpc_tty_receive (pc300dev_t *pc300dev);void cpc_tty_trigger_poll (pc300dev_t *pc300dev); +static void cpc_tty_do_unreg_driver (struct kref *ref) +{ + struct tty_driver *drv = container_of(ref, struct tty_driver, kref); +int ret; + + cpc_tty_unreg_flag =0 ; + + res =tty_unregister_driver (drv); +if (res) +CPC_TTY_DBG ("unregister the tty driver error=%d\n" , res); +} +/* * PC300 TTY clear "signal" */
@@ -239,6 +255,8 @@ void cpc_tty_init(pc300dev_t *pc300dev)/* interface routines from the upper tty layer to the tty driver */ tty_set_operations (&serial_drv, &pc300_ops); +kref_init (&serial_drv.kref); +/* register the TTY driver */ if (tty_register_driver (&serial_drv)) { printk("%s-tty: Failed to register serial driver! ",
@@ -363,37 +381,37 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip)unsigned long flags;int res; -if (!tty || !tty->driver_data ) { +if (!tty || !tty->driver_data) {CPC_TTY_DBG ("hdlx-tty: no TTY in close\n" );return ; } cpc_tty = (st_cpc_tty_area *) tty->driver_data; -if ((cpc_tty->tty != tty)|| (cpc_tty->state !=CPC_TTY_ST_OPEN )) { -CPC_TTY_DBG ("%s: TTY is not opened\n" ,cpc_tty->name); +if ((cpc_tty->tty != tty) || (cpc_tty->state !=CPC_TTY_ST_OPEN )) { +CPC_TTY_DBG ("%s: TTY is not opened\n" , cpc_tty->name);return ; } - +if (!cpc_tty->num_open) { -CPC_TTY_DBG ("%s: TTY is closed\n" ,cpc_tty->name); +CPC_TTY_DBG ("%s: TTY is closed\n" , cpc_tty->name);return ; }if (--cpc_tty->num_open >0 ) { -CPC_TTY_DBG ("%s: TTY closed\n" ,cpc_tty->name); +CPC_TTY_DBG ("%s: TTY closed\n" , cpc_tty->name);return ; }cpc_tty_signal_off (cpc_tty->pc300dev,CTL_DTR ); -CPC_TTY_LOCK (cpc_tty->pc300dev->chan->card, flags);/* lock irq */ +CPC_TTY_LOCK (cpc_tty->pc300dev->chan->card, flags);/* lock irq */ cpc_tty->tty =NULL ; cpc_tty->state =CPC_TTY_ST_INIT ; -CPC_TTY_UNLOCK (cpc_tty->pc300dev->chan->card, flags);/* unlock irq */ - +CPC_TTY_UNLOCK (cpc_tty->pc300dev->chan->card, flags);/* unlock irq */ +if (cpc_tty->buf_rx.first) { -unsigned char * aux; +unsigned char *aux;while (cpc_tty->buf_rx.first) { aux = (unsigned char *)cpc_tty->buf_rx.first; cpc_tty->buf_rx.first = cpc_tty->buf_rx.first->next;
@@ -402,22 +420,18 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip) cpc_tty->buf_rx.first =NULL ; cpc_tty->buf_rx.last =NULL ; } - +kfree (cpc_tty->buf_tx); cpc_tty->buf_tx =NULL ; -CPC_TTY_DBG ("%s: TTY closed\n" ,cpc_tty->name); - -if (!serial_drv.refcount && cpc_tty_unreg_flag) { - cpc_tty_unreg_flag =0 ; -CPC_TTY_DBG ("%s: unregister the tty driver\n" , cpc_tty->name); -if ((res=tty_unregister_driver (&serial_drv))) { -CPC_TTY_DBG ("%s: ERROR ->unregister the tty driver error=%d\n" , - cpc_tty->name,res); - } +CPC_TTY_DBG ("%s: TTY closed\n" , cpc_tty->name); + +if (cpc_tty_unreg_flag) { +CPC_TTY_DBG ("%s: checking unregister the tty driver...\n" , cpc_tty->name); +kref_put (&serial_drv.kref, cpc_tty_do_unreg_driver); } -return ; -} +return ; +}/* * PC300 TTY WRITE routine
@@ -624,33 +638,29 @@ static void cpc_tty_flush_buffer(struct tty_struct *tty)/* * PC300 TTY Hangup routine * -* This routine is called by the tty driver to hangup the interface +* This routine is called by the tty driver to hangup the interface * o clear DTR signal */ static void cpc_tty_hangup (struct tty_struct *tty) -{ -st_cpc_tty_area *cpc_tty; +{ +st_cpc_tty_area *cpc_tty;int res; -if (!tty || !tty->driver_data ) { -CPC_TTY_DBG ("hdlcX-tty: no TTY to hangup\n" ); -return ; +if (!tty || !tty->driver_data) { +CPC_TTY_DBG ("hdlcX-tty: no TTY to hangup\n" ); +return ; } - cpc_tty = (st_cpc_tty_area *) tty->driver_data; + cpc_tty = (st_cpc_tty_area *) tty->driver_data;if ((cpc_tty->tty != tty) || (cpc_tty->state !=CPC_TTY_ST_OPEN )) { -CPC_TTY_DBG ("%s: TTY is not opened\n" ,cpc_tty->name); +CPC_TTY_DBG ("%s: TTY is not opened\n" , cpc_tty->name);return ; } -if (!serial_drv.refcount && cpc_tty_unreg_flag) { - cpc_tty_unreg_flag =0 ; -CPC_TTY_DBG ("%s: unregister the tty driver\n" , cpc_tty->name); -if ((res=tty_unregister_driver (&serial_drv))) { -CPC_TTY_DBG ("%s: ERROR ->unregister the tty driver error=%d\n" , - cpc_tty->name,res); - } +if (cpc_tty_unreg_flag) { +CPC_TTY_DBG ("%s: checking unregister the tty driver...\n" , cpc_tty->name); +kref_put (&serial_drv.kref, cpc_tty_do_unreg_driver); }cpc_tty_signal_off (cpc_tty->pc300dev,CTL_DTR ); }
@@ -1027,43 +1037,40 @@ static void cpc_tty_trace(pc300dev_t *dev, char* buf, int len, char rxtx)*/ void cpc_tty_unregister_service (pc300dev_t *pc300dev) { -st_cpc_tty_area *cpc_tty; +st_cpc_tty_area *cpc_tty = (st_cpc_tty_area *) pc300dev->cpc_tty;ulong flags;int res; -if ((cpc_tty= (st_cpc_tty_area *) pc300dev->cpc_tty) ==NULL ) { +if (cpc_tty ==NULL ) {CPC_TTY_DBG ("%s: interface is not TTY\n" , pc300dev->dev->name); -return ; +return ; }CPC_TTY_DBG ("%s: cpc_tty_unregister_service" , cpc_tty->name); -if (cpc_tty->pc300dev != pc300dev) { -CPC_TTY_DBG ("%s: invalid tty ptr=%s\n" , +if (cpc_tty->pc300dev != pc300dev) { +CPC_TTY_DBG ("%s: invalid tty ptr=%s\n" , pc300dev->dev->name, cpc_tty->name); -return ; +return ; } -if (--cpc_tty_cnt ==0 ) { -if (serial_drv.refcount) { -CPC_TTY_DBG ("%s: unregister is not possible, refcount=%d" , - cpc_tty->name, serial_drv.refcount); +if (--cpc_tty_cnt ==0 ) { +CPC_TTY_DBG ("%s: checking unregister the tty driver...\n" , + cpc_tty->name); + res =kref_put (&serial_drv.kref, cpc_tty_do_unreg_driver); +if (0 == res) { +CPC_TTY_DBG ("%s: unregister is not possible\n" , + cpc_tty->name); cpc_tty_cnt++; cpc_tty_unreg_flag =1 ;return ; - }else { -CPC_TTY_DBG ("%s: unregister the tty driver\n" , cpc_tty->name); -if ((res=tty_unregister_driver (&serial_drv))) { -CPC_TTY_DBG ("%s: ERROR ->unregister the tty driver error=%d\n" , - cpc_tty->name,res); - } } } -CPC_TTY_LOCK (pc300dev->chan->card,flags); - cpc_tty->tty =NULL ; +CPC_TTY_LOCK (pc300dev->chan->card, flags); + cpc_tty->tty =NULL ;CPC_TTY_UNLOCK (pc300dev->chan->card, flags); - cpc_tty->tty_minor =0 ; - cpc_tty->state =CPC_TTY_ST_IDLE ; -} + cpc_tty->tty_minor =0 ; + cpc_tty->state =CPC_TTY_ST_IDLE ; +}/* * PC300 TTY trigger poll routine
Signature · 1 line
1.7.0.4
Quoted 4 lines · Baodong Chen
Fixed code to fix tty_driver's kref field
Coding style issuesSigned-off-by Baodong Chen <[email protected]>
Hi Baodong.
As already pointed out by Jiri please split this up in several patches.
[PATCH 1/x] staging:net:pc300: fix white space usage
[PATCH 2/x] staging:net:pc300: add proper kref support
[PATCH 3/x] staging:net:pc300: use pr_dev
[PATCH 4/x] staging:net:pc300: drop use of CPC_TTY_LOCK/CPC_TTY_UNLOCK macros etc...
The latter two is not impleted yet but proposals for further cleanups.
Sam
drivers/staging/net/pc300_tty.c static void cpc_tty_flush_buffer(struct tty_struct *tty) · line 655
Quoted 12 lines
--- drivers/staging/net/pc300_tty.c | 123 ++++++++++++++++++++------------------ 1 files changed, 65 insertions(+), 58 deletions(-)drivers/staging/net/pc300_tty.c +1
-1- cpc_tty = (st_cpc_tty_area *) tty->driver_data; + cpc_tty = (st_cpc_tty_area *) tty->driver_data;
^drop space
Quoted 17 lines · Sam Ravnborg
Quoted 4 lines · Baodong Chen
Fixed code to fix tty_driver's kref field
Coding style issuesSigned-off-by Baodong Chen <[email protected]>Hi Baodong.
As already pointed out by Jiri please split this up in several patches.
[PATCH 1/x] staging:net:pc300: fix white space usage
[PATCH 2/x] staging:net:pc300: add proper kref support
[PATCH 3/x] staging:net:pc300: usepr_dev
[PATCH 4/x] staging:net:pc300: drop use of CPC_TTY_LOCK/CPC_TTY_UNLOCK macros etc...
Quoted 3 lines
The latter two is not impleted yet but proposals for further cleanups.
Sam
ok, i will follow that rule and resubmit it.
thanks!
Quoted 15 lines
drivers/staging/net/pc300_tty.c static void cpc_tty_flush_buffer(struct tty_struct *tty) · line 655
Quoted 13 lines
--- drivers/staging/net/pc300_tty.c | 123 ++++++++++++++++++++------------------ 1 files changed, 65 insertions(+), 58 deletions(-)drivers/staging/net/pc300_tty.c +1
-1- cpc_tty = (st_cpc_tty_area *) tty->driver_data; + cpc_tty = (st_cpc_tty_area *) tty->driver_data;^drop space