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 <contact@xxxxxxxxxx>: > > 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 <contact@xxxxxxxxxx>: > > > > > > 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 <contact@xxxxxxxxxx> > > > --- > > > 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 > > > > > >