linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: Bluetooth: Fix input device registration
@ 2012-05-14 13:30 Dan Carpenter
  2012-05-14 20:02 ` Gustavo Padovan
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-05-14 13:30 UTC (permalink / raw)
  To: padovan; +Cc: linux-bluetooth

Hi, I am working on some new stuff for Smatch and sending bug reports
on potential bugs I find as I go.

----
This is a semi-automatic email about new static checker warnings.

The patch 3415a5fdde71: "Bluetooth: Fix input device registration" 
from Oct 6, 2011, leads to the following Smatch complaint:

net/bluetooth/hidp/core.c:1072 hidp_add_connection()
	 error: we previously assumed 'session->input' could be null (see line 1049)

net/bluetooth/hidp/core.c
  1046          if (session->hid) {
  1047                  vendor  = session->hid->vendor;
  1048			product = session->hid->product;
  1049		} else if (session->input) {
  1050			vendor  = session->input->id.vendor;
  1051			product = session->input->id.product;
  1052		} else {
                ^^^^^^^^
If we hit this else clause then "session->input" and "session->hid" are
both NULL.

  1053			vendor = 0x0000;
  1054			product = 0x0000;
  1055		}
  1056	
  1057		session->task = kthread_run(hidp_session, session, "khidpd_%04x%04x",
  1058								vendor, product);
  1059		if (IS_ERR(session->task)) {
  1060			err = PTR_ERR(session->task);
  1061			goto unlink;
  1062		}
  1063	
  1064		while (session->waiting_for_startup) {
  1065			wait_event_interruptible(session->startup_queue,
  1066				!session->waiting_for_startup);
  1067		}
  1068	
  1069		if (session->hid)
  1070			err = hid_add_device(session->hid);
  1071		else
  1072			err = input_register_device(session->input);
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It leads to a NULL dereference inside the input_register_device() call.

  1073	
  1074		if (err < 0) {

regards,
dan carpenter


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

* Re: Bluetooth: Fix input device registration
  2012-05-14 13:30 Bluetooth: Fix input device registration Dan Carpenter
@ 2012-05-14 20:02 ` Gustavo Padovan
  0 siblings, 0 replies; 2+ messages in thread
From: Gustavo Padovan @ 2012-05-14 20:02 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: padovan, linux-bluetooth

Hi Dan,

* Dan Carpenter <dan.carpenter@oracle.com> [2012-05-14 16:30:03 +0300]:

> Hi, I am working on some new stuff for Smatch and sending bug reports
> on potential bugs I find as I go.
> 
> ----
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 3415a5fdde71: "Bluetooth: Fix input device registration" 
> from Oct 6, 2011, leads to the following Smatch complaint:
> 
> net/bluetooth/hidp/core.c:1072 hidp_add_connection()
> 	 error: we previously assumed 'session->input' could be null (see line 1049)
> 
> net/bluetooth/hidp/core.c
>   1046          if (session->hid) {
>   1047                  vendor  = session->hid->vendor;
>   1048			product = session->hid->product;
>   1049		} else if (session->input) {
>   1050			vendor  = session->input->id.vendor;
>   1051			product = session->input->id.product;
>   1052		} else {
>                 ^^^^^^^^
> If we hit this else clause then "session->input" and "session->hid" are
> both NULL.

Actually both can never be NULL at the same time here. If after call
hdip_setup_input() session->input is still NULL, the we goto purge and skip
the code below.

	Gustavo

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

end of thread, other threads:[~2012-05-14 20:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 13:30 Bluetooth: Fix input device registration Dan Carpenter
2012-05-14 20:02 ` Gustavo Padovan

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).