From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Sun, 22 Jan 2023 19:21:40 +0100 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pJeyK-002IAl-HE for lore@lore.pengutronix.de; Sun, 22 Jan 2023 19:21:40 +0100 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pJeyI-00076Y-DK for lore@pengutronix.de; Sun, 22 Jan 2023 19:21:39 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/9bEkar1TCT+TWOdC60lZ7LfgWU9tnGwfHq6ubwyzI0=; b=VBLm0hY4U49PnLxqZe5hvRSXVI EFVpK8OZPvjdmnTk70Xnrzp4DfTbiUYU2n2t7RxlWOUmURzR14srftZz0SN7KTJhGfHT0rw4DRSfk /yLEgb/cICtbAdUi1vaTstnW4d11PMC44gHeFCctu+tsF6Qg0bEHrtHNMLoWExYmwP0FyCWa0smFF D+1R5DDjvLvPT+awinQfo7isWfGbE2x7ctA4VylgS/COcRnkW0sRyMp/Ycgsg4wz+xmxy9UKM08Hk f0FdWLnDTG2Fr6fBd9nLZrUGKqRrZMQ038N+SC/uyQx5mEyLepHM2pw6dhnPNi0Kkxnp6SvPoG2xg B4dZQM1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJeww-00FeyW-VE; Sun, 22 Jan 2023 18:20:15 +0000 Received: from out0.migadu.com ([94.23.1.103]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJewr-00Fey8-6N for barebox@lists.infradead.org; Sun, 22 Jan 2023 18:20:11 +0000 Date: Mon, 23 Jan 2023 05:19:47 +1100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1674411605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/9bEkar1TCT+TWOdC60lZ7LfgWU9tnGwfHq6ubwyzI0=; b=D8p3i1psBdY6VnjO2YqkAT/2kX4RGlDmmPhh37FyDWgHqPjtzjet3oJu2DwZhKDrBtou/9 Fa3K3P9aVrKld1qbtuRxZimLi0UMBz7Hh9A0SozUixhB/HD4BrEoRAFAl7JX1ZGlkovxqA xLSxkj08ws459ZA555NrN+QLC9opM7/FRfHVOZkJtViULMotLGncj2+rj77T9jW63+fxvw 1tQLV9TqUqbbPGIax7TVN7a9+SPEIAiIOZw2cwD+xPxcST3RkfPlY3WM5LQNL9HHYohLYz MuiFRBFchvYQgwkJ63uE5dBQErEyyxOnCI2G9Tr6fFcCH4o9dBPLhedLEuKZMA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: John Watts To: Alexander Shiyan Cc: barebox@lists.infradead.org Message-ID: References: <20230122150432.4096816-1-contact@jookia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230122_102010_157510_B3FBDA44 X-CRM114-Status: GOOD ( 29.11 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-5.0 required=4.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: Re: [PATCH] spi: Fix probing SPI drivers without a cs-gpios node X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) I certainly appreciate the feedback. One thing to note is that an existing driver has a similar check, so that would be 4 places with code like this. On Sun, Jan 22, 2023 at 09:09:38PM +0300, Alexander Shiyan wrote: > I dont know. I said how would I do it if it was my patch. I hope > Sasсha will decide how it will be better. > > вс, 22 янв. 2023 г. в 20:13, John Watts : > > > > Hi there, > > > > Yes it would be possible to refactor it to do that. > > Would it be worth it for these few instances? > > > > John > > > > On Sun, Jan 22, 2023 at 08:06:04PM +0300, Alexander Shiyan wrote: > > > Hello. > > > > > > These lines can be defined as a regular function like > > > get_cs_gpio_cound(node), isn't it? > > > > > > вс, 22 янв. 2023 г. в 18:06, John Watts : > > > > > > > > of_gpio_named_count returns a negative value on error but this > > > > is discarded and cast to a u16, making error handling impossible. > > > > > > > > With debug logging enabled this effectively halts booting so the board can > > > > print an error over serial 65534 times. > > > > > > > > Check for this error and proceed as if there are no gpios specified. > > > > > > > > Signed-off-by: John Watts > > > > --- > > > > drivers/spi/atmel_spi.c | 8 +++++++- > > > > drivers/spi/imx_spi.c | 8 +++++++- > > > > drivers/spi/stm32_spi.c | 8 +++++++- > > > > 3 files changed, 21 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c > > > > index ec90330e53..a2314be8ee 100644 > > > > --- a/drivers/spi/atmel_spi.c > > > > +++ b/drivers/spi/atmel_spi.c > > > > @@ -388,6 +388,7 @@ static int atmel_spi_probe(struct device_d *dev) > > > > struct resource *iores; > > > > int ret = 0; > > > > int i; > > > > + int num_gpios; > > > > struct spi_master *master; > > > > struct device_node *node = dev->device_node; > > > > struct atmel_spi *as; > > > > @@ -408,7 +409,12 @@ static int atmel_spi_probe(struct device_d *dev) > > > > master->num_chipselect = pdata->num_chipselect; > > > > as->cs_pins = pdata->chipselect; > > > > } else { > > > > - master->num_chipselect = of_gpio_named_count(node, "cs-gpios"); > > > > + num_gpios = of_gpio_named_count(node, "cs-gpios"); > > > > + if (num_gpios < 0) { > > > > + num_gpios = 0; > > > > + } > > > > + > > > > + master->num_chipselect = num_gpios; > > > > as->cs_pins = xzalloc(sizeof(u32) * master->num_chipselect); > > > > > > > > for (i = 0; i < master->num_chipselect; i++) { > > > > diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c > > > > index 3e0ad2db00..b10076639a 100644 > > > > --- a/drivers/spi/imx_spi.c > > > > +++ b/drivers/spi/imx_spi.c > > > > @@ -564,11 +564,17 @@ static int imx_spi_dt_probe(struct imx_spi *imx) > > > > { > > > > struct device_node *node = imx->master.dev->device_node; > > > > int i; > > > > + int num_gpios; > > > > > > > > if (!node) > > > > return -ENODEV; > > > > > > > > - imx->master.num_chipselect = of_gpio_named_count(node, "cs-gpios"); > > > > + num_gpios = of_gpio_named_count(node, "cs-gpios"); > > > > + if (num_gpios < 0) { > > > > + num_gpios = 0; > > > > + } > > > > + > > > > + imx->master.num_chipselect = num_gpios; > > > > imx->cs_array = xzalloc(sizeof(u32) * imx->master.num_chipselect); > > > > > > > > for (i = 0; i < imx->master.num_chipselect; i++) > > > > diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c > > > > index 639c4f1740..a34e0b143d 100644 > > > > --- a/drivers/spi/stm32_spi.c > > > > +++ b/drivers/spi/stm32_spi.c > > > > @@ -513,8 +513,14 @@ static void stm32_spi_dt_probe(struct stm32_spi_priv *priv) > > > > { > > > > struct device_node *node = priv->master.dev->device_node; > > > > int i; > > > > + int num_gpios; > > > > > > > > - priv->master.num_chipselect = of_gpio_named_count(node, "cs-gpios"); > > > > + num_gpios = of_gpio_named_count(node, "cs-gpios"); > > > > + if (num_gpios < 0) { > > > > + num_gpios = 0; > > > > + } > > > > + > > > > + priv->master.num_chipselect = num_gpios; > > > > priv->cs_gpios = xzalloc(sizeof(u32) * priv->master.num_chipselect); > > > > > > > > for (i = 0; i < priv->master.num_chipselect; i++) > > > > -- > > > > 2.39.0 > > > > > > > >