2007-02-19 18:18:37

by Cyrill Gorcunov

[permalink] [raw]
Subject: [PATCH] USB Elan FTDI: check for workqueue creation

This patch prevents from NULL pointer usage if
workqueue creation failed.

Signed-off-by: Cyrill Gorcunov <[email protected]>

---

drivers/usb/misc/ftdi-elan.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 0c1d66d..67a25e9 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -57,9 +57,9 @@ module_param(distrust_firmware, bool, 0);
MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
"t setup");
extern struct platform_driver u132_platform_driver;
-static struct workqueue_struct *status_queue;
-static struct workqueue_struct *command_queue;
-static struct workqueue_struct *respond_queue;
+static struct workqueue_struct *status_queue = NULL;
+static struct workqueue_struct *command_queue = NULL;
+static struct workqueue_struct *respond_queue = NULL;
/*
* ftdi_module_lock exists to protect access to global variables
*
@@ -2905,17 +2905,31 @@ static int __init ftdi_elan_init(void)
{
int result;
printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name,
- __TIME__, __DATE__);
+ __TIME__, __DATE__);
init_MUTEX(&ftdi_module_lock);
INIT_LIST_HEAD(&ftdi_static_list);
status_queue = create_singlethread_workqueue("ftdi-status-control");
+ if (!status_queue)
+ goto err1;
command_queue = create_singlethread_workqueue("ftdi-command-engine");
+ if (!command_queue)
+ goto err2;
respond_queue = create_singlethread_workqueue("ftdi-respond-engine");
+ if (!respond_queue)
+ goto err3;
result = usb_register(&ftdi_elan_driver);
if (result)
printk(KERN_ERR "usb_register failed. Error number %d\n",
- result);
+ result);
return result;
+
+ err3:
+ destroy_workqueue(command_queue);
+ err2:
+ destroy_workqueue(status_queue);
+ err1:
+ printk(KERN_ERR "%s couldn't create workqueue\n", ftdi_elan_driver.name);
+ return -ENOMEM;
}

static void __exit ftdi_elan_exit(void)


2007-02-22 23:57:10

by Pete Zaitcev

[permalink] [raw]
Subject: Re: [PATCH] USB Elan FTDI: check for workqueue creation

On Mon, 19 Feb 2007 21:15:49 +0300, Cyrill Gorcunov <[email protected]> wrote:

> +++ b/drivers/usb/misc/ftdi-elan.c
> @@ -57,9 +57,9 @@ module_param(distrust_firmware, bool, 0);
> MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
> "t setup");
> extern struct platform_driver u132_platform_driver;
> -static struct workqueue_struct *status_queue;
> +static struct workqueue_struct *status_queue = NULL;

You better drop this part. Someone is bound to object.

-- Pete

2007-02-23 07:56:15

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] USB Elan FTDI: check for workqueue creation

On Thu, Feb 22, 2007 at 03:55:23PM -0800, Pete Zaitcev wrote:
| On Mon, 19 Feb 2007 21:15:49 +0300, Cyrill Gorcunov <[email protected]> wrote:
|
| > +++ b/drivers/usb/misc/ftdi-elan.c
| > @@ -57,9 +57,9 @@ module_param(distrust_firmware, bool, 0);
| > MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
| > "t setup");
| > extern struct platform_driver u132_platform_driver;
| > -static struct workqueue_struct *status_queue;
| > +static struct workqueue_struct *status_queue = NULL;
|
| You better drop this part. Someone is bound to object.
|
| -- Pete
|

Hi,

actually I don't understand why... Event on ftdi_elan_exit()
status_queue is setting up to NULL. And what is bound to object?
Could you write more detailed?

Cyrill

2007-02-23 08:12:57

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] USB Elan FTDI: check for workqueue creation

On Thu, Feb 22, 2007 at 11:57:38PM -0800, Pete Zaitcev wrote:
| On Fri, 23 Feb 2007 10:53:22 +0300, Cyrill Gorcunov <[email protected]> wrote:
|
| > | > -static struct workqueue_struct *status_queue;
| > | > +static struct workqueue_struct *status_queue = NULL;
|
| > | You better drop this part. Someone is bound to object.
|
| > actually I don't understand why... Event on ftdi_elan_exit()
| > status_queue is setting up to NULL. And what is bound to object?
| > Could you write more detailed?
|
| All these variables are static, they are already initialized to zero.
|
| -- Pete
|

Pete,

I may be wrong, but a lot of the kernel code have static pointers
initialized to NULL with explicit manner... More over I always thought
that _static_ is not mean _initialized to zero_. I think _static_ is
just the method to _hide_ variables in the file (as ANSI C describes).
Am I wrong?

Cyrill

2007-02-24 01:45:12

by Pete Zaitcev

[permalink] [raw]
Subject: Re: [PATCH] USB Elan FTDI: check for workqueue creation

On Fri, 23 Feb 2007 11:10:05 +0300, Cyrill Gorcunov <[email protected]> wrote:

> I may be wrong, but a lot of the kernel code have static pointers
> initialized to NULL with explicit manner... More over I always thought
> that _static_ is not mean _initialized to zero_. I think _static_ is
> just the method to _hide_ variables in the file (as ANSI C describes).
> Am I wrong?

I'm afraid you are wrong here. Static variables are initialized on
zero in C, although I cannot provide you with a relevant quote from
a standard. Just trust me for now, and resubmit the patch without
the first segment... :-) You're clearly fixing a bug in it.

-- Pete

2007-02-24 07:15:21

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] USB Elan FTDI: check for workqueue creation

On Fri, Feb 23, 2007 at 05:43:37PM -0800, Pete Zaitcev wrote:
| On Fri, 23 Feb 2007 11:10:05 +0300, Cyrill Gorcunov <[email protected]> wrote:
|
| > I may be wrong, but a lot of the kernel code have static pointers
| > initialized to NULL with explicit manner... More over I always thought
| > that _static_ is not mean _initialized to zero_. I think _static_ is
| > just the method to _hide_ variables in the file (as ANSI C describes).
| > Am I wrong?
|
| I'm afraid you are wrong here. Static variables are initialized on
| zero in C, although I cannot provide you with a relevant quote from
| a standard. Just trust me for now, and resubmit the patch without
| the first segment... :-) You're clearly fixing a bug in it.
|
| -- Pete
|

Hi Pete,

OK, I'll send a new one ;)

Cyrill