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=1796490230; b=t3wKlXVs7lWotO+Tlo1X0q84VQWmzPfxT8VYr7+KrrrptwZSP3S4rFPtIB7lUDqyRU9K YpvNhSEeqkkRGS6gEbfudnMC2KcHYXamDJIWwu7VTNXmeeV2UwpfwIGwawLdVz7jK2kAL KshvVx+7Axo+eZNb0Prny/tNCaDeYrLS9JrL40KAt0j/EseNz3IK7CZ19SczgtnEc4Uzs Nqg2R7VO6NrjFN5twgFBHk1sUZdj2gkZ84b2eZwbMLSDtco9TRPgzibKp/bSgx4tU6FFb A0kTH0CybV+CDB10XEeJcuXHfXpQjJMnibRF1OeYMjlKZlCInHBw4nH7ZYg/uKeW5sQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796490230; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=uDBhtUhy2YAbII8eslQyp4yC6LktqG8pODDFSnBE9cA=; b=krIjZyfU2qXDq5cWMrN+0ziv8evaT/bNGRj7zgU/98RN00nV8jIGBOml5r2NqcMNFtTx Ez/HliWW/9RD68mIEGSCI5m86ThmdCtE7wiebWZferz6uYA5YEyLCHTLNLzjMbTXAzHbc w8tsVdjA14aF8HD3F6UqnsI3JX88RKDbDcUhg5yFCr1OPHJkP/tuTbgLxCawVgJRoA46Z 4mPEs3L7S9z5PtfeIM2+YrPz2G3ZFNKcrXbQLM0iqH0p7rLsqeYqtl090cIdnufrcqcG2 34quT6Zd6VHSmtsNknrhyBBt+lbqh3CLVLCYTodit4dfskBi8Jr/BaJwCYo28Vdr0CA== 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=Y2qMSrML; 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 07B33606A31F for ; Sat, 5 Dec 2026 17:03:49 +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=Y2qMSrML Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE4F41F0092B; Sat, 5 Dec 2026 17:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796490229; bh=uDBhtUhy2YAbII8eslQyp4yC6LktqG8pODDFSnBE9cA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Y2qMSrMLUvjmZSP7z19P5FC0z5WDw6WQ6JXDxcCxxqVjtcnqXNmNi6Q1W05fMp1GD TRVr0LgqL9xsXwYQdxQXbWW5y051MoSBLP2rmBd0F5O3WE2z0VFqmCRX4bovVqox/R jQSjmga3ZRuH6issEyKc4lAI4tzZiZ/z/FQ6sBH0NYG+t2ZQlxOQWqmzmvXcAV7QxS LPfiMNLSOW2D/j5twc63ikhsRD7dftSsx3yom8sUCqWZ7zA378RBBk7pqyVkM2+jpM s8jeVFxCbIIUhA/bhzG5groPPu+g5YndWK8/7KlIgQ6em9IZnnvNdw0S/wtsmw1j0W BSLIFgmS3teXQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] gpio: viperboard: implement .get_direction() Reply-To: sashiko-reviews@lists.linux.dev To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: linux-gpio@vger.kernel.org In-Reply-To: <20261205165253.4264-1-25031212351@stu.xidian.edu.cn> References: <20261205165253.4264-1-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 17:03:49 +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 3 potential issues to consider: - [Medium] gpio: viperboard: single-driver workaround leaves gpiolib WARN_ON unfixed - [Medium] gpio: viperboard: stale direction after USB error corrupts GPIOD_FLAG_IS_OUT - [Medium] gpio: viperboard: unlocked get_direction() reads race with direction updates -- commit 35f11d2ebc7aa7c44e719194cb0daba3cd5528a2 Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> gpio: viperboard: implement .get_direction() This commit adds .get_direction() callbacks for both the gpioa and gpiob chips in the viperboard GPIO driver using the cached gpioa_out and gpiob_out bitmaps. > diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboar= d.c > index 89087fd48a819..1b83ab0d66af0 100644 > --- a/drivers/gpio/gpio-viperboard.c > +++ b/drivers/gpio/gpio-viperboard.c > @@ -252,6 +252,15 @@ static int vprbrd_gpioa_direction_output(struct gpio= _chip *chip, > return 0; > } > =20 > +static int vprbrd_gpioa_get_direction(struct gpio_chip *chip, > + unsigned int offset) > +{ > + struct vprbrd_gpio *gpio =3D gpiochip_get_data(chip); > + > + return (gpio->gpioa_out & (1 << offset)) ? GPIO_LINE_DIRECTION_OUT : > + GPIO_LINE_DIRECTION_IN; > +} > + > /* ----- end of gpio a chip --------------------------------------------= -- */ [Severity: Medium] Can vprbrd_gpioa_get_direction() report a stale direction after a USB transfer error and corrupt GPIOD_FLAG_IS_OUT in gpiolib? vprbrd_gpioa_direction_input() and vprbrd_gpioa_direction_output() update gpio->gpioa_out before usb_control_msg() and leave the bit changed if the transfer fails with -EREMOTEIO. The same applies to gpio->gpiob_out in vprbrd_gpiob_direction_input() and vprbrd_gpiob_direction_output() before vprbrd_gpiob_setdir(). With .get_direction() exposing these bitmaps, a later gpiod_get_direction() call copies the failed direction into desc->flags, desynchronizing gpiolib from the hardware. Updating gpioa_out and gpiob_out only after the USB direction command succeeds would avoid this. [Severity: Medium] Can vprbrd_gpioa_get_direction() race with concurrent direction updates on gpio->gpioa_out? gpiolib only holds a shared SRCU read lock across chip callbacks, while vprbrd_gpioa_direction_input() and vprbrd_gpioa_direction_output() modify gpio->gpioa_out outside vb->lock (and vprbrd_gpiob_get_direction() has the same unlocked read on gpio->gpiob_out): CPU0 CPU1 vprbrd_gpioa_direction_output() gpio->gpioa_out |=3D (1 << off); vprbrd_gpioa_get_direction() gpio->gpioa_out & (1 << off) <-- data race / uncommitted state mutex_lock(&vb->lock) usb_control_msg(...) This causes a data race and lets gpiod_get_direction() propagate an uncommitted direction into desc->flags before the USB transfer completes. Since both chips set can_sleep =3D true, serializing gpioa_out and gpiob_out accesses under vb->lock alongside the USB transfers would prevent this. [ ... ] > @@ -412,6 +430,7 @@ static int vprbrd_gpio_probe(struct platform_device *= pdev) > vb_gpio->gpioa.get =3D vprbrd_gpioa_get; > vb_gpio->gpioa.direction_input =3D vprbrd_gpioa_direction_input; > vb_gpio->gpioa.direction_output =3D vprbrd_gpioa_direction_output; > + vb_gpio->gpioa.get_direction =3D vprbrd_gpioa_get_direction; > =20 > ret =3D devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpioa, vb_gpio); > if (ret < 0) > @@ -428,6 +447,7 @@ static int vprbrd_gpio_probe(struct platform_device *= pdev) > vb_gpio->gpiob.get =3D vprbrd_gpiob_get; > vb_gpio->gpiob.direction_input =3D vprbrd_gpiob_direction_input; > vb_gpio->gpiob.direction_output =3D vprbrd_gpiob_direction_output; > + vb_gpio->gpiob.get_direction =3D vprbrd_gpiob_get_direction; > =20 > return devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpiob, vb_gpio); > } [Severity: Medium] Should the WARN_ON(!gc->get_direction) regression be fixed in gpiolib instead of working around it in gpio-viperboard alone? Commit 471e998c0e31 ("gpiolib: remove redundant callback check") removed the !guard.gc->get_direction check in gpiod_get_direction() before calling gpiochip_get_direction(), exposing its WARN_ON(!gc->get_direction) to normal callers such as sysfs direction_show(). Because get_direction is optional, every other GPIO driver without it (for example gpio-da9052 and gpio-vx855) still hits the warning. Returning -EOPNOTSUPP without WARN_ON in gpiochip_get_direction() fixes the core bug, leaving this patch standalone without the Fixes: or Cc: stable trailers. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205165253.4264= -1-25031212351@stu.xidian.edu.cn?part=3D1