2018-06-12 04:53:03

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH] tty: serial: add error handling for try_module_get

When try_module_get fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling try_module_get.

Signed-off-by: Zhouyang Jia <[email protected]>
---
drivers/tty/serial/kgdboc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index b4ba2b1..641e22a 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -286,8 +286,10 @@ static void kgdboc_pre_exp_handler(void)
con_debug_enter(vc_cons[fg_console].d);
}
/* Increment the module count when the debugger is active */
- if (!kgdb_connected)
- try_module_get(THIS_MODULE);
+ if (!kgdb_connected) {
+ if (!try_module_get(THIS_MODULE))
+ printk(KERN_ERR "kgdboc: cannot get module.\n");
+ }
}

static void kgdboc_post_exp_handler(void)
--
2.7.4



2018-06-12 08:24:47

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] tty: serial: add error handling for try_module_get

On Tue, Jun 12, 2018 at 7:50 AM, Zhouyang Jia <[email protected]> wrote:
> When try_module_get fails, the lack of error-handling code may
> cause unexpected results.

What results? What is recovery approach here?
How printing message change a behaviour?

> This patch adds error-handling code after calling try_module_get.

> + if (!kgdb_connected) {
> + if (!try_module_get(THIS_MODULE))
> + printk(KERN_ERR "kgdboc: cannot get module.\n");

So, what's wrong with pr_err() ?

> + }

--
With Best Regards,
Andy Shevchenko