From 6c201dd2c0e101892edfa50b06c9c695f454a752 Mon Sep 17 00:00:00 2001 From: anton Date: Sun, 14 Feb 2021 14:40:39 +0000 Subject: Bail out earlier during attach if no devices are paired with the receiver. --- sys/dev/usb/uhidpp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'sys') diff --git a/sys/dev/usb/uhidpp.c b/sys/dev/usb/uhidpp.c index f1f0dcc38dd..12bf3da7035 100644 --- a/sys/dev/usb/uhidpp.c +++ b/sys/dev/usb/uhidpp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhidpp.c,v 1.8 2021/02/14 14:39:25 anton Exp $ */ +/* $OpenBSD: uhidpp.c,v 1.9 2021/02/14 14:40:38 anton Exp $ */ /* * Copyright (c) 2021 Anton Lindqvist @@ -387,20 +387,22 @@ uhidpp_attach(struct device *parent, struct device *self, void *aux) serial[0], serial[1], serial[2], serial[3]); npaired++; } + if (npaired == 0) + goto out; /* Enable notifications for the receiver. */ error = hidpp10_enable_notifications(sc, HIDPP_DEVICE_ID_RECEIVER); if (error) printf(" error %d", error); - printf("\n"); - strlcpy(sc->sc_sensdev.xname, sc->sc_hdev.sc_dev.dv_xname, sizeof(sc->sc_sensdev.xname)); sensordev_install(&sc->sc_sensdev); sc->sc_senstsk = sensor_task_register(sc, uhidpp_refresh, 6); +out: mtx_leave(&sc->sc_mtx); + printf("\n"); } int @@ -416,7 +418,8 @@ uhidpp_detach(struct device *self, int flags) KASSERT(sc->sc_resp_state == UHIDPP_RESP_NONE); - sensordev_deinstall(&sc->sc_sensdev); + if (sc->sc_sensdev.xname[0] != '\0') + sensordev_deinstall(&sc->sc_sensdev); for (i = 0; i < UHIDPP_NDEVICES; i++) { struct uhidpp_device *dev = &sc->sc_devices[i]; -- cgit v1.2.3