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=1796034576; b=hVGe+wVS8IwKR3YUO/funDRiqDGBDNnB2uDqg59DMRQmcuuCmeT9N8qgoDcj94WLHXZn xnKsKGfGt8bQ/+JOqSdzsjBFbm0G23awurWgpfQv3JpgytCqXJs2vK11Nbap8m9NhCZJN 3F8FXr+lYICcFvOmJG1pcw1y+OO/+yEed7d960rJdcp35vU6Z9Hs7SJ3VBiyT2Sfm04F3 r5/sOV6aOV35SHrxrynw9Ox1bMyaKWIMBKrE9iAR10R1I3ZBv8YmoKWZaXFdoIbGmHUga ZW77fp0KapArXztFqQmw4+73IE9mdHNNPMRO5998mKCqcZ1zICuJwmCWVc0ncMNx6Kg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796034576; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=FbznmGeVJWkovzL65J072qi85uGqS3ZWW2/sxj77Zn8=; b=CfJFO0InQbeTaQo2VmCbzS1AQhAl59u1VT9ae6f6wyTw3zSb8jH+7KNM9I0fRdXPOtKt DIaDrVhkgtl/gffBDyO/6GvHiDMklRGRSrog57uMxklhfEhklbeVpGAL44QsRAPj7VhW2 IxCvcxzZcdxo0Wk5AXyFtd1OKf7Cez2ujtqo+ozvlGUj+SQJqj0NchWBhOQ8GBIa693iw R+B0sqz6L8SbgeGpqY1TRW3xfDz5SFZcF2ykhUfghTkhx/z+iiEPpRzeMVtGX5mm2brpN jO46lObDDgg9FALUGksZtZb/X4NoTgkpDVSv75CW+sYdJsJK0iLI7+lG2OOKbI7mMFA== 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=Lg4okTMm; 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 93463606A31C for ; Mon, 30 Nov 2026 10:29:36 +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=Lg4okTMm Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6F5B1F00897; Mon, 30 Nov 2026 10:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796034575; bh=FbznmGeVJWkovzL65J072qi85uGqS3ZWW2/sxj77Zn8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Lg4okTMmvymrUnLmtEw8JUmQ60EK+TC1MfM7YxVZvvzw2xaDBEXYSr9asNjqMxxdu idfIFPTHjCf/CXlNkBr/AmJi0BH818boRT7NFJV53uIVkq9d6q5euYONu+/Ek4/TMR /2jKVuQE3eVtFeM0SKL58AX4bYuK4dR5JTZpM14g5HXFowGzrI/6wPryVSWgX/b6JI roq3SiytKIIzzlY9UoetFIsAEWrkQrg3pGVre/eZ1o15Fp2qfb9HXyzaz+l4qT03qn hmbBhhKUBZguuBRd546pTcVjqJmcznOJkNjlrg8oXwYK3voFuCfv9KmaHN6/ZWKanp qaZjm2+boI8HQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] gpio: pca953x: Re-check level-triggered lines that stay active Reply-To: sashiko-reviews@lists.linux.dev To: "Alexey Charkov" Cc: linux-gpio@vger.kernel.org In-Reply-To: <20261130-pca953x-level-reenable-v1-1-a989d2505da4@flipper.net> References: <20261130-pca953x-level-reenable-v1-1-a989d2505da4@flipper.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 10:29:35 +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 2 potential issues to consider: - [High] gpio: pca953x: deadlock with disable_irq() on irq_wake_thread() - [Medium] gpio: pca953x: spurious recheck in pca953x_irq_set_type() when disabled -- commit 8dd2b0c1488595f3c519717f339414a171ce7d99 Author: Alexey Charkov gpio: pca953x: Re-check level-triggered lines that stay active This commit wakes the expander's IRQ thread to re-scan input registers after handling a level-triggered interrupt, enabling one, or switching an enabled interrupt to level triggering. > diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c > index 270cea8b4b492..e8ff948f392ca 100644 > --- a/drivers/gpio/gpio-pca953x.c > +++ b/drivers/gpio/gpio-pca953x.c [ ... ] > @@ -899,6 +913,15 @@ static void pca953x_irq_bus_sync_unlock(struct irq_d= ata *d) > pca953x_gpio_direction_input_unlocked(&chip->gpio_chip, level); > =20 > out: > + /* > + * The chip only interrupts on input changes, so a level-triggered line > + * that is already active when enabled would go unnoticed. > + */ > + if (chip->irq_level_recheck) { > + chip->irq_level_recheck =3D false; > + irq_wake_thread(chip->client->irq, chip); > + } > + > mutex_unlock(&chip->irq_lock); > } > =20 > @@ -919,6 +942,9 @@ static int pca953x_irq_set_type(struct irq_data *d, u= nsigned int type) > assign_bit(hwirq, chip->irq_trig_level_low, type & IRQ_TYPE_LEVEL_LOW); > assign_bit(hwirq, chip->irq_trig_level_high, type & IRQ_TYPE_LEVEL_HIGH= ); > =20 > + if ((type & IRQ_TYPE_LEVEL_MASK) && test_bit(hwirq, chip->irq_mask)) > + chip->irq_level_recheck =3D true; > + > return 0; > } [Severity: Medium] Does checking test_bit(hwirq, chip->irq_mask) here wake the IRQ thread even when the interrupt is disabled? Because pca953x_irq_chip does not implement .irq_disable, disable_irq() disables the line lazily without calling pca953x_irq_mask(), leaving hwirq set in chip->irq_mask. Calling irq_set_irq_type() on a lazily disabled line therefore sets chip->irq_level_recheck and triggers an I2C input scan (clearing the hardware interrupt condition on the expander and updating chip->irq_stat) while the consumer still has the interrupt disabled. Should this check !irqd_irq_disabled(d) instead? [ ... ] > @@ -1055,9 +1083,25 @@ static irqreturn_t pca953x_irq_handler(int irq, vo= id *devid) > =20 > handle_nested_irq(nested_irq); > ret =3D 1; > + > + /* > + * The chip interrupts again only once an input changes, > + * so a level still active after its handler, as when a > + * new event came in while the handler cleared the last > + * one, would go unnoticed: read the inputs again. Not > + * while the consumer keeps the interrupt disabled, which > + * would only spin, as enabling it re-checks anyway. > + */ > + if ((test_bit(level, chip->irq_trig_level_low) || > + test_bit(level, chip->irq_trig_level_high)) && > + !irqd_irq_disabled(irq_get_irq_data(nested_irq))) > + recheck =3D true; > } > } > =20 > + if (recheck) > + irq_wake_thread(chip->client->irq, chip); > + > return IRQ_RETVAL(ret); > } [Severity: High] Can calling irq_wake_thread(chip->client->irq, chip) deadlock with pca953x_save_context() during suspend? pca953x_save_context() holds chip->i2c_lock while calling disable_irq(chip->client->irq): drivers/gpio/gpio-pca953x.c:pca953x_save_context() { guard(mutex)(&chip->i2c_lock); /* Disable IRQ to prevent early triggering while regmap "cache only" is on= */ if (chip->client->irq > 0) disable_irq(chip->client->irq); regcache_cache_only(chip->regmap, true); } Neither irq_wake_thread() nor __irq_wake_thread() checks whether chip->client->irq has IRQD_IRQ_DISABLED set, so waking the parent IRQ thread increments desc->threads_active and schedules another run of pca953x_irq_handler(): CPU0 CPU1 (irq/client->irq) pca953x_irq_handler() pca953x_irq_pending() lock(&chip->i2c_lock) unlock(&chip->i2c_lock) pca953x_save_context() lock(&chip->i2c_lock) disable_irq(chip->client->irq) __disable_irq_nosync() synchronize_irq() /* waits for threads_active =3D=3D = 0 */ handle_nested_irq(nested_irq) irq_wake_thread(client->irq, chip) /* sets IRQTF_RUNTHREAD, increments threads_active */ pca953x_irq_handler() pca953x_irq_pending() lock(&chip->i2c_lock) <-- deadlock In addition, pca953x_irq_bus_sync_unlock() can call irq_wake_thread(chip->client->irq, chip) after pca953x_save_context() has disabled chip->client->irq and placed regmap into cache-only mode. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-pca953x-le= vel-reenable-v1-1-a989d2505da4@flipper.net?part=3D1