Message ID | 1479772241-16453-1-git-send-email-juan.gutierrez@nxp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-spi-owner@kernel.org> Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C122760237 for <patchwork-linux-spi@patchwork.kernel.org>; Tue, 22 Nov 2016 04:19:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A902328324 for <patchwork-linux-spi@patchwork.kernel.org>; Tue, 22 Nov 2016 04:19:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B2452831B; Tue, 22 Nov 2016 04:19:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C68EF2831B for <patchwork-linux-spi@patchwork.kernel.org>; Tue, 22 Nov 2016 04:19:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755074AbcKVETF (ORCPT <rfc822;patchwork-linux-spi@patchwork.kernel.org>); Mon, 21 Nov 2016 23:19:05 -0500 Received: from mail-db5eur01on0043.outbound.protection.outlook.com ([104.47.2.43]:63008 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754959AbcKVETE (ORCPT <rfc822;linux-spi@vger.kernel.org>); Mon, 21 Nov 2016 23:19:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Y3EPGPvpLoyCGurzH3jvP+/UAIPaHP5qYjY4sCx7QAc=; b=abzscdUYQOZLHQHo6Yb3kuB2UFQ4AgoJKFmDR2rFZwqBdm0ChCMAHPdHu42yVVm1BpnnN4h/eyAP5Y0NBSfnGd3PjFJfSazJp6r1M3XAc2OurRUKd3rmWCpMmyu2KrM2J0KBS5ydBuTABfCC7+jIvYWgzCGWGsyLlmgvVnj6edU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=juan.gutierrez@nxp.com; Received: from kakaroto.am.freescale.net (192.88.168.50) by DB4PR04MB0766.eurprd04.prod.outlook.com (10.141.45.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.734.8; Mon, 21 Nov 2016 23:51:50 +0000 From: Juan Gutierrez <juan.gutierrez@nxp.com> To: <broonie@kernel.org>, <linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <juan.gutierrez@nxp.com>, <yibin.gong@nxp.com>, <fabio.estevam@nxp.com>, <alejandro.sierra@nxp.com> Subject: [PATCH] spi: use sg_next for walking through the allocated scatterlist table Date: Mon, 21 Nov 2016 17:50:41 -0600 Message-ID: <1479772241-16453-1-git-send-email-juan.gutierrez@nxp.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.88.168.50] X-ClientProxiedBy: SN1PR12CA0019.namprd12.prod.outlook.com (10.162.96.157) To DB4PR04MB0766.eurprd04.prod.outlook.com (10.141.45.19) X-Microsoft-Exchange-Diagnostics: 1; DB4PR04MB0766; 2:xrP8JBekLhCbepNsfyAcL7lkuzRJJDjYxSp84HNSHo8DUQiutiQSJ+PEjXSakHodqNfBcEti8aP0NEqDW4DTfhAqcrTMJDhpkJrrC3xDKiBPL9cW1srorWEjjF9hjrhw5bvLJS4mo6sO08Sqg3UmO7ppqWUGdLkVWqMAh0FvSJ4=; 3:oQI4jk6/ETom5UO5xXdPeiBm6jPPDyyRQSDBNH/aQbO2Ck2SSQeqweQDqotk2zUaS5J6pn9xzYb79n3t1oXkoJC2r7tJzoCrJGU5FaThf20jmyAnpGUR7XRZyIiBMgzzEo72zseClSiXPWq+yjhIRjglFHR2vZL6CR8TWs2VFv4=; 25:WLIMFsAPmhiptMcMgMW8Btg6fdS5KZYSTT/Ep/bYmzbxUIKQqNRxUyg3rc+p2XV3WI6kraa6gSFJsubySZItifoO0wf611J/1VVbICEFKjCU5jN5cYW5/Z/eZ4Z7Po0cMes+8caDl2d5pohmIKgvC0J6FyqtlVDy4Xzp5tl9lXLSIsH/tGKQDB20VLR5F2yk1GdLOe11Quc2vnX7DnubDVyU79bdt1Pvlld2bQEHqiOnCv29XVkdSlQc3utQGJTp0+TrpQPHxM2ZfrbwnEvhS3pcLMNuLduh7VNHNN/MQ5nC2Uj2c9bXflTtZgzHZzfJ+PqmSJd5OiLAHvH3eJdD0zWPL4GbHs+VxukYg12r0OXPcNmrQd7mF/N0ytF3zE9Npnn+lDPzCMarMolAR+Bgp3isDm5KXxhm75yid4YrePuxEWi2/71krDQc0yWEBR3ivAVqifjiRRH+qsv++4POzw== X-MS-Office365-Filtering-Correlation-Id: 3aa37b4b-a98d-45c8-172b-08d412695e01 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB4PR04MB0766; X-Microsoft-Exchange-Diagnostics: 1; DB4PR04MB0766; 31:inOC5lEmV+Q1fWZ+paU184Tx25yYO/UGxh50zF9jNcaX2RRRvPybmjtniAVmVDYesSh1K1D9a/NSnHBQDnKkp6Fgul974R4vrP22OdZZNRoEuLaZ73IlXERagw8/4dEga/NYd4Lwky1Z4GHDEaTHh1n7JJQnxoLlVpulIlx92mWBlBi8uX5mWT6G2UNj1lyHIOqsRZmQgti3+kKMp2hrWrgvroRrwsdb+fyqfUQYc1k1t0iOdBA9Wd1QZVHDoq01; 20:qwfP7BO//mSgp/oU8Z+QxTD1YrGU8aaQSSyH9vIumBWmYlzM502xtPFJgHlDTWEDu7Qzoium/1N8S04k71pEQ16VYUXNCWS+QYG33Kjg6tgeFg33wuumf/JD2bd96Sum87oIOSUD0gBwgQEb+8kWXwlfFZoriBnoSDZDfAAzHcWbta4EhE4oiuHGnGZiH0fk/X3teiKj/WOP80raSWvndovYhPdU6BKUyW6EK24WwPoNM8uvt3dtdy9pCDg4I7K69NbInX8Xf2dwMBtBjG0bY86MtyKovQOtWBzl3q/YopWSnc0S5uYzXwRj1lmLdNJT+VrwCbMVlnorEkx0yTxp2ip1V1kvD88xR2bGltGUWxMDrSVzceunVensHJUnZlXSJtFakATt/DDo5l4dOXmPMv4qbVVitJFypGwqNW1pnoL1YsMfgFE+0/+9q+i8uDC26+jzPU9xpKYozWCCNy5mKMrAmfm/hkVIq9vLObscv47KENkxv5zdWjaDS+5MLQGE X-Microsoft-Antispam-PRVS: <DB4PR04MB07665A2D0CE1A7C516CE43A898B50@DB4PR04MB0766.eurprd04.prod.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:(131327999870524)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040307)(6060326)(6045199)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6046074)(6061324)(6041248); SRVR:DB4PR04MB0766; BCL:0; PCL:0; RULEID:; SRVR:DB4PR04MB0766; X-Microsoft-Exchange-Diagnostics: 1; DB4PR04MB0766; 4:oraHX2HWG3nwNKGmVBCIUnHlVwP6iTxiqaPhs3HnxltYxgg6xJ1L/OPudgrvs7tO9tate5uV0a7eSOj7sugDuCW4yJRdKy+EjT8b9isg0mgZyiuN4hhY77B762VdFNEtHMpoQmwynGhoST6DEPlbsi7f0ZRyN/g/BFI+0rhGfKf/QqMckarVOCtSUOsd0hC1ACJKunaHRlSKleFvqWMrNhrMm+lKDW/Zolmn+JX7xSOU29iEYAukUIvuS7xOMr5FF0XDD4OGpuIWN7keNJ3MyMhlOUXdKX2hOsEK9+X5TsiHZLx/VHgl5pYtH7XP4TUoNYXUl94w1DFqbHf0mVVREXI6SPi8yTdtXEyTPRid83kIrxtcgu4NpvOptkzJELPSgRi9AUEpbbqDFAxs+yiKFmZ4gkbp/a9XzkHlccf3ijO9xJujIe4vaN2YjaMSsgPRIQXSKE7cMCYwboBL65p42hunuF8ImRN0iK9c2h+sQL3PPD7xqqJGVgQMDOPiUE+Q1oVOAYbNRuEH+twSA0Fphj5hyuteYTatPXX209aV8Od9IEcv67DE8bQM4GcnARnUMYQU5o82sI846HaKGI1HRg== X-Forefront-PRVS: 01334458E5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(305945005)(6666003)(36756003)(38730400001)(2906002)(189998001)(42186005)(4326007)(47776003)(8676002)(68736007)(66066001)(50226002)(2201001)(7846002)(101416001)(81156014)(86362001)(105586002)(33646002)(50466002)(48376002)(92566002)(5003940100001)(77096005)(6116002)(50986999)(81166006)(3846002)(97736004)(7736002)(106356001)(5001770100001)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB4PR04MB0766; H:kakaroto.am.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB4PR04MB0766; 23:QIK0TU9voBgHmL4O9fC7PcQQG+HkMPs6PyURkbu/8?= =?us-ascii?Q?H8mdeXiJkUCsIoRxYpUSWcQKzo44kFWAd+MZ/DVcDZSHeZkb2lkg6yc7NIeA?= =?us-ascii?Q?zdXD6QL02fD6W/txV5kqX39HDuEURGYHL9PSDpKinA2p2vYpZt+nf1YbwOdr?= =?us-ascii?Q?Os45RcAuXLyVNKfSezWZEWp4AMK+TKG3VaBQLXyttGIrzVSqf4j41YKLz8C4?= =?us-ascii?Q?GhNwlxyZDz0Q/TfxJQR5l7nsqBXTwec7tf2+a9mFQ8iI53jHM8ILADPiVa3r?= =?us-ascii?Q?juJA9aNPerK90t2E5K/upy04+tGN45my0B1XsD5pT5PM9StRk24muUkfozEr?= =?us-ascii?Q?g5uut02iB+ZkLNYxjHGviDqqm02upDVYgg7vs6yFGRyCu21XSV/7nxLGMGaf?= =?us-ascii?Q?pNkOo09utttP5U8gFDDMPuDQA67JKkBhgobnYdu8W8Su39tCW3lgIud6HhFM?= =?us-ascii?Q?BXCoq3nutAhlocAuz0mod8srWoe5ti3w/QyaCOy/C4UgolOFEH0leDuBg59K?= =?us-ascii?Q?wXEC+NaNZcS6zmLSmZ8MsufYBkxWgRdbkc8HKyFPz1RoEKtFowO/BTpL9bD5?= =?us-ascii?Q?7IKOYlyfn+rVKmwnPu5ULeSz8HItomknTp3+IQfVz3mBe/j/Xyo2MHWYOaqF?= =?us-ascii?Q?PeROUYkI5thieFUl5+s/e97RMLapuT2yOxyw/pzVWX2wNlsPiQVYW7Wdx5e9?= =?us-ascii?Q?agoGZ423YdGR+Uwg6u9O//I/3gOrXIKZPvQUQP904fMq8bNskr+HDb9k3+Uy?= =?us-ascii?Q?D9alWReqRH3O6p3LIsC+9uGjPfmMEt0Vf9EWAxoCJcKGjErGjX1k7akFn8g3?= =?us-ascii?Q?vWJT22gXd/jOke8pajkA2uIk/YLD3ufmy2Oii21G4FarRr3lYn37xU6s3W5D?= =?us-ascii?Q?i9MAzNyKM7tGIGj6/yglgBHNgRinNlRKh2qFAlc4EqyyM1iqHB0ikD4UlvNW?= =?us-ascii?Q?RtGLS8/aObJMIWLb+tyFPmfRWwfug+QmjiEg16xb19tOSMF5z3wT/Y6o8vx1?= =?us-ascii?Q?vCfoYjOazMlv//ufuNFj2xq?= X-Microsoft-Exchange-Diagnostics: 1; DB4PR04MB0766; 6:frwgFtYdWuGBJWNgkTwZObLREGoMjs1dbsvDi6c7A2wBVRYRsmdH/mIqn+H8dEmFWCKirxupvhB1QwiXG3Rr5j9hOprvcgPLojLXqirUl8b3aQxD4uuRaI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QzXLo9AVYnCGRdBPdJmCrQsY9fCNN3VcwK8U1kvg1N9LiRnK2m2X5SupWAN2jf6pmoGk2YNWlo6KUXMYWTJ4rNyb1ftHOeIqqo/1rWOjWZb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2016 23:51:50.7084 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR04MB0766 X-OriginatorOrg: nxp.com Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: <linux-spi.vger.kernel.org> X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP |
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 838783c..6435548 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -720,6 +720,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev, int desc_len; int sgs; struct page *vm_page; + struct scatterlist *sg; void *sg_buf; size_t min; int i, ret; @@ -738,6 +739,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev, if (ret != 0) return ret; + sg = &sgt->sgl[0]; for (i = 0; i < sgs; i++) { if (vmalloced_buf || kmap_buf) { @@ -751,16 +753,17 @@ static int spi_map_buf(struct spi_master *master, struct device *dev, sg_free_table(sgt); return -ENOMEM; } - sg_set_page(&sgt->sgl[i], vm_page, + sg_set_page(sg, vm_page, min, offset_in_page(buf)); } else { min = min_t(size_t, len, desc_len); sg_buf = buf; - sg_set_buf(&sgt->sgl[i], sg_buf, min); + sg_set_buf(sg, sg_buf, min); } buf += min; len -= min; + sg = sg_next(sg); } ret = dma_map_sg(dev, sgt->sgl, sgt->nents, dir);
A null dereference or Oops exception might occurs when reading at once the whole content of an spi-nor of big enough size that requires an scatterlist table that does not fit into one single page. The spi_map_buf function is ignoring the chained sg case by dereferenceing the scatterlist elements in an array fashion. This wrongly assumes that the allocation of the scatterlist elements are contiguous. This is true as long as the scatterlist table fits within a PAGE_SIZE. However, for allocation where the scatter table is bigger than that, the pages allocated by sg_alloc might not be contigous. The sg table can be properly walked by sg_next instead of using an array. Signed-off-by: Juan Gutierrez <juan.gutierrez@nxp.com> --- drivers/spi/spi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)