linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] uwb: properly check kthread_run return value
@ 2017-09-13 16:06 Andrey Konovalov
  2017-09-13 16:53 ` Dmitry Vyukov
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Konovalov @ 2017-09-13 16:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Johan Hovold, Gustavo A . R . Silva,
	Arvind Yadav, linux-usb, linux-kernel
  Cc: Dmitry Vyukov, Kostya Serebryany, Andrey Konovalov

uwbd_start() calls kthread_run() and checks that the return value is
not NULL. But the return value is not NULL in case kthread_run() fails,
it takes the form of ERR_PTR(-EINTR).

Use IS_ERR() instead.

Also add a check to uwbd_stop().

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 drivers/uwb/uwbd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/uwb/uwbd.c b/drivers/uwb/uwbd.c
index 01c20a260a8b..2a3cc48d837c 100644
--- a/drivers/uwb/uwbd.c
+++ b/drivers/uwb/uwbd.c
@@ -303,7 +303,7 @@ static int uwbd(void *param)
 void uwbd_start(struct uwb_rc *rc)
 {
 	rc->uwbd.task = kthread_run(uwbd, rc, "uwbd");
-	if (rc->uwbd.task == NULL)
+	if (IS_ERR(rc->uwbd.task))
 		printk(KERN_ERR "UWB: Cannot start management daemon; "
 		       "UWB won't work\n");
 	else
@@ -313,7 +313,8 @@ void uwbd_start(struct uwb_rc *rc)
 /* Stop the UWB daemon and free any unprocessed events */
 void uwbd_stop(struct uwb_rc *rc)
 {
-	kthread_stop(rc->uwbd.task);
+	if (!IS_ERR(rc->uwbd.task))
+		kthread_stop(rc->uwbd.task);
 	uwbd_flush(rc);
 }
 
-- 
2.14.1.581.gf28d330327-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] uwb: properly check kthread_run return value
  2017-09-13 16:06 [PATCH v2] uwb: properly check kthread_run return value Andrey Konovalov
@ 2017-09-13 16:53 ` Dmitry Vyukov
  2017-09-14 12:31   ` Andrey Konovalov
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Vyukov @ 2017-09-13 16:53 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Greg Kroah-Hartman, Johan Hovold, Gustavo A . R . Silva,
	Arvind Yadav, USB list, LKML, Kostya Serebryany

On Wed, Sep 13, 2017 at 6:06 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
> uwbd_start() calls kthread_run() and checks that the return value is
> not NULL. But the return value is not NULL in case kthread_run() fails,
> it takes the form of ERR_PTR(-EINTR).
>
> Use IS_ERR() instead.
>
> Also add a check to uwbd_stop().
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  drivers/uwb/uwbd.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/uwb/uwbd.c b/drivers/uwb/uwbd.c
> index 01c20a260a8b..2a3cc48d837c 100644
> --- a/drivers/uwb/uwbd.c
> +++ b/drivers/uwb/uwbd.c
> @@ -303,7 +303,7 @@ static int uwbd(void *param)
>  void uwbd_start(struct uwb_rc *rc)
>  {
>         rc->uwbd.task = kthread_run(uwbd, rc, "uwbd");
> -       if (rc->uwbd.task == NULL)
> +       if (IS_ERR(rc->uwbd.task))
>                 printk(KERN_ERR "UWB: Cannot start management daemon; "
>                        "UWB won't work\n");
>         else
> @@ -313,7 +313,8 @@ void uwbd_start(struct uwb_rc *rc)
>  /* Stop the UWB daemon and free any unprocessed events */
>  void uwbd_stop(struct uwb_rc *rc)
>  {
> -       kthread_stop(rc->uwbd.task);
> +       if (!IS_ERR(rc->uwbd.task))
> +               kthread_stop(rc->uwbd.task);

It looks weird to assign an error to rc->uwbd.task and leave it there.
I think it's better to not assign errors to rc->uwbd.task, i.e. it's
either a valid task or NULL.

>         uwbd_flush(rc);
>  }
>
> --
> 2.14.1.581.gf28d330327-goog
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] uwb: properly check kthread_run return value
  2017-09-13 16:53 ` Dmitry Vyukov
@ 2017-09-14 12:31   ` Andrey Konovalov
  0 siblings, 0 replies; 3+ messages in thread
From: Andrey Konovalov @ 2017-09-14 12:31 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Greg Kroah-Hartman, Johan Hovold, Gustavo A . R . Silva,
	Arvind Yadav, USB list, LKML, Kostya Serebryany

On Wed, Sep 13, 2017 at 6:53 PM, Dmitry Vyukov <dvyukov@google.com> wrote:
> On Wed, Sep 13, 2017 at 6:06 PM, Andrey Konovalov <andreyknvl@google.com> wrote:
>> uwbd_start() calls kthread_run() and checks that the return value is
>> not NULL. But the return value is not NULL in case kthread_run() fails,
>> it takes the form of ERR_PTR(-EINTR).
>>
>> Use IS_ERR() instead.
>>
>> Also add a check to uwbd_stop().
>>
>> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>> ---
>>  drivers/uwb/uwbd.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/uwb/uwbd.c b/drivers/uwb/uwbd.c
>> index 01c20a260a8b..2a3cc48d837c 100644
>> --- a/drivers/uwb/uwbd.c
>> +++ b/drivers/uwb/uwbd.c
>> @@ -303,7 +303,7 @@ static int uwbd(void *param)
>>  void uwbd_start(struct uwb_rc *rc)
>>  {
>>         rc->uwbd.task = kthread_run(uwbd, rc, "uwbd");
>> -       if (rc->uwbd.task == NULL)
>> +       if (IS_ERR(rc->uwbd.task))
>>                 printk(KERN_ERR "UWB: Cannot start management daemon; "
>>                        "UWB won't work\n");
>>         else
>> @@ -313,7 +313,8 @@ void uwbd_start(struct uwb_rc *rc)
>>  /* Stop the UWB daemon and free any unprocessed events */
>>  void uwbd_stop(struct uwb_rc *rc)
>>  {
>> -       kthread_stop(rc->uwbd.task);
>> +       if (!IS_ERR(rc->uwbd.task))
>> +               kthread_stop(rc->uwbd.task);
>
> It looks weird to assign an error to rc->uwbd.task and leave it there.
> I think it's better to not assign errors to rc->uwbd.task, i.e. it's
> either a valid task or NULL.

Sent v3.

>
>>         uwbd_flush(rc);
>>  }
>>
>> --
>> 2.14.1.581.gf28d330327-goog
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-14 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-13 16:06 [PATCH v2] uwb: properly check kthread_run return value Andrey Konovalov
2017-09-13 16:53 ` Dmitry Vyukov
2017-09-14 12:31   ` Andrey Konovalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).