Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2747876pxj; Mon, 31 May 2021 09:44:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKayBY6uiTRyAl9aJ4TKWJLUsw1yC+SmArX2rjekq1FOd5vFyHt6M0hYhktEXmyEGIdt4f X-Received: by 2002:a17:906:2bc5:: with SMTP id n5mr23951897ejg.531.1622479441114; Mon, 31 May 2021 09:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479441; cv=none; d=google.com; s=arc-20160816; b=bOB8PL2n9goFAHKO+qlmT9Rto1Ok6VrlgpTcEsAzOafVzDmGrnpfovsjUfoVsJHTSz qYXtDsANZ2gM1jK6bx64DoYhNgUfUd2CBTCtbCOXY87TfsV4o2GO+/XYGLTOVzDDQXS7 0UO3ILG2ufTsVSmgvq2zUo4OhIYaRzO/Lr4SJaDyFRO/LgBCUQLkIyPMx80PsoaBBvGb CPUsyyr2zg2UvaMTU1yF2qjX70/iaDvA+s6T0Cq5QYIASlOY3BQnOpJPoWft7TdrCTPv aVpBYjOMvcyJOlGoCrp9n2bfuuReyNWHvqAkl7CdoR/7yjP7Ll9xNQjikmSV7peyYHby KE/g== 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=hwpId6HnKpWT+d4JWUZV9FMCy4BLOUtKkR5YgEaErwI=; b=Sw9xmHMNiN4J2VQl800sXcWCnOX+pbBrMsTONaNML+feF6tu+8QectyNGiOwknolDy 1mt5cF9TY1PC1I7U0XndVnWSLzJSQvSMkLKHuX4PPjHXMLlZEHZsh5B9q40T4D4y1hu8 Cn13RJTuSxrmYyISVixjgPydI+278SETTG85chZP0vi8hRRYJXE/FYmlGJmm+GgOrr/0 Z5a+ZJyA36GXH/lqQmk+2yeldkdrWC3kuEuuk6aYDAU8uYrmWXu4bxGV7kv2+GKX8aU/ nFO2IbZaB6A8fb0/YnRQVsm/wo113YV8FbUZxF6R1MVtVrIzpK8O+KXI4cpMvJMjx6Jj wGPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VFDmEmEn; 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 j7si14841449ejm.280.2021.05.31.09.43.38; Mon, 31 May 2021 09:44:01 -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=VFDmEmEn; 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 S233232AbhEaQm0 (ORCPT + 99 others); Mon, 31 May 2021 12:42:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:45938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbhEaOvo (ORCPT ); Mon, 31 May 2021 10:51:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E44EB6192F; Mon, 31 May 2021 13:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469495; bh=CIfVlU3+wV0uj2rS+MlMz+qHMLRWBkF6CLZxdql3ps0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFDmEmEnxX1+Klh3NTe7TiEUpBR/a5Gpbr2irQ6ThVyHCrhE18vcrypZYjHPxnqOI PH9P7ySOs687KlxXN+9WVPjX/tSeyOONsVsZgzn2HPfUWN8v3qQhHTVROwMIbGBAAN qaxLBikPNVIlTbKjdJ944AZziabFEz3dmv0Ag8Lg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leilk Liu , Mark Brown , Sasha Levin Subject: [PATCH 5.12 220/296] spi: take the SPI IO-mutex in the spi_set_cs_timing method Date: Mon, 31 May 2021 15:14:35 +0200 Message-Id: <20210531130711.230929777@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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: Leilk Liu [ Upstream commit dc5fa590273890a8541ce6e999d606bfb2d73797 ] this patch takes the io_mutex to prevent an unprotected HW register modification in the set_cs_timing callback. Fixes: 4cea6b8cc34e ("spi: add power control when set_cs_timing") Signed-off-by: Leilk Liu Link: https://lore.kernel.org/r/20210508060214.1485-1-leilk.liu@mediatek.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8da4fe475b84..5495138c257e 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3463,9 +3463,12 @@ int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup, if (spi->controller->set_cs_timing && !(spi->cs_gpiod || gpio_is_valid(spi->cs_gpio))) { + mutex_lock(&spi->controller->io_mutex); + if (spi->controller->auto_runtime_pm) { status = pm_runtime_get_sync(parent); if (status < 0) { + mutex_unlock(&spi->controller->io_mutex); pm_runtime_put_noidle(parent); dev_err(&spi->controller->dev, "Failed to power device: %d\n", status); @@ -3476,11 +3479,13 @@ int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup, hold, inactive); pm_runtime_mark_last_busy(parent); pm_runtime_put_autosuspend(parent); - return status; } else { - return spi->controller->set_cs_timing(spi, setup, hold, + status = spi->controller->set_cs_timing(spi, setup, hold, inactive); } + + mutex_unlock(&spi->controller->io_mutex); + return status; } if ((setup && setup->unit == SPI_DELAY_UNIT_SCK) || -- 2.30.2