From patchwork Tue Feb 11 15:20:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1236349 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=E0pUKbyH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48H6251Df8z9sRQ for ; Wed, 12 Feb 2020 02:21:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 25053816FF; Tue, 11 Feb 2020 16:20:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="E0pUKbyH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 326D8816BA; Tue, 11 Feb 2020 16:20:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FORGED_SPF_HELO, SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02on0714.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe05::714]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0C7278172D for ; Tue, 11 Feb 2020 16:20:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bwrYsVM5YNJL3Wmnl8eGGsygdcdIVAk5DmEGWTRov5OOrFf+bRz+Wy4Diz9nQHQ+Qu0u+Dx2OkLpFsiEJ4CmFDdM2l4yN90dvzEUUg9THGLkh0th7zSkHvHkSz6nAV00hJnUJ3JroRS+yr9tL+IUdeSWSITeId3Zgpt39bJ6y+43NHkHRV8Wp72onr+YAu9/2vM0g/S1pCWSptd5zPmeuSzUz4QcZdP28nx9DHB+Uh21vbe34pegPBEVy4w0SMFqW1vVfOb+27aqfpeWQd8Nvzb07vJg7GavulE0ilygaia4L9sXwDjtROQMhTCOZb0MQfBZ0CCEShxw93VT7oCyug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kGqeJ4Ssw64f8IMeHvv3LwyJrEiwxIVLv5qHp6V4kUg=; b=mhzLxLPwUmnF3As+2hqEokddSMnjK0b7E7BkeHnmhlSS/C6LTm24tZv//KEELRsUMuFUbaFKuQfwc9j6HWoC9QVzFFDmWiwiwMV6h7q5wpIU1C5BG6HNbBnrr/8t44bl01IccAWVYoDJjYe9n02rTuqfZJw3/ycmx/kXbrS2BGRO70EKRFZo7fiOnzN6yOxuoTtnkT2agpnLb+Y+1Uhc+KoFCq1XBeVNRLe57MEy8WAqQs7I8KbCTA3fe7jcosQtqDuPpefQq0/DnVEBDIxMwN5xu1csiZvcDadpunRBFQdWYLMra3SGRv1A4T6+Eg/OegG5SCX/WNHLAf47y9Rm2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kGqeJ4Ssw64f8IMeHvv3LwyJrEiwxIVLv5qHp6V4kUg=; b=E0pUKbyH30GBFfjmYjl0XqiZEwIBW+GbZDQvcy/eXu+H/3hg9YatOF71egYErk0VFD5r/IsMy/MnLnEj8FP47h8kydtmxs7mYd/f3X7kemXmuGFK1tVt1aQd62g7MTfG9OoHC6NshT8Z93wL6+igZVPnb+7vV6Zwj/vce2pxToI= Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (20.178.126.85) by VI1PR10MB2141.EURPRD10.PROD.OUTLOOK.COM (20.177.58.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.25; Tue, 11 Feb 2020 15:20:24 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::8175:5aa2:2870:766d]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::8175:5aa2:2870:766d%6]) with mapi id 15.20.2707.030; Tue, 11 Feb 2020 15:20:24 +0000 Received: from prevas-ravi.prevas.se (81.216.59.226) by HE1PR05CA0209.eurprd05.prod.outlook.com (2603:10a6:3:f9::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.23 via Frontend Transport; Tue, 11 Feb 2020 15:20:23 +0000 From: Rasmus Villemoes To: "u-boot@lists.denx.de" Subject: [PATCH resend 3/5] mpc8xxx_spi: put max_cs to use Thread-Topic: [PATCH resend 3/5] mpc8xxx_spi: put max_cs to use Thread-Index: AQHV4O7If59bg/EzIkGsCSst2VAbSw== Date: Tue, 11 Feb 2020 15:20:24 +0000 Message-ID: <20200211151947.26091-4-rasmus.villemoes@prevas.dk> References: <20200211151947.26091-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20200211151947.26091-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR05CA0209.eurprd05.prod.outlook.com (2603:10a6:3:f9::33) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) x-mailer: git-send-email 2.23.0 authentication-results: spf=none (sender IP is ) smtp.mailfrom=rasmus.villemoes@prevas.dk; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [81.216.59.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1df116d3-b9b1-4cbb-7b25-08d7af05ea77 x-ms-traffictypediagnostic: VI1PR10MB2141: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:418; x-forefront-prvs: 0310C78181 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(346002)(396003)(366004)(39850400004)(136003)(199004)(189003)(36756003)(316002)(186003)(16526019)(71200400001)(2906002)(478600001)(956004)(2616005)(6486002)(26005)(6506007)(86362001)(6916009)(81156014)(81166006)(52116002)(6512007)(4326008)(8976002)(107886003)(5660300002)(1076003)(54906003)(44832011)(8676002)(8936002)(66946007)(66556008)(66446008)(64756008)(66476007); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR10MB2141; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: prevas.dk does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dIs/v4xLxsKHsqGKQNM0dYdVtQD2/r7Lc9Lplp3yOCFb3NILtT9UDPlTHMXseWvTd4Ga1DvVxlfURS582yg6al8x2E4AYXwkpRxKwfbiw2aWOf6aIsgpkR88dr/MhyV3HqXn4DbnyFmg1+n1OhiAQSNsHpLongC+MEIhr/jvrHZm3LWvUWO2haBqrM6Gu8v7JlGAOhHekjLAdic17/Q5xUpssM6zLig3GIa0bxikfz+v/NTiIQJODN3hJu8g7nCLwJCjrBdW6MJxMz9aEoII4nTfePhZyC8uyoZ4pZrMeisJvkizAy6q8YcSLIGsjPryp2SbLd2uAcdAN9nmfBiQvZOJ0ymmWyn+Kw6w8Q4LG5N16BtJUFjHhVmOxsb/8pDvzb4UAzJKzTXJE5ZrPpu7jIZKBfi61aUdlETBzYpPbhSKVXpDRbCf3HZC+EN39NCN x-ms-exchange-antispam-messagedata: OJPatLltDf3NjrcceBrioij/ZW8CyvzWbyMvkEQsRB37sWK1i9AlnU6o+8hNwABhk+59k3ZKJ2ydPTZJwV+1O6b1WABsZrQZOsaq2c08RjkFu1JVUIonQHN6pDLUgGLclUVam795Q1ZsCC4xgiKGTg== MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 1df116d3-b9b1-4cbb-7b25-08d7af05ea77 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Feb 2020 15:20:24.1499 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: FR42Gan90/miCJhlGSuIeAW2ZrpBFyOWs7Cl5OQIBB4/HZyNakfztJQLrFsvGMJFIOF9euH5oknzSnOSFiCE8zmOb6KceS0XTal6x0Bbs3Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB2141 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?iso-8859-1?q?Klaus_Henning_S=F8rensen?= Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.1 at phobos.denx.de X-Virus-Status: Clean Currently, max_cs is write-only; it's just set in mpc8xxx_spi_ofdata_to_platdata and not otherwise used. My mpc8309 was always resetting during an "sf probe 0". It turns out dm_gpio_set_dir_flags() was being called with garbage, since nothing had initialized priv->gpios[0] - our device tree used "cs-gpios" rather than "gpios", so gpio_request_list_by_name() had returned 0. That would have been a lot easier to figure out if the chip select index was sanity checked, so rename max_cs to cs_count, and reject a xfer with a too large cs index. Signed-off-by: Rasmus Villemoes --- drivers/spi/mpc8xxx_spi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 1c7bf10f91..ac4d0a9bae 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -35,7 +35,7 @@ enum { struct mpc8xxx_priv { spi8xxx_t *spi; struct gpio_desc gpios[16]; - int max_cs; + int cs_count; }; static inline u32 to_prescale_mod(u32 val) @@ -74,7 +74,7 @@ static int mpc8xxx_spi_ofdata_to_platdata(struct udevice *dev) if (ret < 0) return -EINVAL; - priv->max_cs = ret; + priv->cs_count = ret; return 0; } @@ -131,6 +131,11 @@ static int mpc8xxx_spi_xfer(struct udevice *dev, uint bitlen, debug("%s: slave %s:%u dout %08X din %08X bitlen %u\n", __func__, bus->name, platdata->cs, *(uint *)dout, *(uint *)din, bitlen); + if (platdata->cs >= priv->cs_count) { + dev_err(dev, "chip select index %d too large (cs_count=%d)\n", + platdata->cs, priv->cs_count); + return -EINVAL; + } if (flags & SPI_XFER_BEGIN) mpc8xxx_spi_cs_activate(dev);