Showing error 1708

User: Jiri Slaby
Error type: Double Unlock
Error type description: Some lock is unlocked twice unintentionally in a sequence
File location: drivers/spi/spi.c
Line in file: 696
Project: Linux Kernel
Project version: 2.6.28
Tools: Smatch (1.59)
Entered: 2013-09-10 15:16:58 UTC


Source:

666        /* Use preallocated DMA-safe buffer.  We can't avoid copying here,
667         * (as a pure convenience thing), but we can keep heap costs
668         * out of the hot path ...
669         */
670        if ((n_tx + n_rx) > SPI_BUFSIZ)
671                return -EINVAL;
672
673        spi_message_init(&message);
674        memset(&x, 0, sizeof x);
675        x.len = n_tx + n_rx;
676        spi_message_add_tail(&x, &message);
677
678        /* ... unless someone else is using the pre-allocated buffer */
679        if (!mutex_trylock(&lock)) {
680                local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
681                if (!local_buf)
682                        return -ENOMEM;
683        } else
684                local_buf = buf;
685
686        memcpy(local_buf, txbuf, n_tx);
687        x.tx_buf = local_buf;
688        x.rx_buf = local_buf;
689
690        /* do the i/o */
691        status = spi_sync(spi, &message);
692        if (status == 0)
693                memcpy(rxbuf, x.rx_buf + n_tx, n_rx);
694
695        if (x.tx_buf == buf)
696                mutex_unlock(&lock);
697        else
698                kfree(local_buf);
699
700        return status;
701}
702EXPORT_SYMBOL_GPL(spi_write_then_read);
703
704/*-------------------------------------------------------------------------*/
705
706static int __init spi_init(void)
Show full sources