OSDN Git Service

greybus: es1: test apb1_log_task safely
authorAlex Elder <elder@linaro.org>
Fri, 27 Mar 2015 20:20:49 +0000 (15:20 -0500)
committerGreg Kroah-Hartman <greg@kroah.com>
Mon, 30 Mar 2015 13:28:13 +0000 (15:28 +0200)
When usb_log_enable() is called, the global apb1_log_task is used to
hold the result of kthread_run().  It is possible for kthread_run()
to return an error pointer, so tests of apb_log_task against NULL
are insufficient to determine its validity.

Note that kthread_run() never returns NULL so we don't have to check
for that.  But apb1_log_task is initially NULL, so that global must
be both non-null and not an error in order to be considered valid.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/es1.c

index 239358d..af8e7b3 100644 (file)
@@ -540,12 +540,12 @@ static const struct file_operations apb1_log_fops = {
 
 static void usb_log_enable(struct es1_ap_dev *es1)
 {
-       if (apb1_log_task != NULL)
+       if (!IS_ERR_OR_NULL(apb1_log_task))
                return;
 
        /* get log from APB1 */
        apb1_log_task = kthread_run(apb1_log_poll, es1, "apb1_log");
-       if (apb1_log_task == ERR_PTR(-ENOMEM))
+       if (IS_ERR(apb1_log_task))
                return;
        apb1_log_dentry = debugfs_create_file("apb1_log", S_IRUGO,
                                                gb_debugfs_get(), NULL,
@@ -554,7 +554,7 @@ static void usb_log_enable(struct es1_ap_dev *es1)
 
 static void usb_log_disable(struct es1_ap_dev *es1)
 {
-       if (apb1_log_task == NULL)
+       if (IS_ERR_OR_NULL(apb1_log_task))
                return;
 
        debugfs_remove(apb1_log_dentry);
@@ -568,7 +568,7 @@ static ssize_t apb1_log_enable_read(struct file *f, char __user *buf,
                                size_t count, loff_t *ppos)
 {
        char tmp_buf[3];
-       int enable = apb1_log_task != NULL;
+       int enable = !IS_ERR_OR_NULL(apb1_log_task);
 
        sprintf(tmp_buf, "%d\n", enable);
        return simple_read_from_buffer(buf, count, ppos, tmp_buf, 3);