* [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c
@ 2012-08-27 13:34 Baodong Chen
2012-08-30 13:36 ` Jiri Slaby
0 siblings, 1 reply; 4+ messages in thread
From: Baodong Chen @ 2012-08-27 13:34 UTC (permalink / raw)
To: gregkh, jslaby, davem; +Cc: devel, linux-kernel, Baodong Chen
Signed-off-by: Baodong Chen <chenbdchenbd@gmail.com>
---
drivers/staging/net/pc300_tty.c | 55 ++++++++++++++++++++++-----------------
1 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/drivers/staging/net/pc300_tty.c b/drivers/staging/net/pc300_tty.c
index 4709f42..91ada93 100644
--- a/drivers/staging/net/pc300_tty.c
+++ b/drivers/staging/net/pc300_tty.c
@@ -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! ",
@@ -408,13 +426,9 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip)
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);
- }
+ 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;
}
@@ -644,13 +658,9 @@ static void cpc_tty_hangup(struct tty_struct *tty)
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);
}
@@ -1043,19 +1053,16 @@ void cpc_tty_unregister_service(pc300dev_t *pc300dev)
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);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c
2012-08-27 13:34 [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c Baodong Chen
@ 2012-08-30 13:36 ` Jiri Slaby
2012-09-04 21:25 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2012-08-30 13:36 UTC (permalink / raw)
To: Baodong Chen; +Cc: gregkh, davem, devel, linux-kernel
On 08/27/2012 03:34 PM, Baodong Chen wrote:
Sorry, I do not get this change. You should not touch tty_driver.kref at
all.
And what is the patch good for?
> Signed-off-by: Baodong Chen <chenbdchenbd@gmail.com>
> ---
> drivers/staging/net/pc300_tty.c | 55 ++++++++++++++++++++++-----------------
> 1 files changed, 31 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/staging/net/pc300_tty.c b/drivers/staging/net/pc300_tty.c
> index 4709f42..91ada93 100644
> --- a/drivers/staging/net/pc300_tty.c
> +++ b/drivers/staging/net/pc300_tty.c
> @@ -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! ",
> @@ -408,13 +426,9 @@ static void cpc_tty_close(struct tty_struct *tty, struct file *flip)
>
> 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);
> - }
> + 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;
> }
> @@ -644,13 +658,9 @@ static void cpc_tty_hangup(struct tty_struct *tty)
> 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);
> }
> @@ -1043,19 +1053,16 @@ void cpc_tty_unregister_service(pc300dev_t *pc300dev)
> 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);
>
--
js
suse labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c
2012-08-30 13:36 ` Jiri Slaby
@ 2012-09-04 21:25 ` Greg KH
2012-10-15 13:35 ` Baodong Chen
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2012-09-04 21:25 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Baodong Chen, devel, davem, linux-kernel
On Thu, Aug 30, 2012 at 03:36:18PM +0200, Jiri Slaby wrote:
> On 08/27/2012 03:34 PM, Baodong Chen wrote:
>
> Sorry, I do not get this change. You should not touch tty_driver.kref at
> all.
Yeah, that's not ok, it's now dropped from my patch queue.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c
2012-09-04 21:25 ` Greg KH
@ 2012-10-15 13:35 ` Baodong Chen
0 siblings, 0 replies; 4+ messages in thread
From: Baodong Chen @ 2012-10-15 13:35 UTC (permalink / raw)
To: Greg KH; +Cc: Jiri Slaby, devel, davem, linux-kernel
sorry for my mistake, i should do more home work on code!!
On Wed, Sep 5, 2012 at 5:25 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Thu, Aug 30, 2012 at 03:36:18PM +0200, Jiri Slaby wrote:
>> On 08/27/2012 03:34 PM, Baodong Chen wrote:
>>
>> Sorry, I do not get this change. You should not touch tty_driver.kref at
>> all.
>
> Yeah, that's not ok, it's now dropped from my patch queue.
>
> greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-15 13:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-27 13:34 [PATCH] staging:fixed code to fit tty_driver's kref filed fixed code to fit tty_driver's kref filed for drivers/staging/net/pc300_tty.c Baodong Chen
2012-08-30 13:36 ` Jiri Slaby
2012-09-04 21:25 ` Greg KH
2012-10-15 13:35 ` Baodong Chen
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).