Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3713985pxv; Mon, 26 Jul 2021 10:03:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/JiNGxPt2O1NKbmSK+5PFiqF0BkElNztkrsQhUR1l+DA1jmDvEwAA5fiTfvMIuFj319RA X-Received: by 2002:a67:7fc4:: with SMTP id a187mr13620750vsd.59.1627319013173; Mon, 26 Jul 2021 10:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319013; cv=none; d=google.com; s=arc-20160816; b=aVljJrtZl/kdSOL54QS+u8ozLAUkKldF3vaOveUjHVmjNz8TzC8rrWF69zEo8QhMAI 0rnLl121RNSrCInBYfc/CiUPdEmeWBw+4YlxLxV78qsx3jROanXzWO0pNOaYTwnJT4b2 baJjRW+yQBe87EMnwcU0XSWMCYtgBihV3YU+21sRef9+aV1CPKIwl8pgHigx+CBPD3kU 5VCWdRg4uQoC5vjWdFWSY4tpFSCQsL2/Bs6bMj3PXywsATtTFTBypdbM5ccpjuR7kOiE g9v563C0n2v4mzc5iPS59zwvoNGJYRuKzENopfTN8x3xLT7F5GQ1swGItxdEm3GRydZ+ f5Jg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ija1ErUW/gGSNjxAoFRgtYxIadnImnw+05ry/JWkwzw=; b=NZ8p92OUKD766GfXG7GVz5sbMDea0lYRCXJELOI0EnS8PdJeuL2sOynlv62n2josOs l6CuP0+oodHKNJcSG1Z/KzXunU0g+Rm47NF8pHCFmCFqtR8Jk29Tx6j6LF31/UPdCwGP yZXnQBbDXipfP/SZciv4t8u1MV/mR3Wu4BznCPT+A19TGE78WQQhDj2HCGF1R1R/WqWW 9KpFgj4n5AXXFmE23vdCsndanWLTEL/nPUE62EirhAZL9Cbn4bQEZsr76g7NeV8RpP9i 4uxVWt0HLO8l0bTszUs2DeUK9tndRz+yCueCj/GnEcRGSmF2HQXj5q+YerVd6sgQ1f9P FUNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BNpH1Cne; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si308118vsh.416.2021.07.26.10.02.57; Mon, 26 Jul 2021 10:03:33 -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=@linuxfoundation.org header.s=korg header.b=BNpH1Cne; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238160AbhGZPkp (ORCPT + 99 others); Mon, 26 Jul 2021 11:40:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:38198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237467AbhGZPXL (ORCPT ); Mon, 26 Jul 2021 11:23:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB7FF60EB2; Mon, 26 Jul 2021 16:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315420; bh=1o2MyKCtsRusEYEXJMA1hrjflzIlkJ3fM5R5DHhhJZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNpH1Cne+JyTQUMmaaf4yxD1SQEXpd319siI1WtEPuZk7pNwBin9UGRdxiBYn4AfU TTDVKlQhrdGZexPrc8mPE/tbMhWpBqvAC8KZR3T0MfZbqeYvivuD0qYrXDwtCuruiz FUdwyYDgKWWWzjBGb9jV2EynBJYt0vw0NC7GaAuE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandru Tachici , Florian Fainelli , Mark Brown , Sasha Levin Subject: [PATCH 5.10 089/167] spi: spi-bcm2835: Fix deadlock Date: Mon, 26 Jul 2021 17:38:42 +0200 Message-Id: <20210726153842.388132310@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandru Tachici [ Upstream commit c45c1e82bba130db4f19d9dbc1deefcf4ea994ed ] The bcm2835_spi_transfer_one function can create a deadlock if it is called while another thread already has the CCF lock. Signed-off-by: Alexandru Tachici Fixes: f8043872e796 ("spi: add driver for BCM2835") Reviewed-by: Florian Fainelli Link: https://lore.kernel.org/r/20210716210245.13240-2-alexandru.tachici@analog.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-bcm2835.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 29ee555a42f9..33c32e931767 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -84,6 +84,7 @@ MODULE_PARM_DESC(polling_limit_us, * struct bcm2835_spi - BCM2835 SPI controller * @regs: base address of register map * @clk: core clock, divided to calculate serial clock + * @clk_hz: core clock cached speed * @irq: interrupt, signals TX FIFO empty or RX FIFO ¾ full * @tfr: SPI transfer currently processed * @ctlr: SPI controller reverse lookup @@ -124,6 +125,7 @@ MODULE_PARM_DESC(polling_limit_us, struct bcm2835_spi { void __iomem *regs; struct clk *clk; + unsigned long clk_hz; int irq; struct spi_transfer *tfr; struct spi_controller *ctlr; @@ -1082,19 +1084,18 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, struct spi_transfer *tfr) { struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); - unsigned long spi_hz, clk_hz, cdiv; + unsigned long spi_hz, cdiv; unsigned long hz_per_byte, byte_limit; u32 cs = bs->prepare_cs[spi->chip_select]; /* set clock */ spi_hz = tfr->speed_hz; - clk_hz = clk_get_rate(bs->clk); - if (spi_hz >= clk_hz / 2) { + if (spi_hz >= bs->clk_hz / 2) { cdiv = 2; /* clk_hz/2 is the fastest we can go */ } else if (spi_hz) { /* CDIV must be a multiple of two */ - cdiv = DIV_ROUND_UP(clk_hz, spi_hz); + cdiv = DIV_ROUND_UP(bs->clk_hz, spi_hz); cdiv += (cdiv % 2); if (cdiv >= 65536) @@ -1102,7 +1103,7 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, } else { cdiv = 0; /* 0 is the slowest we can go */ } - tfr->effective_speed_hz = cdiv ? (clk_hz / cdiv) : (clk_hz / 65536); + tfr->effective_speed_hz = cdiv ? (bs->clk_hz / cdiv) : (bs->clk_hz / 65536); bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv); /* handle all the 3-wire mode */ @@ -1318,6 +1319,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) return bs->irq ? bs->irq : -ENODEV; clk_prepare_enable(bs->clk); + bs->clk_hz = clk_get_rate(bs->clk); err = bcm2835_dma_init(ctlr, &pdev->dev, bs); if (err) -- 2.30.2