From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795291478; b=oxW8+HGYTKELy4fwa7tp7jdnUcUKYxN9NTn95E8LO4yQA9j3u97gJ12ejA0DdYJNoMsH StMgPhFTpOHz8v35KeAY9bGA014aBmYQGPPrtfa3FfBVe3bSf7GDCmgnb24BR9mhJzjZx otZsk1r+OCGSDVXga2Cknq5WXD78wYwAn7us5xCfIUeSrC9BwF8MtzOPO/wN9ScMdkCGE xZIkm8/5eK7DZl9JFyKH3XB55uRGfQOXOiIrnsi9qM2bdLBUYSqcUBtnhSih65OHGe2D1 WVd3TMCU7evGxzxkAQ8z6rf/ojJJd83M/+si5R2SsEUSKs7kJj2OWXhxIu/UZVzytTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795291478; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=7xHFK0KvszCXzELsirK7T2QT4xsTdhJttLSD3vRl4bo=; b=lMGj3JI5hWxJMqy2v0iEWBFYlopkjN2QtsHwD0HvQFegF3kB4QZpJ5esJTyMcVeSZ5Fq e3Y9yWq+/RgFauwTD/TgKHe30EqEKa/hfc8D3PugIu9SkOAYB48SkuZID+hoML75atSpv /pARY2rhxE2cdjt9ARQ9JDfmsuEDBgWF7q810JYUXx7BblSNRV/oPOHZk3LFeNFM1F3hJ W4rS+Zbt7OrY2xi1Ku5AQbFgFlJAUGJ1p7uIKdi/D6lFTbLMHl0ycXhgpW2vQvHwHGEbf L2l64+5nf4IvtO1fd3a0lLwy/dBkq/+e5k6LSD8uammprJEPcnntpLSOfWW+uL9XWTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FVmy5oVE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3C99606A320; Sat, 21 Nov 2026 20:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FVmy5oVE Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCB0D1F000C0; Sat, 21 Nov 2026 20:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795291477; bh=7xHFK0KvszCXzELsirK7T2QT4xsTdhJttLSD3vRl4bo=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=FVmy5oVEYIO5pxD4hUcrYHdZ5NCL/KnAOPm9JCNv23K4FDou+Vgbi1BxsBoBcjX// uSgdnwGluM+Br8vx6hM1WAUbKLUJGwybuadVpdfWEKa7M3TFsMfU0likUdGBMQM/X0 HpYWxfHbDjx4x9U7oxLxP1jxwCFmhMHXeuydrRuMzHJzx9czxjzeSbfbLvU4jHtYE7 69rekw9ZrRHwAqFos8mXLlsRl3QrWt/CWz6sOciMVFUVXzbTGL7ihZdLCLjdeam7sR wUm6FpK6aTtSraCZnFTxMZ95J1yDtcdrDcgCZP7wZlbeMvvS5qxxpxHEsysCvc4Z6S HSjpnIaCrQ+yQ== Date: Sat, 21 Nov 2026 20:04:30 +0000 From: Jonathan Cameron To: Srinivas Pandruvada Cc: Zheng Shuhao , Jiri Kosina , Benjamin Tissoires , Heiko Stuebner , Lee Jones , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ayaan Mirza Baig , syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com, Zhang Lixu Subject: Re: [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child iteration Message-ID: <20261121200430.311d4a4c@jic23-hlaptop> In-Reply-To: <20261121200230.6b1ccffd@jic23-hlaptop> References: <1795161418.hid-sensor-hub@viennaoffh.gmail.com> <20261120135005.566-1-viennaoffh@gmail.com> <573f3eb75601c17d6e766fc47a7cce1bc2274998.camel@linux.intel.com> <0165ee623890e4d3778390e46ad955956c512812.camel@linux.intel.com> <179519435494.24396.10633733692339086433@viennaoffh.gmail.com> <20261121200230.6b1ccffd@jic23-hlaptop> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, 21 Nov 2026 20:02:30 +0000 Jonathan Cameron wrote: > On Fri, 20 Nov 2026 09:56:41 -0800 > Srinivas Pandruvada wrote: >=20 > > On Sat, 2026-11-21 at 01:05 +0800, Zheng Shuhao wrote: =20 > > > =C2=A0> In reality this can't happen as the hid_hw_close() and =20 > > > hid_hw_stop() =20 > > > > is called before, so there can't be any raw_event. =20 > > >=20 > > > It might not be reachable after hid_hw_stop(). I may have > > > misunderstood the > > > lockdep report and overstated this as a possible deadlock. Sorry. > > > =20 > > > > How come this is possible? The HID sensor hub is only deleting its > > > > own > > > > children. Can you give an example here? =20 > > >=20 > > > With CONFIG_HID_BATTERY_STRENGTH=3Dy, this UHID device creates a Sens= or > > > Hub and > > > a Joystick battery. The HID input layer registers the battery power > > > supply as > > > a child of the HID device, without platform_data. > > >=20 > > > With the unpatched hid-sensor-hub module, UHID_DESTROY triggers a > > > KASAN > > > NULL-pointer dereference in sensor_hub_finalize_pending_fn(): > > >=20 > > > =C2=A0 KASAN: null-ptr-deref in range [0x0000000000000028- > > > 0x000000000000002f] > > > =C2=A0 RIP: sensor_hub_finalize_pending_fn+0x44/0x65 [hid_sensor_hub] > > > =C2=A0 Call trace: device_for_each_child -> sensor_hub_remove -> > > > hid_device_remove > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 -> hid_destroy_device -> uhid_dev_destroy -> > > > uhid_char_write > > > =20 > >=20 > > OK, Adding to commit description will help for others. =20 >=20 > Process thing. Zhang Lixu, please do not send a new version Sorry! That was for Zheng Shuhao. I realised a fraction of a second too late to hit the cancel button :( > in reply to an older one. I only spotted this today because > I was working for patchwork. Otherwise it would be way back > in my email history and probably lost. >=20 > New version, new email thread. Avoids breaking tools and > keeps things in order for those reviewing patches. > It seems the LLMs are following the suggested process for the > git project itself. As far as I aware no part of the kernel > has ever asked for this style of replying to an earlier commit > and many actively oppose it because it makes a massive mess > for large series. >=20 > Thanks, >=20 > Jonathan >=20 > >=20 > > Thanks, > > Srinivas > > =20 > > > The reproducer is below: > > >=20 > > > #define _GNU_SOURCE > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > >=20 > > > static const unsigned char sensor_battery_rdesc[] =3D { > > > 0x05, 0x20,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage Page (Senso= rs) */ > > > 0x09, 0x10,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage (Sensor Hub= ) */ > > > 0xa1, 0x01,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Collection (Appli= cation) */ > > > 0xc0,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 /* End Collection */ > > > 0x05, 0x01,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage Page (Gener= ic Desktop) */ > > > 0x09, 0x04,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage (Joystick) = */ > > > 0xa1, 0x01,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Collection (Appli= cation) */ > > > 0x05, 0x06,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage Page (Gener= ic Device Controls) */ > > > 0x09, 0x20,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Usage (Battery St= rength) */ > > > 0x15, 0x00,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Logical Minimum (= 0) */ > > > 0x25, 0x64,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Logical Maximum (= 100) */ > > > 0x75, 0x08,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Report Size (8) */ > > > 0x95, 0x01,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Report Count (1) = */ > > > 0x81, 0x02,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Input (Data, Vari= able, Absolute) */ > > > 0xc0,=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 /* End Collection */ > > > }; > > >=20 > > > static int send_event(int fd, struct uhid_event *event) > > > { > > > ssize_t written =3D write(fd, event, sizeof(*event)); > > >=20 > > > if (written =3D=3D sizeof(*event)) > > > return 0; > > > if (written < 0) > > > perror("write /dev/uhid"); > > > else > > > fprintf(stderr, "short UHID write: %zd\n", written); > > > return -1; > > > } > > >=20 > > > static bool hid_battery_exists(void) > > > { > > > static const char prefix[] =3D "hid-0003:1234:5678."; > > > DIR *dir =3D opendir("/sys/class/power_supply"); > > > struct dirent *entry; > > > bool found =3D false; > > >=20 > > > if (!dir) > > > return false; > > > while ((entry =3D readdir(dir))) { > > > if (!strncmp(entry->d_name, prefix, sizeof(prefix) - > > > 1)) { > > > found =3D true; > > > break; > > > } > > > } > > > closedir(dir); > > > return found; > > > } > > >=20 > > > int main(void) > > > { > > > struct uhid_event event =3D { 0 }; > > > struct pollfd pfd; > > > int fd, attempt; > > > bool started =3D false; > > > bool battery_found =3D false; > > >=20 > > > fd =3D open("/dev/uhid", O_RDWR | O_CLOEXEC); > > > if (fd < 0) { > > > perror("open /dev/uhid"); > > > return 1; > > > } > > >=20 > > > event.type =3D UHID_CREATE2; > > > strcpy((char *)event.u.create2.name, "sensor-hub-battery- > > > null-test"); > > > strcpy((char *)event.u.create2.phys, "hid-null-test"); > > > event.u.create2.rd_size =3D sizeof(sensor_battery_rdesc); > > > event.u.create2.bus =3D BUS_USB; > > > event.u.create2.vendor =3D 0x1234; > > > event.u.create2.product =3D 0x5678; > > > memcpy(event.u.create2.rd_data, sensor_battery_rdesc, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sizeof(sensor_battery_rdesc)); > > > if (send_event(fd, &event)) > > > goto out_close; > > >=20 > > > pfd.fd =3D fd; > > > pfd.events =3D POLLIN; > > > if (poll(&pfd, 1, 5000) <=3D 0) { > > > fprintf(stderr, "timed out waiting for > > > UHID_START\n"); > > > goto out_destroy; > > > } > > > memset(&event, 0, sizeof(event)); > > > if (read(fd, &event, sizeof(event)) !=3D sizeof(event)) { > > > perror("read UHID event"); > > > goto out_destroy; > > > } > > > started =3D event.type =3D=3D UHID_START; > > > if (!started) { > > > fprintf(stderr, "unexpected UHID event: %u\n", > > > event.type); > > > goto out_destroy; > > > } > > >=20 > > > for (attempt =3D 0; attempt < 50 && !hid_battery_exists(); > > > attempt++) > > > usleep(100000); > > > if (!hid_battery_exists()) { > > > fprintf(stderr, "HID battery power-supply child was > > > not created\n"); > > > goto out_destroy; > > > } > > > battery_found =3D true; > > > puts("HID battery power-supply child created"); > > >=20 > > > out_destroy: > > > memset(&event, 0, sizeof(event)); > > > event.type =3D UHID_DESTROY; > > > if (send_event(fd, &event)) > > > goto out_close; > > > usleep(300000); > > > if (!started) > > > goto out_close; > > > puts("UHID device destroyed without userspace error"); > > > close(fd); > > > return battery_found ? 0 : 1; > > >=20 > > > out_close: > > > close(fd); > > > return 1; > > > } =20 > > =20 >=20 >=20