uwb: properly check kthread_run return value
PATCH v2 1/1 uwb: properly check kthread_run return value
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().
--- drivers/uwb/uwbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/uwb/uwbd.c +3 -2
@@ -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); }
Signature · 1 line
2.14.1.581.gf28d330327-goog
Quoted 27 lines · Andrey Konovalov
uwbd_start()callskthread_run()and checks that the return value is not NULL. But the return value is not NULL in casekthread_run()fails, it takes the form ofERR_PTR(-EINTR).Use
IS_ERR()instead.Also add a check to
uwbd_stop().Signed-off-by Andrey Konovalov <[email protected]>--- drivers/uwb/uwbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/uwb/uwbd.c +1
-1@@ -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
drivers/uwb/uwbd.c void uwbd_start(struct uwb_rc *rc) · line 317
Quoted 6 lines
drivers/uwb/uwbd.c +2
-1@@ -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.
Quoted 6 lines
drivers/uwb/uwbd.c +0
-1uwbd_flush (rc); } --2.14.1.581.gf28d330327-goog
Quoted 30 lines · Dmitry Vyukov
Quoted 29 lines · Andrey Konovalov
uwbd_start()callskthread_run()and checks that the return value is not NULL. But the return value is not NULL in casekthread_run()fails, it takes the form ofERR_PTR(-EINTR).Use
IS_ERR()instead.Also add a check to
uwbd_stop().Signed-off-by Andrey Konovalov <[email protected]>--- drivers/uwb/uwbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/uwb/uwbd.c +1
-1@@ -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)
Quoted 8 lines
drivers/uwb/uwbd.c void uwbd_start(struct uwb_rc *rc) · line 317
Quoted 4 lines
drivers/uwb/uwbd.c +2
-1{ -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.taskand leave it there. I think it's better to not assign errors torc->uwbd.task, i.e. it's either a valid task or NULL.
Sent v3.
Quoted 7 lines
Quoted 7 lines
drivers/uwb/uwbd.c +0
-1uwbd_flush (rc); } --2.14.1.581.gf28d330327-goog