Re: [PATCH v11 2/2] spi: loongson: add bus driver for the loongson spi controller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 24, 2023 at 10:52 AM zhuyinbo <zhuyinbo@xxxxxxxxxxx> wrote:
> 在 2023/5/23 下午8:54, andy.shevchenko@xxxxxxxxx 写道:
> > Mon, May 22, 2023 at 03:10:30PM +0800, Yinbo Zhu kirjoitti:

...

> >> +static int loongson_spi_update_state(struct loongson_spi *loongson_spi,
> >> +                            struct spi_device *spi, struct spi_transfer *t)
> >> +{
> >> +    unsigned int hz;
> >> +
> >> +    if (t)
> >> +            hz = t->speed_hz;
> >
> > And if t is NULL? hz will be uninitialized. Don't you get a compiler warning?
> > (Always test your code with `make W=1 ...`)
>
> I always use `make W=1` and I don't find any warning, but that what you
> said was right and I will initial hz.

Note, if hz == 0 when t == NULL, you can unify that check with the below.

> >> +    if (hz && loongson_spi->hz != hz)

Something like

  if (t && _spi->hz != t->speed_hz)
    ...(..., t->speed_hz);

In such a case you won't need a temporary variable.

> >> +            loongson_spi_set_clk(loongson_spi, hz);
> >> +
> >> +    if ((spi->mode ^ loongson_spi->mode) & SPI_MODE_X_MASK)
> >> +            loongson_spi_set_mode(loongson_spi, spi);
> >> +
> >> +    return 0;
> >> +}

...

> > Why do you use deprecated naming? Can you use spi_controller* instead of
> > spi_master* in all cases?
>
> It seems was a personal code style issue and I don't find the
> differences between spi_controller and spi_master, Using spi_controller*
> is also acceptable to me and I will use spi_controller* instead of
> spi_master* in all cases.

Read this section (#4) in full
https://kernel.org/doc/html/latest/process/coding-style.html#naming

...

> >> +    clk = devm_clk_get_optional(dev, NULL);
> >> +    if (!IS_ERR(clk))
> >> +            spi->clk_rate = clk_get_rate(clk);
> >
> >> +    else
> >
> > Redundant. Just check for the error first as it's very usual pattern in the
> > Linux kernel.
>
> Like below ?
>
>          clk = devm_clk_get_optional(dev, NULL);
> -       if (!IS_ERR(clk))
> -               spi->clk_rate = clk_get_rate(clk);
> -       else
> +       if (IS_ERR(clk))
>                  return dev_err_probe(dev, PTR_ERR(clk), "unable to get
> clock\n");
>
> +       spi->clk_rate = clk_get_rate(clk);

Yes.

>          loongson_spi_reginit(spi);

> >> +            return dev_err_probe(dev, PTR_ERR(clk), "unable to get clock\n");

...

> >> +    ret = loongson_spi_init_master(dev, reg_base);
> >> +    if (ret)
> >> +            return dev_err_probe(dev, ret, "failed to initialize master\n");
> >> +
> >> +    return ret;
> >
> >       return 0;
>
> It seems was more appropriate that initialize ret then return ret.
> Do you think so ?

What do you mean and how does it help here?


...

> >> +#include <linux/spi/spi.h>
> >
> > This neither.
>
> That other .c file seems to need it and I will move it to other .c
> code file.

Yes, please do.

...

> >> +#define     LOONGSON_SPI_SPCR_REG   0x00
> >> +#define     LOONGSON_SPI_SPSR_REG   0x01
> >> +#define     LOONGSON_SPI_FIFO_REG   0x02
> >> +#define     LOONGSON_SPI_SPER_REG   0x03
> >> +#define     LOONGSON_SPI_PARA_REG   0x04
> >> +#define     LOONGSON_SPI_SFCS_REG   0x05
> >> +#define     LOONGSON_SPI_TIMI_REG   0x06
> >
> > Where is this used outside of the main driver?
>
> These definitions are only used in core.c

Then the obvious question, why are they located in *.h?

...

> >> +/* Bits definition for Loongson SPI register */
> >> +#define     LOONGSON_SPI_PARA_MEM_EN        BIT(0)
> >> +#define     LOONGSON_SPI_SPCR_CPHA  BIT(2)
> >> +#define     LOONGSON_SPI_SPCR_CPOL  BIT(3)
> >> +#define     LOONGSON_SPI_SPCR_SPE   BIT(6)
> >> +#define     LOONGSON_SPI_SPSR_WCOL  BIT(6)
> >> +#define     LOONGSON_SPI_SPSR_SPIF  BIT(7)

Similar question here.

-- 
With Best Regards,
Andy Shevchenko




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux