17.06.2020 04:41, Sowjanya Komatineni пишет:
...
> -static int tegra_mipi_wait(struct tegra_mipi *mipi)
> +int tegra_mipi_wait(struct tegra_mipi_device *device)
>  {
> +     struct tegra_mipi *mipi = device->mipi;
>       unsigned long timeout = jiffies + msecs_to_jiffies(250);
>       u32 value;
> +     int err;
> +
> +     err = clk_enable(device->mipi->clk);
> +     if (err < 0)
> +             return err;
> +
> +     mutex_lock(&device->mipi->lock);

The timeout variable should be assigned *after* taking the lock.

It will be better if you could use the read_poll_timeout() or
readl_relaxed_poll_timeout() here.

>       while (time_before(jiffies, timeout)) {
>               value = tegra_mipi_readl(mipi, MIPI_CAL_STATUS);
>               if ((value & MIPI_CAL_STATUS_ACTIVE) == 0 &&
>                   (value & MIPI_CAL_STATUS_DONE) != 0)
> -                     return 0;
> +                     goto done;
>  
>               usleep_range(10, 50);
>       }
>  
> -     return -ETIMEDOUT;
> +     err = -ETIMEDOUT;
> +done:
> +     mutex_unlock(&device->mipi->lock);
> +     clk_disable(device->mipi->clk);
> +     return err;
>  }
> +EXPORT_SYMBOL(tegra_mipi_wait);

Reply via email to