Skip to content

Commit 2ac97f0

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Have wacom_tpc_irq guard against possible NULL dereference
The following Smatch complaint was generated in response to commit 2a6cdbd ("HID: wacom: Introduce new 'touch_input' device"): drivers/hid/wacom_wac.c:1586 wacom_tpc_irq() error: we previously assumed 'wacom->touch_input' could be null (see line 1577) The 'touch_input' and 'pen_input' variables point to the 'struct input_dev' used for relaying touch and pen events to userspace, respectively. If a device does not have a touch interface or pen interface, the associated input variable is NULL. The 'wacom_tpc_irq()' function is responsible for forwarding input reports to a more-specific IRQ handler function. An unknown report could theoretically be mistaken as e.g. a touch report on a device which does not have a touch interface. This can be prevented by only calling the pen/touch functions are called when the pen/touch pointers are valid. Fixes: 2a6cdbd ("HID: wacom: Introduce new 'touch_input' device") Signed-off-by: Jason Gerecke <[email protected]> Reviewed-by: Ping Cheng <[email protected]> Cc: [email protected] Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7af4c72 commit 2ac97f0

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

drivers/hid/wacom_wac.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,37 +1571,38 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
15711571
{
15721572
unsigned char *data = wacom->data;
15731573

1574-
if (wacom->pen_input)
1574+
if (wacom->pen_input) {
15751575
dev_dbg(wacom->pen_input->dev.parent,
15761576
"%s: received report #%d\n", __func__, data[0]);
1577-
else if (wacom->touch_input)
1577+
1578+
if (len == WACOM_PKGLEN_PENABLED ||
1579+
data[0] == WACOM_REPORT_PENABLED)
1580+
return wacom_tpc_pen(wacom);
1581+
}
1582+
else if (wacom->touch_input) {
15781583
dev_dbg(wacom->touch_input->dev.parent,
15791584
"%s: received report #%d\n", __func__, data[0]);
15801585

1581-
switch (len) {
1582-
case WACOM_PKGLEN_TPC1FG:
1583-
return wacom_tpc_single_touch(wacom, len);
1586+
switch (len) {
1587+
case WACOM_PKGLEN_TPC1FG:
1588+
return wacom_tpc_single_touch(wacom, len);
15841589

1585-
case WACOM_PKGLEN_TPC2FG:
1586-
return wacom_tpc_mt_touch(wacom);
1590+
case WACOM_PKGLEN_TPC2FG:
1591+
return wacom_tpc_mt_touch(wacom);
15871592

1588-
case WACOM_PKGLEN_PENABLED:
1589-
return wacom_tpc_pen(wacom);
1593+
default:
1594+
switch (data[0]) {
1595+
case WACOM_REPORT_TPC1FG:
1596+
case WACOM_REPORT_TPCHID:
1597+
case WACOM_REPORT_TPCST:
1598+
case WACOM_REPORT_TPC1FGE:
1599+
return wacom_tpc_single_touch(wacom, len);
15901600

1591-
default:
1592-
switch (data[0]) {
1593-
case WACOM_REPORT_TPC1FG:
1594-
case WACOM_REPORT_TPCHID:
1595-
case WACOM_REPORT_TPCST:
1596-
case WACOM_REPORT_TPC1FGE:
1597-
return wacom_tpc_single_touch(wacom, len);
1598-
1599-
case WACOM_REPORT_TPCMT:
1600-
case WACOM_REPORT_TPCMT2:
1601-
return wacom_mt_touch(wacom);
1601+
case WACOM_REPORT_TPCMT:
1602+
case WACOM_REPORT_TPCMT2:
1603+
return wacom_mt_touch(wacom);
16021604

1603-
case WACOM_REPORT_PENABLED:
1604-
return wacom_tpc_pen(wacom);
1605+
}
16051606
}
16061607
}
16071608

0 commit comments

Comments
 (0)