From: Alex Elder Date: Fri, 27 Mar 2015 20:20:49 +0000 (-0500) Subject: greybus: es1: test apb1_log_task safely X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1624 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=dada3b02a38c2e1d06a43d0d909d48f4db798dfc;p=karo-tx-linux.git greybus: es1: test apb1_log_task safely 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/es1.c b/drivers/staging/greybus/es1.c index 239358dce9be..af8e7b33270b 100644 --- a/drivers/staging/greybus/es1.c +++ b/drivers/staging/greybus/es1.c @@ -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);