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=1796215893; b=EW0ZjxHwyHjX8YhE5ThS3J61pIi/FGETx6jT9YB0ottoMly1h7VZVNgYUT8DmSb957ir qK1GeR0Fddwh67SM2JSBg6EVFWUKYyvRHvBFiPvQWvpAVDciEuq/FXyjf3xGphSk5m9in hwhDe8F0fIMpwgM5ZI/QoiE2QmyKhY7ic8vCUoa91AMEwfbXtmVcuuJUrUqajKKFUrhUA 5bWtXhTJTePnr5UmWSFztu8rxcy9y4GWrz1vZxZ0cpfo6JjHIbJzJm4DuSKyBi649Xgvy Dp6bYJ+D2PcQEttWGoLyQpv1BvtE5i066M65TR7AkYK4E06qCvCnXL5CFBQjjrwI/KQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796215893; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+B7RCAif7PvIRxAoCuskiiSKd4/XcZxfTLOg+kA7D7g=; b=oKx6QvKlsA2Toiv+vrfpSGIBWp8HOiSwqAwejmFnrxJhA/vnZ8N86kcoKR5evXGvhE9k VaszHej8Nom5iAKqEpavMT0wgTGK9fmjI+E+BBxba8WNkYJ9FNjuEQNwtfv13SR53Fu2Z pnlDtZA/o0EfLsxs2xk2T61BFHTvjfH8U1wFP2CDhFi+XWcm64Y3AZ+7vIK6fnYIVgzEe frdY3OYfy5vKkbgay1h1oZ/TZt9hhvXJ8k5fdXMkjJIjZoYrxpjmsARQhwICKLoQu1Xh2 X8KczXfkxyUBKKkMYJIPlmK3vMwt7ksGPxNR46UksevgzseF2CmoW6nyK315yi/kriQ== 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=Iha55Nbd; 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 6C951606A31A for ; Wed, 2 Dec 2026 12:51:33 +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=Iha55Nbd Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF3C51F00896; Wed, 2 Dec 2026 12:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796215892; bh=+B7RCAif7PvIRxAoCuskiiSKd4/XcZxfTLOg+kA7D7g=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Iha55NbdnfE0N0UklffOVjC4aCJsh9vu3N0g1d00BrP+ejRSaubjfo15K3Wx+qNx2 VococanspWYm+51jUX7VW2y2EBbmnkt8PS5gBtL1zt01LlMqZ71lU+A+TuhSEFKRAD AuJiOBasY4O2jnUqMPbtWBIQlAWnFqCsVeoPY2RDFIByeZFIWNzZMZhC/qy6W/BHT9 A37rHhBrDYpzLVND8H+ElHON9hKsC2cgL6l85nVcV+KEae89frLB7k7Vz5EUwcUf9w 8nWbFOWfX4GdBjE9+RqScjDfTAfoqzQnpK5gmfESevH6P4UwnGybGb4hYSSflzZSi0 WmKgkruD7Gmbg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND] i2c: i2c-gpio: Enhance driver for buses with shared SDA Reply-To: sashiko-reviews@lists.linux.dev To: "Anatoliy Oleinikov" Cc: linux-gpio@vger.kernel.org In-Reply-To: <20261202-i2c-gpio-shared-sda-v1-1-8b411d498d14@wizle.tech> References: <20261202-i2c-gpio-shared-sda-v1-1-8b411d498d14@wizle.tech> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 12:51:32 +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: - [Medium] i2c: gpio: race in i2c_gpio_cleanup_line() unlocking before gpiod_put() -- commit dfec81ba8dfe460cb6648555affaacf28b81ef65 Author: Anatoliy Oleinikov i2c: i2c-gpio: Enhance driver for buses with shared SDA This commit generalizes the shared SCL line tracking and locking in i2c-gpio to also support sharing the SDA line across multiple I2C adapters. > diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c > index 56d6847cbf6d7..40d7d0178af86 100644 > --- a/drivers/i2c/busses/i2c-gpio.c > +++ b/drivers/i2c/busses/i2c-gpio.c [ ... ] > @@ -455,66 +480,76 @@ static bool i2c_gpio_scl_matches(struct i2c_gpio_sc= l_data *a, struct i2c_gpio_sc [ ... ] > -static void i2c_gpio_cleanup_scl(struct i2c_gpio_scl_data *scl) > +static void i2c_gpio_cleanup_line(struct i2c_gpio_line_data *line) > { > - if (!refcount_dec_and_mutex_lock(&scl->ref, &i2c_gpio_scl_list_lock)) > + if (!refcount_dec_and_mutex_lock(&line->ref, &i2c_gpio_line_list_lock)) > return; > =20 > - list_del(&scl->list); > - mutex_unlock(&i2c_gpio_scl_list_lock); > - gpiod_put(scl->gpio); > - i2c_gpio_free_scl(scl); > + list_del(&line->list); > + mutex_unlock(&i2c_gpio_line_list_lock); > + gpiod_put(line->gpio); > + i2c_gpio_free_line(line); > } [Severity: Medium] Can a concurrent i2c_gpio_lookup_line() fail with -EBUSY if it runs between mutex_unlock(&i2c_gpio_line_list_lock) and gpiod_put(line->gpio)? With both SDA and SCL now going through i2c_gpio_lookup_line(), a probe that succeeds on SDA and hits -EPROBE_DEFER on SCL unwinds via err_cleanup_sda -> i2c_gpio_cleanup_line(priv->sda). If another adapter sharing that SDA pin probes at the same time, the following interleaving can occur: CPU0 CPU1 i2c_gpio_probe() [adapter A] i2c_gpio_probe() [adapter B] priv->sda =3D i2c_gpio_lookup_line() priv->scl =3D i2c_gpio_lookup_line() -> -EPROBE_DEFER i2c_gpio_cleanup_line(priv->sda) refcount_dec_and_mutex_lock() list_del(&line->list) mutex_unlock(&i2c_gpio_line_list_lock) i2c_gpio_lookup_line("sda", ...) lock(&i2c_gpio_line_list_lock) // misses entry, adds new_line unlock(&i2c_gpio_line_list_lock) i2c_gpio_get_desc() gpiod_get() -> -EBUSY gpiod_put(line->gpio) Because the GPIO descriptor still has FLAG_REQUESTED set until gpiod_put() finishes, adapter B fails permanently with -EBUSY instead of deferring probe. Calling gpiod_put(line->gpio) before removing the entry and unlocking i2c_gpio_line_list_lock (or clearing line->gpio under the lock before dropping it for gpiod_put()) would avoid this race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-i2c-gpio-s= hared-sda-v1-1-8b411d498d14@wizle.tech?part=3D1