* [PATCH next] staging: wilc1000: avoid NULL pointer dereference on error
@ 2015-10-07 5:08 Vincent Stehlé
2015-10-07 6:23 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Vincent Stehlé @ 2015-10-07 5:08 UTC (permalink / raw)
To: devel
Cc: linux-wireless, linux-kernel, Vincent Stehlé, Johnny Kim,
Rachel Kim, Dean Lee, Chris Park, Nicolas Ferre,
Greg Kroah-Hartman
The host_int_init() function can dereference the pstrWFIDrv pointer
while it is NULL on its error path. Jump directly to the _fail_ error
label in the end of the error handling path to avoid that.
By doing that we also skip stopping our kthread and destroying
our message queue, but they were not started or created yet in that case
anyway.
This fixes the following coccinelle error:
drivers/staging/wilc1000/host_interface.c:6100:17-33: ERROR: pstrWFIDrv is NULL but dereferenced.
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Johnny Kim <johnny.kim@atmel.com>
Cc: Rachel Kim <rachel.kim@atmel.com>
Cc: Dean Lee <dean.lee@atmel.com>
Cc: Chris Park <chris.park@atmel.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
Hi,
Another form of this patch would make sense on mainline as well, but the
driver has changed so much in the mean time that it makes more sense to
modify staging-next.
Best regards,
V.
drivers/staging/wilc1000/host_interface.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 2cf82b2..2fe3023 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -6017,7 +6017,7 @@ s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv)
pstrWFIDrv = kzalloc(sizeof(tstrWILC_WFIDrv), GFP_KERNEL);
if (!pstrWFIDrv) {
result = -ENOMEM;
- goto _fail_timer_2;
+ goto _fail_;
}
*phWFIDrv = pstrWFIDrv;
err = add_handler_in_list(pstrWFIDrv);
--
2.5.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH next] staging: wilc1000: avoid NULL pointer dereference on error
2015-10-07 5:08 [PATCH next] staging: wilc1000: avoid NULL pointer dereference on error Vincent Stehlé
@ 2015-10-07 6:23 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2015-10-07 6:23 UTC (permalink / raw)
To: Vincent Stehlé
Cc: devel, Rachel Kim, Dean Lee, Chris Park, Nicolas Ferre,
linux-wireless, Johnny Kim, linux-kernel, Greg Kroah-Hartman
On Wed, Oct 07, 2015 at 07:08:25AM +0200, Vincent Stehlé wrote:
> drivers/staging/wilc1000/host_interface.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
> index 2cf82b2..2fe3023 100644
> --- a/drivers/staging/wilc1000/host_interface.c
> +++ b/drivers/staging/wilc1000/host_interface.c
> @@ -6017,7 +6017,7 @@ s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv)
> pstrWFIDrv = kzalloc(sizeof(tstrWILC_WFIDrv), GFP_KERNEL);
> if (!pstrWFIDrv) {
> result = -ENOMEM;
> - goto _fail_timer_2;
> + goto _fail_;
Fair enough. I would have prefered a direct return, but his also works.
The error handling in this function is still very bad and nonsensical.
You have fixed the first goto but all the others are buggy as well.
if add_handler_in_list() fails we should "goto free_pstrWFIDrv" (except
the label name should have Hungarian notation or CamelCase). Instead of
freeing the current code unlocks a lock which is not initialiazed and
frees some timers which are also not initialized.
TODO: wilc1000: fix error handling in host_int_init()
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-07 6:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-07 5:08 [PATCH next] staging: wilc1000: avoid NULL pointer dereference on error Vincent Stehlé
2015-10-07 6:23 ` Dan Carpenter
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).