From patchwork Wed Jun 19 14:38:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 11004459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDC9A14BB for ; Wed, 19 Jun 2019 14:38:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC83028179 for ; Wed, 19 Jun 2019 14:38:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFEA128528; Wed, 19 Jun 2019 14:38:35 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9EF6328179 for ; Wed, 19 Jun 2019 14:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbfFSOie (ORCPT ); Wed, 19 Jun 2019 10:38:34 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:13427 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbfFSOie (ORCPT ); Wed, 19 Jun 2019 10:38:34 -0400 Received-SPF: Pass (esa2.microchip.iphmx.com: domain of Tudor.Ambarus@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="Tudor.Ambarus@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa2.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa2.microchip.iphmx.com; envelope-from="Tudor.Ambarus@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa2.microchip.iphmx.com; spf=Pass smtp.mailfrom=Tudor.Ambarus@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com X-IronPort-AV: E=Sophos;i="5.63,392,1557212400"; d="scan'208";a="38031678" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 Jun 2019 07:38:32 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex04.mchp-main.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 19 Jun 2019 07:38:32 -0700 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 19 Jun 2019 07:38:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zZXh86IpFZVS5y9m5VijsHA2ZTpWuRHLJMTWK54Sqiw=; b=Z2MYpX1DyLg6JGBqXVsVeWMIDadACh9IH9vEDMQlcXS9VZcULW08ZOBsXKXk0ZkjpwdojBF28nUozQTjpy/cTJ71GpSbJVQ/Ho92RxfsjdXbxF42gxUKg7ChuIYT6cSrdNLloXT2UsibQbiaQ0xKSqN/qoRJawX4yo4LY8KRqFw= Received: from BN6PR11MB1842.namprd11.prod.outlook.com (10.175.98.146) by BN6PR11MB1620.namprd11.prod.outlook.com (10.172.23.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1987.10; Wed, 19 Jun 2019 14:38:28 +0000 Received: from BN6PR11MB1842.namprd11.prod.outlook.com ([fe80::e581:f807:acdc:cb36]) by BN6PR11MB1842.namprd11.prod.outlook.com ([fe80::e581:f807:acdc:cb36%9]) with mapi id 15.20.1987.014; Wed, 19 Jun 2019 14:38:28 +0000 From: To: CC: , , , , Subject: [PATCH] spi: fix ctrl->num_chipselect constraint Thread-Topic: [PATCH] spi: fix ctrl->num_chipselect constraint Thread-Index: AQHVJqyoJDQBj/rjE0m3OqBeVYcv8g== Date: Wed, 19 Jun 2019 14:38:28 +0000 Message-ID: <20190619143820.4045-1-tudor.ambarus@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR04CA0048.eurprd04.prod.outlook.com (2603:10a6:802:2::19) To BN6PR11MB1842.namprd11.prod.outlook.com (2603:10b6:404:101::18) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.9.5 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 224def5d-4c37-4779-605f-08d6f4c3cb20 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:BN6PR11MB1620; x-ms-traffictypediagnostic: BN6PR11MB1620: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1468; x-forefront-prvs: 0073BFEF03 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(346002)(366004)(136003)(396003)(39860400002)(376002)(189003)(199004)(6916009)(102836004)(2351001)(71190400001)(386003)(6506007)(71200400001)(256004)(14444005)(2501003)(1076003)(26005)(86362001)(186003)(2906002)(25786009)(5660300002)(5640700003)(53936002)(6436002)(6512007)(52116002)(99286004)(107886003)(6486002)(4326008)(54906003)(316002)(72206003)(478600001)(36756003)(66066001)(486006)(66446008)(14454004)(64756008)(66556008)(66476007)(3846002)(6116002)(73956011)(66946007)(50226002)(8936002)(305945005)(7736002)(8676002)(1730700003)(81156014)(81166006)(68736007)(2616005)(476003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR11MB1620;H:BN6PR11MB1842.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Ji9KpdGKWoi2eGeKUby4auqrxnUmQEo7kDARaq7ehUQvBzR/TU6zta2D+aiPX5MJgUDTcIY18vT5R7TRqlUp9pwvdOsU/dIWAzJhmThm0AXxJ2uhdhD5GnOhix/e4ysc1+Pq2+wRxixIAQSQJfpFnyk13bTcsw8HPuBiyejjt0zq5Xd8217YLsqc49YaNZ/spRmuQXNcyGq8vnqepWIF4ni6IPAm1R/CfqkdsVTG6Xs4d7/gXPzbXbLQ4LvhZlGJjBKhaJbAfBbWdWCPSMPOhfZBh8aOJUvR1EA7HbFTbvrJu+0iccMSqU/NnDxJ3exR+UTCyV85GdwVVmQndjj2Iv7my1Ytzc+kqck8MOAUGjijOe4NCGK+BdUaXkQsvkiDNiaDxMb7DnFdBup0c0hp8rgh/OxE10j+n3gBR5JJlXs= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 224def5d-4c37-4779-605f-08d6f4c3cb20 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jun 2019 14:38:28.7253 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tudor.ambarus@microchip.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1620 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tudor Ambarus at91sam9g25ek showed the following error at probe: atmel_spi f0000000.spi: Using dma0chan2 (tx) and dma0chan3 (rx) for DMA transfers atmel_spi: probe of f0000000.spi failed with error -22 Commit 0a919ae49223 ("spi: Don't call spi_get_gpio_descs() before device name is set") moved the calling of spi_get_gpio_descs() after ctrl->dev is set, but didn't move the !ctrl->num_chipselect check. When there are chip selects in the device tree, the spi-atmel driver lets the SPI core discover them when registering the SPI master. The ctrl->num_chipselect is thus expected to be set by spi_get_gpio_descs(). Move the !ctlr->num_chipselect after spi_get_gpio_descs() as it was before the aforementioned commit. While touching this block, get rid of the explicit comparison with 0 and update the commenting style. Fixes: 0a919ae49223 ("spi: Don't call spi_get_gpio_descs() before device name is set") Signed-off-by: Tudor Ambarus --- drivers/spi/spi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index db7d9e8466c7..5c081f8cf0b8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2394,11 +2394,6 @@ int spi_register_controller(struct spi_controller *ctlr) if (status) return status; - /* even if it's just one always-selected device, there must - * be at least one chipselect - */ - if (ctlr->num_chipselect == 0) - return -EINVAL; if (ctlr->bus_num >= 0) { /* devices with a fixed bus num must check-in with the num */ mutex_lock(&board_lock); @@ -2469,6 +2464,13 @@ int spi_register_controller(struct spi_controller *ctlr) } } + /* + * Even if it's just one always-selected device, there must + * be at least one chipselect. + */ + if (!ctlr->num_chipselect) + return -EINVAL; + status = device_add(&ctlr->dev); if (status < 0) { /* free bus id */