2018-06-12 04:44:41

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH] isdn/i4l: 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/isdn/i4l/isdn_common.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index 7c6f3f5..7e52851 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -71,7 +71,8 @@ static int isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding);
static inline void
isdn_lock_driver(isdn_driver_t *drv)
{
- try_module_get(drv->interface->owner);
+ if (!try_module_get(drv->interface->owner))
+ printk(KERN_WARNING "isdn_lock_driver: cannot get module\n");
drv->locks++;
}

--
2.7.4



2018-06-12 10:12:06

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] isdn/i4l: add error handling for try_module_get

On 6/12/2018 7:43 AM, Zhouyang Jia wrote:

> 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/isdn/i4l/isdn_common.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
> index 7c6f3f5..7e52851 100644
> --- a/drivers/isdn/i4l/isdn_common.c
> +++ b/drivers/isdn/i4l/isdn_common.c
> @@ -71,7 +71,8 @@ static int isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding);
> static inline void
> isdn_lock_driver(isdn_driver_t *drv)
> {
> - try_module_get(drv->interface->owner);
> + if (!try_module_get(drv->interface->owner))
> + printk(KERN_WARNING "isdn_lock_driver: cannot get module\n");

Do you call this error handling code? :-)
And BTW we have pr_warn() for that.

> drv->locks++;
> }
>

MBR, Sergei