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=1796489920; b=fCSPjGuMcSvF5ckAcWYlr+okXdywPQzRzCOSFzDUL8p0ipOvS+cXz2kl6VTnw4tpmeqh uTRTeGOp8FmrP4FKP3aiT1UXvPblWf6nxI2KMJJlxAMAvgn09VM58BAKyibBehJkm4SCA ANzDC3ISlRffo7goB64tiaTvU9pmzo6Bmhtqe/SnwSWnybbMLevSGJ24xjbqMptg9kYHF KUPxAAX5SAS1WcdpvCr26AvpkQ/0kFv4VC1frvTUrG9dWXVMIXTc77hw2JAxihr9UADc1 P0B1qWurzt6HUtGdXnKKlWTCONADrOhcicLm1AtWoRvI27Zq3u6+tm2aDw2sbRsew4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796489920; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+rElb67USr82vNqxcqw7sfhArm0NAcq5+4AwSBRZyLs=; b=DOmBkpjOeGRu3L6DzWZLiqp9ipzVvCCwiUFexLRewP0544Y9vS2nvoxs4Wu1zzXjbYOk TanW2BGUhlwWEwrBboif5BPVBfSt3O9UCBydsVERfLMy4+8ZdalgoXIAmDmWBPLx87FW3 s2x9xm1d5eUlSqOObjJhP2frFeuhNM2KMhVcfamAAG3JneEA3XkAa25WzkDZub8qypMmv GgaZ5JTj+mEsZruovS16F95W0R3W7vLhxhg7eFOi4Rfdh2ME9MJGPKXuqbloRSBntGb0G jn1RkqJG1mVlF1Jvb+MnIxA+wfYkHibpT7nrcq/6jk/jhruUeKFvieTiQLbTpKMLz1w== 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=OuyQzBgB; 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 16449606A31F for ; Sat, 5 Dec 2026 16:58:39 +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=OuyQzBgB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83E9B1F0092B; Sat, 5 Dec 2026 16:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796489919; bh=+rElb67USr82vNqxcqw7sfhArm0NAcq5+4AwSBRZyLs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OuyQzBgBE8lyBq4ZJxaeqimrbEvKgDsAkt8Pri6qpDVymOAx7DTxKpvZZfzDbAzGv sNvBmbjTnIzmTV63UdnxfGmet4RKjhRGc0JydipgIBNyDIhaeYqR5u8qTGP5GKYFiw rMBCePHhwugucaCjKrPFC7zGBYIlqIumldKVD28oJVs9jGTOWCT5Xf832vSgO1Yxbz QC2pQB4C20CVpr9mynS4767TBp1bVz2p00Z9WZjbViAluSo8W8v9vYKwR8wT7wVaCV nbkc4SISlPlpORq/lcJLaMGD7NxoOSez2SVDoaqBZhXCE2y5H+uVnWsb4dcbnJy5Us Vj+XtTEqo5gpQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] gpio: mpsse: return -ENODEV when the USB interface is gone Reply-To: sashiko-reviews@lists.linux.dev To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: linux-gpio@vger.kernel.org In-Reply-To: <20261205164613.3860-1-25031212351@stu.xidian.edu.cn> References: <20261205164613.3860-1-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:58:39 +0000 X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] gpio: mpsse: unsynchronized disconnect checks leave TOCTOU and post-disconnect I/O -- commit f254763b85bf36f0d8bf91ec142bc3d8a202bced Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> gpio: mpsse: return -ENODEV when the USB interface is gone This commit adds NULL checks for the USB interface and its driver data in mpsse_bulk_xfer() and mpsse_read() so they return -ENODEV instead of dereferencing a cleared interface pointer after disconnect. > diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c > index 61c5ca96314b7..ae1a976452143 100644 > --- a/drivers/gpio/gpio-mpsse.c > +++ b/drivers/gpio/gpio-mpsse.c > @@ -105,11 +105,20 @@ static DEFINE_IDA(gpio_mpsse_ida); > =20 > static int mpsse_bulk_xfer(struct usb_interface *intf, struct bulk_desc = *desc) > { > - struct mpsse_priv *priv =3D usb_get_intfdata(intf); > - struct usb_device *udev =3D priv->udev; > + struct mpsse_priv *priv; > + struct usb_device *udev; > unsigned int pipe; > int ret; > =20 > + if (!intf) > + return -ENODEV; > + > + priv =3D usb_get_intfdata(intf); > + if (!priv) > + return -ENODEV; > + > + udev =3D priv->udev; > + > if (desc->tx) > pipe =3D usb_sndbulkpipe(udev, priv->bulk_out->bEndpointAddress); > else > @@ -144,7 +153,14 @@ static int mpsse_read(struct usb_interface *intf, u8= *buf, size_t len) > { > int ret; > struct bulk_desc desc; > - struct mpsse_priv *priv =3D usb_get_intfdata(intf); > + struct mpsse_priv *priv; > + > + if (!intf) > + return -ENODEV; > + > + priv =3D usb_get_intfdata(intf); > + if (!priv) > + return -ENODEV; > =20 > desc.len_actual =3D 0; > desc.tx =3D false; [Severity: High] Can these checks in mpsse_bulk_xfer() and mpsse_read() still race with gpio_mpsse_disconnect() and allow usb_bulk_msg() to run after disconnect returns? CPU0 CPU1 gpio_mpsse_set_bank() ... mpsse_bulk_xfer(priv->intf, ...) if (!intf) /* non-NULL */ priv =3D usb_get_intfdata(intf) if (!priv) /* non-NULL */ usb_unbind_interface() gpio_mpsse_disconnect() priv->intf =3D NULL; usb_set_intfdata(intf, NULL); usb_enable_interface(..., false) usb_bulk_msg(udev, ...) <-- I/O on unbound interface gpio_mpsse_disconnect() clears priv->intf and calls usb_set_intfdata(intf, NULL) without holding priv->io_mutex, even though the GPIO callbacks hold priv->io_mutex while reading priv->intf. In addition, gpio_mpsse_probe() uses devm_gpiochip_add_data(), so gpiochip_remove() and its synchronize_srcu() barrier only run later in device_unbind_cleanup() -> devres_release_all(), after usb_unbind_interface() has already returned. This violates the usb_bulk_msg() contract that disconnect() wait for in-flight transfers to complete. On driver unbind or module unload while the device stays attached, a racing thread can submit a bulk transfer to an unbound interface while stalling gpiochip_remove() under device_lock. Because priv->intf is accessed without locks or READ_ONCE()/WRITE_ONCE(), inlining these static helpers can also reload priv->intf between the NULL check and usb_get_intfdata(intf), leaving a NULL pointer dereference. Callbacks that skip USB I/O, such as gpio_mpsse_get_direction(), also continue to succeed after disconnect instead of returning -ENODEV. Registering the chip with gpiochip_add_data() (with priv->gpio.parent set to dev) and calling gpiochip_remove(&priv->gpio) synchronously in gpio_mpsse_disconnect() before clearing priv->intf and intfdata would drain in-flight callbacks and transfers before disconnect returns. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205164613.3860= -1-25031212351@stu.xidian.edu.cn?part=3D1