Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4469543imw; Tue, 19 Jul 2022 07:12:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfKaCuvDv1z6gP4hJczVRrNvZJpsFDQBLpuWfTpUu/srFAH2Cki1l1Md47NCHwWxtZtJRm X-Received: by 2002:a05:6870:1607:b0:101:8840:6b4f with SMTP id b7-20020a056870160700b0010188406b4fmr18422323oae.13.1658239952178; Tue, 19 Jul 2022 07:12:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658239952; cv=none; d=google.com; s=arc-20160816; b=MjZ89lX9dN+IkWMdUb10kA45tB3A61ddRxrd704UMAzsYLJIcoKpAN98TT2/Hcku0d XADAhNqQartSJkxGPi8keTrYady0QGQd6+Xfy/mfuWGE7Yi6J2Sr00GX97/kOyfzTW7K lkCTorUzDoXXIXBVQVRk+JLaPd24SJfzG2SM3WVgjxC7xMzgIHedjxR15lCjWH6OkEDB YluqCWQaA0bFpMFh1ZBGBkY9WH/J6NJcQg4lojc1jPCudElv6IX5aA/V4zF4Ygcj8RLZ 1Ur54YVR4Z68L7SZhLZYGs2yw2aMDcG1NoyAZMomyICkWCs7gveP+rMHRNzJTz/AtN5E XB4Q== 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=7uKZrLbQOMAtGGxUuKb5uX5GW7QkP2Gv2yTSBMxgyd0=; b=bhQ0t2ORM9jqc49nJTEQbWntM9Z0C2UYuTCRSX72QFVc6ho7uGAGJP8c9EYIwfBM1O 3ai56AMM9W3K5mqkBnuJoyrgDEoMEfDC12oscvlIaWSnaTBKBK/PT/6ceeXqDTIjN8Z/ O22G87mlKm+jaFK9bbQaZHsUjDEgD1DNF5/gB45tsJd2vKLWXPlWeIqTgdOnySbqxe8e MF9dM19fiQGBCTmxkZuixIdkTPo1SD3V5JKgrobuhYUX07kt9OGClxeMpMP1WrfzljnR 9IT4M3QPgsNbj7j8DUyDkJX2qL2u/o4rXuySRBQtm/86nsuOqiOeF7qWBz4X9PoqNeZr 2Ieg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CgdxNaBi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020aca4005000000b0033a397f4837si12529223oia.302.2022.07.19.07.12.18; Tue, 19 Jul 2022 07:12:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CgdxNaBi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240424AbiGSMbF (ORCPT + 99 others); Tue, 19 Jul 2022 08:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240866AbiGSMaE (ORCPT ); Tue, 19 Jul 2022 08:30:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBCC46D54C; Tue, 19 Jul 2022 05:11:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7AEF3B81B37; Tue, 19 Jul 2022 12:11:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEACCC341C6; Tue, 19 Jul 2022 12:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232691; bh=5JisgN0ujQbm7P/KToV789LWlkwNuqdhCX08242VV+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CgdxNaBiY5ped1t05iTuK8AtTPWKmHFiqPG6gYyzh6xKdijwVFzSSJZNT0FB1PUaD TPWcMwD6uRToBLgan7q/lG0qmNF8Ru5/470SjavS0v/IQkovf2z0t5eC2gsW3+AZJd hyOfoQP6ruu1tQ7jr8hPqgG9OqF0uMwuyldzdWOo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anastasios Vacharakis , Cristian Ciocaltea , Mark Brown , Sasha Levin Subject: [PATCH 5.15 032/167] spi: amd: Limit max transfer and message size Date: Tue, 19 Jul 2022 13:52:44 +0200 Message-Id: <20220719114659.861525597@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cristian Ciocaltea [ Upstream commit 6ece49c56965544262523dae4a071ace3db63507 ] Enabling the SPI CS35L41 audio codec driver for Steam Deck [1] revealed a problem with the current AMD SPI controller driver implementation, consisting of an unrecoverable system hang. The issue can be prevented if we ensure the max transfer size and the max message size do not exceed the FIFO buffer size. According to the implementation of the downstream driver, the AMD SPI controller is not able to handle more than 70 bytes per transfer, which corresponds to the size of the FIFO buffer. Hence, let's fix this by setting the SPI limits mentioned above. [1] https://lore.kernel.org/r/20220621213819.262537-1-cristian.ciocaltea@collabora.com Reported-by: Anastasios Vacharakis Fixes: bbb336f39efc ("spi: spi-amd: Add AMD SPI controller driver support") Signed-off-by: Cristian Ciocaltea Link: https://lore.kernel.org/r/20220706100626.1234731-2-cristian.ciocaltea@collabora.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-amd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 3cf76096a76d..39dbe9903da2 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -28,6 +28,7 @@ #define AMD_SPI_RX_COUNT_REG 0x4B #define AMD_SPI_STATUS_REG 0x4C +#define AMD_SPI_FIFO_SIZE 70 #define AMD_SPI_MEM_SIZE 200 /* M_CMD OP codes for SPI */ @@ -245,6 +246,11 @@ static int amd_spi_master_transfer(struct spi_master *master, return 0; } +static size_t amd_spi_max_transfer_size(struct spi_device *spi) +{ + return AMD_SPI_FIFO_SIZE; +} + static int amd_spi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -275,6 +281,8 @@ static int amd_spi_probe(struct platform_device *pdev) master->flags = SPI_MASTER_HALF_DUPLEX; master->setup = amd_spi_master_setup; master->transfer_one_message = amd_spi_master_transfer; + master->max_transfer_size = amd_spi_max_transfer_size; + master->max_message_size = amd_spi_max_transfer_size; /* Register the controller with SPI framework */ err = devm_spi_register_master(dev, master); -- 2.35.1