From patchwork Tue Apr 1 22:42:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 14035394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6B68C36010 for ; Tue, 1 Apr 2025 22:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=aA+KpehJIiM/yw2CsjlSoD6DX9cheZB+RV1vV7ZSPTM=; b=SaBBS8gaT1DJGW1wQDxjvnMlvY UFtOg+dhfls79PBE2nR4SH5RD7obcKYmCIQJaUMGbHmDnokxg00TGxwq9tjKXh84yKp1u1l++zdSV 9Qux01i3KFNohk81FLjCatnWHkE3ip82Yc2mTMwoadKkUyuzlypxyldX6br1tUxclPGGRkwzDeZAq 48iSQqbxOO8BW8zGCtOCP7sAuQtTEWAqjbUMMjw81EzJKMCCacDkOQ1T2JEKCrFQeG0xye/2bZlXg qQY3UCg0qQTcPdJMTcxOGuA+HMu43lGRQhkhkv+DDdSyRMs/Pis2HnMRqZoxZLA63ljZLVAxOXlXJ pHAt0qIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzkLl-00000004Ybe-0LLz; Tue, 01 Apr 2025 22:44:53 +0000 Received: from relay.smtp-ext.broadcom.com ([192.19.166.228]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzkK2-00000004YI1-00XH; Tue, 01 Apr 2025 22:43:07 +0000 Received: from mail-acc-it-01.broadcom.com (mail-acc-it-01.acc.broadcom.net [10.35.36.83]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id 4AFEAC000928; Tue, 1 Apr 2025 15:43:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 4AFEAC000928 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1743547382; bh=OXgiqBm85z4tWCR8EwZh57yh1Zl0z2cB7ncr9Tk25Ck=; h=From:To:Cc:Subject:Date:From; b=WAGbrPll6tu8Nrubq8NZTYHf6nlQe24BbQgsn3+SE01sXIHLq4UgXsQ4wNCSrJzEC C8r/95ORDBo6+P5wIg+0TZtjEaoA8fwLT+iJ3ZnlLT2+mGHILQ+IMYu4qDASy9kZpl Sv3XafIvtkJB61xlQrpaEqmMUOVQUPoWLXQzGG/E= Received: from stbirv-lnx-1.igp.broadcom.net (stbirv-lnx-1.igp.broadcom.net [10.67.48.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail-acc-it-01.broadcom.com (Postfix) with ESMTPSA id 1FEB44002F44; Tue, 1 Apr 2025 18:43:01 -0400 (EDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , Mark Brown , Ray Jui , Scott Branden , Broadcom internal kernel review list , Linus Walleij , Bartosz Golaszewski , linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE) Subject: [PATCH] spi: bcm2835: Do not call gpiod_put() on invalid descriptor Date: Tue, 1 Apr 2025 15:42:38 -0700 Message-Id: <20250401224238.2854256-1-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250401_154306_106849_BE062C39 X-CRM114-Status: GOOD ( 11.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If we are unable to lookup the chip-select GPIO, the error path will call bcm2835_spi_cleanup() which unconditionally calls gpiod_put() on the cs->gpio variable which we just determined was invalid. Fixes: 21f252cd29f0 ("spi: bcm2835: reduce the abuse of the GPIO API") Signed-off-by: Florian Fainelli Reviewed-by: Bartosz Golaszewski --- drivers/spi/spi-bcm2835.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index e1b9b1235787..a5d621b94d5e 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1162,7 +1162,8 @@ static void bcm2835_spi_cleanup(struct spi_device *spi) sizeof(u32), DMA_TO_DEVICE); - gpiod_put(bs->cs_gpio); + if (!IS_ERR(bs->cs_gpio)) + gpiod_put(bs->cs_gpio); spi_set_csgpiod(spi, 0, NULL); kfree(target);