Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp818835pxj; Fri, 7 May 2021 23:05:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlatbFZSLf0jf7ptsQLhwxl4HvJGZ3dyj3epq2Z+77jaNUw3PNM+r3ZgOoguY0XIkjIGMZ X-Received: by 2002:a62:d108:0:b029:25d:497e:2dfd with SMTP id z8-20020a62d1080000b029025d497e2dfdmr14427193pfg.29.1620453903469; Fri, 07 May 2021 23:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620453903; cv=none; d=google.com; s=arc-20160816; b=RY8FAF6k73xqO/fRWivta8AqRrFGJhtTWOz/YlPtE5AkiA26tXjLmLeX6QCVQKR5Ji wwbVIxj4otZEAvp95QjLEBQJRN17JY093BSjx5RReDGxZ5LgSzoBiTEt4Iu6FNGMBS9e TY0atfd6JF69zPll+n9RIpXdxTFK33AcGRzLiUx94OUk/MIYILbvl1m9i1/wfK8hyXYm 9HY+XGwYlABk7Rwkba/+V9izSjadvnSZwaSYxQ0AWdlFhN51WY9/2GAxsMHZIJz4JmpD X64z31sw07+23IAbFF/WdrOOLJ9NYB5s7quw8BQ/J7vMX6zzbBL2VyWueA3NiJRk9JEy 0hbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=RMmnVq4zBur2RDJHJcSZFXZIgubb+25sQl1ScvA+rO8=; b=a+nk+KEWGSoSS5bRQTZW7AwALqKU8ERUpWp9otYjhQkQIDkw1nhMFsqkGqLSWnCwUC UAVPjHjavgFr485XX+PSwbVyLvW0paMDInO6Hnjt2iCPHep5HyWLtcfuVvftTWbCMIZq gep+JBdl2rNQBGvmjobFPZelrdcoVIO4NXqTQgBy6b52LxAtnxMpcd0VuSTeKONqLGWH 4fusvR/Qees5LW6X51IdkR77nz2HfYe4KOA8+ONUPnlhBtxD4zPEk8QXvCPNREYeuiQe kp60LViVqAOxq0NV6rV0dBQiFcvF+eJef/marQ4RUQhz1b5wwdMP3GPZ51WfLmdTESDa GWkQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m21si17373686pjv.116.2021.05.07.23.04.50; Fri, 07 May 2021 23:05:03 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbhEHGDg (ORCPT + 99 others); Sat, 8 May 2021 02:03:36 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:28806 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229473AbhEHGDg (ORCPT ); Sat, 8 May 2021 02:03:36 -0400 X-UUID: 943db313235c48f4ab6d6ade246fc35c-20210508 X-UUID: 943db313235c48f4ab6d6ade246fc35c-20210508 Received: from mtkcas32.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1994536755; Sat, 08 May 2021 14:02:31 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 8 May 2021 14:02:20 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 8 May 2021 14:02:19 +0800 From: Leilk Liu To: Mark Brown CC: Mark Rutland , Matthias Brugger , , , , , , Leilk Liu Subject: [PATCH] spi: take the SPI IO-mutex in the spi_set_cs_timing method Date: Sat, 8 May 2021 14:02:14 +0800 Message-ID: <20210508060214.1485-1-leilk.liu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: BC75931E69A775349CBFFC250E38064680A523688CABCE0898A061ACCED4A45F2000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 2350d131871b..6bda471b9621 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3459,9 +3459,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); @@ -3472,11 +3475,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.18.0