Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4202077pxu; Mon, 12 Oct 2020 12:07:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjCG7/yKYn/F/eVSDYB/U+F1x8f1+TlRPok4/g7NiSJlEK8wNxnO1G/8HvrQIXKF1dwMi5 X-Received: by 2002:a17:906:7fd8:: with SMTP id r24mr28910210ejs.553.1602529649280; Mon, 12 Oct 2020 12:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602529649; cv=none; d=google.com; s=arc-20160816; b=JsY1qJCsh6r21YryNtwoAKG+XCOJ/LTnhXTWwYy2LRP80eZ8A0XhDOfUtuE0/7jJVE 6dtXryaD5TGYAgaRUBXo562fk3CJG3HKLEdBbcrJh6zOUO60nwf3APaFjkmnLoi+Ejdt hhb8qzdmW2bRijPgUkeNPU541z5dECfVh+3Yv0bm1Z0eROvTQHHOtry3g7leVg2ZMxmZ JRfk06bTAROR6Z4YwdkeRMFBEL1Q2DXK7pJ3o8bP5G6LFYB0Tb4nnc1gO8nzo51byjjM heJJa4V2glyh6Anu7Fu2pFVcvao/l9/6K4K9quONv0oTmCR3baDWzu7InXuIRUD9oIdf SSoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pwddcJI1U/Wh4Q19Nd96lNM0O63jBXyzZKq74LcWTZU=; b=mKg+xxHF79jGmgA+9R9gpBM+YgfJiMLVjslv55DLPgifqO4BDB0WmAECYzM9XLNaUK PW0rmBfpOvadLkmtIel9Y5HEHehe0UT3PoOMhTE+rxbU6s884UBVV9VdBwQ699MaiK5j gi7mHYiebUsfpAvSy09ByUg16Pde3OdvHgUHcLauI82WXPn9nZtpHoaMrbKQ1WdkDNTO PqWFcWiHY24D7tN2ARGhfsck+3aNUoYp4tPHIXUjJWlBa3Tkfox4TCOLTppxnGQQLrbn s0kor1Saa6chspfFHvrNhfPHJWphqFGwI/ufYRkNqZlS5tD2CGH1192uAXMkmgLZgrph b/fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fkMuuLDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si11990305eju.267.2020.10.12.12.07.00; Mon, 12 Oct 2020 12:07:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fkMuuLDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390911AbgJLTD3 (ORCPT + 99 others); Mon, 12 Oct 2020 15:03:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:52586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390144AbgJLTDK (ORCPT ); Mon, 12 Oct 2020 15:03:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE94421BE5; Mon, 12 Oct 2020 19:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602529389; bh=GxyUJ336LKwVyiU9N8vXJbaW07K1JUB7kHNAeeWC/Ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fkMuuLDwZ9RTuK4sRq/SVAfPIhq4Mthc6s5UQy4GtJ+CMnfrYzmcbQ+TrzwY/+ZYA tcaJrkSgbl56sR3QFuykZrlMa4RISaPB0f+p00XCM+O7VSYYAvob+ID3gOXITBLOop QSSTE3Ia48yAm6GWQZ9uaQdnM5JcPmSlUPuYewbA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marc Zyngier , Linus Walleij , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 5.8 23/24] gpio: pca953x: Survive spurious interrupts Date: Mon, 12 Oct 2020 15:02:38 -0400 Message-Id: <20201012190239.3279198-23-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012190239.3279198-1-sashal@kernel.org> References: <20201012190239.3279198-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit 8b81edd80baf12d64420daff1759380aa9a14998 ] The pca953x driver never checks the result of irq_find_mapping(), which returns 0 when no mapping is found. When a spurious interrupt is delivered (which can happen under obscure circumstances), the kernel explodes as it still tries to handle the error code as a real interrupt. Handle this particular case and warn on spurious interrupts. Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20201005140217.1390851-1-maz@kernel.org Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/gpio/gpio-pca953x.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 11c3bbd105f11..1de182b85e4c4 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -821,8 +821,21 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid) ret = pca953x_irq_pending(chip, pending); mutex_unlock(&chip->i2c_lock); - for_each_set_bit(level, pending, gc->ngpio) - handle_nested_irq(irq_find_mapping(gc->irq.domain, level)); + if (ret) { + ret = 0; + + for_each_set_bit(level, pending, gc->ngpio) { + int nested_irq = irq_find_mapping(gc->irq.domain, level); + + if (unlikely(nested_irq <= 0)) { + dev_warn_ratelimited(gc->parent, "unmapped interrupt %d\n", level); + continue; + } + + handle_nested_irq(nested_irq); + ret = 1; + } + } return IRQ_RETVAL(ret); } -- 2.25.1