Skip to content

Commit 58b7cb1

Browse files
jigpugregkh
authored andcommitted
HID: wacom: Have wacom_tpc_irq guard against possible NULL dereference
commit 2ac97f0f6654da14312d125005c77a6010e0ea38 upstream. 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 <jason.gerecke@wacom.com> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c0fd730 commit 58b7cb1

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

drivers/hid/wacom_wac.c

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

1443-
if (wacom->pen_input)
1443+
if (wacom->pen_input) {
14441444
dev_dbg(wacom->pen_input->dev.parent,
14451445
"%s: received report #%d\n", __func__, data[0]);
1446-
else if (wacom->touch_input)
1446+
1447+
if (len == WACOM_PKGLEN_PENABLED ||
1448+
data[0] == WACOM_REPORT_PENABLED)
1449+
return wacom_tpc_pen(wacom);
1450+
}
1451+
else if (wacom->touch_input) {
14471452
dev_dbg(wacom->touch_input->dev.parent,
14481453
"%s: received report #%d\n", __func__, data[0]);
14491454

1450-
switch (len) {
1451-
case WACOM_PKGLEN_TPC1FG:
1452-
return wacom_tpc_single_touch(wacom, len);
1455+
switch (len) {
1456+
case WACOM_PKGLEN_TPC1FG:
1457+
return wacom_tpc_single_touch(wacom, len);
14531458

1454-
case WACOM_PKGLEN_TPC2FG:
1455-
return wacom_tpc_mt_touch(wacom);
1459+
case WACOM_PKGLEN_TPC2FG:
1460+
return wacom_tpc_mt_touch(wacom);
14561461

1457-
case WACOM_PKGLEN_PENABLED:
1458-
return wacom_tpc_pen(wacom);
1462+
default:
1463+
switch (data[0]) {
1464+
case WACOM_REPORT_TPC1FG:
1465+
case WACOM_REPORT_TPCHID:
1466+
case WACOM_REPORT_TPCST:
1467+
case WACOM_REPORT_TPC1FGE:
1468+
return wacom_tpc_single_touch(wacom, len);
14591469

1460-
default:
1461-
switch (data[0]) {
1462-
case WACOM_REPORT_TPC1FG:
1463-
case WACOM_REPORT_TPCHID:
1464-
case WACOM_REPORT_TPCST:
1465-
case WACOM_REPORT_TPC1FGE:
1466-
return wacom_tpc_single_touch(wacom, len);
1467-
1468-
case WACOM_REPORT_TPCMT:
1469-
case WACOM_REPORT_TPCMT2:
1470-
return wacom_mt_touch(wacom);
1470+
case WACOM_REPORT_TPCMT:
1471+
case WACOM_REPORT_TPCMT2:
1472+
return wacom_mt_touch(wacom);
14711473

1472-
case WACOM_REPORT_PENABLED:
1473-
return wacom_tpc_pen(wacom);
1474+
}
14741475
}
14751476
}
14761477

0 commit comments

Comments
 (0)