From patchwork Thu Apr 16 02:54:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 6223611 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 702DF9F2EC for ; Thu, 16 Apr 2015 03:29:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80ADA2021B for ; Thu, 16 Apr 2015 03:29:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B4C4201F2 for ; Thu, 16 Apr 2015 03:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751575AbbDPD3f (ORCPT ); Wed, 15 Apr 2015 23:29:35 -0400 Received: from mail-bn1bon0145.outbound.protection.outlook.com ([157.56.111.145]:7143 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751402AbbDPD3e (ORCPT ); Wed, 15 Apr 2015 23:29:34 -0400 X-Greylist: delayed 1102 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Apr 2015 23:29:34 EDT Received: from DM2PR0301MB1214.namprd03.prod.outlook.com (0.160.219.155) by DM2PR0301MB1327.namprd03.prod.outlook.com (0.160.221.156) with Microsoft SMTP Server (TLS) id 15.1.136.17; Thu, 16 Apr 2015 02:56:50 +0000 Received: from BY2PR03CA003.namprd03.prod.outlook.com (10.255.93.20) by DM2PR0301MB1214.namprd03.prod.outlook.com (0.160.219.155) with Microsoft SMTP Server (TLS) id 15.1.136.25; Thu, 16 Apr 2015 02:56:49 +0000 Received: from BY2FFO11FD047.protection.gbl (10.255.93.4) by BY2PR03CA003.outlook.office365.com (10.255.93.20) with Microsoft SMTP Server (TLS) id 15.1.136.25 via Frontend Transport; Thu, 16 Apr 2015 02:56:48 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD047.mail.protection.outlook.com (10.1.15.175) with Microsoft SMTP Server (TLS) id 15.1.142.12 via Frontend Transport; Thu, 16 Apr 2015 02:56:48 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t3G2uj8l020561; Wed, 15 Apr 2015 19:56:46 -0700 From: Robin Gong To: CC: , Subject: [PATCH v1] spi: check tx_buf and rx_buf in spi_unmap_msg Date: Thu, 16 Apr 2015 10:54:18 +0800 Message-ID: <1429152858-1141-1-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(92566002)(104016003)(110136001)(229853001)(33646002)(2351001)(62966003)(36756003)(19580405001)(47776003)(85426001)(6806004)(19580395003)(50986999)(106466001)(105606002)(77156002)(87936001)(48376002)(50466002)(50226001)(46102003)(77096005)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1214; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1214; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1327; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:DM2PR0301MB1214; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1214; X-Forefront-PRVS: 0548586081 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2015 02:56:48.6973 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1214 X-OriginatorOrg: freescale.com Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,RCVD_ILLEGAL_IP, RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some spi device drivers use the same tx_buf and rx_buf repeatly for better performance such as driver/input/touchsreen/ads7846.c, but spi core grab tx_buf /rx_buf of transfer and set them as dummy_tx/dummy_rx once they are NULL. Thus, in the second time the tx_buf/rx_buf will be replaced by dummy_tx/dummy_rx and the data which produced by the last tx or rx may be wrongly sent to the device or handled by the upper level protocol. This patch just keep the orignal value of tx_buf/rx_buf if they are NULL after this transfer processed. Signed-off-by: Robin Gong --- drivers/spi/spi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index d5d7d22..50910d8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -583,6 +583,15 @@ static int spi_unmap_msg(struct spi_master *master, struct spi_message *msg) rx_dev = master->dma_rx->device->dev; list_for_each_entry(xfer, &msg->transfers, transfer_list) { + /* + * Restore the original value of tx_buf or rx_buf if they are + * NULL. + */ + if (xfer->tx_buf == master->dummy_tx) + xfer->tx_buf = NULL; + if (xfer->rx_buf == master->dummy_rx) + xfer->rx_buf = NULL; + if (!master->can_dma(master, msg->spi, xfer)) continue;