Merge remote-tracking branch 'spi/topic/msglen' into spi-next
[cascardo/linux.git] / drivers / spi / spi.c
index 7e3446c..7ed5c14 100644 (file)
@@ -774,7 +774,7 @@ static int spi_queued_transfer(struct spi_device *spi, struct spi_message *msg)
        msg->status = -EINPROGRESS;
 
        list_add_tail(&msg->queue, &master->queue);
-       if (master->running && !master->busy)
+       if (!master->busy)
                queue_kthread_work(&master->kworker, &master->pump_messages);
 
        spin_unlock_irqrestore(&master->queue_lock, flags);
@@ -1169,7 +1169,7 @@ int spi_register_master(struct spi_master *master)
        else {
                status = spi_master_initialize_queue(master);
                if (status) {
-                       device_unregister(&master->dev);
+                       device_del(&master->dev);
                        goto done;
                }
        }
@@ -1351,6 +1351,11 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
        struct spi_master *master = spi->master;
        struct spi_transfer *xfer;
 
+       if (list_empty(&message->transfers))
+               return -EINVAL;
+       if (!message->complete)
+               return -EINVAL;
+
        /* Half-duplex links include original MicroWire, and ones with
         * only one data pin like SPI_3WIRE (switches direction) or where
         * either MOSI or MISO is missing.  They can also be caused by
@@ -1378,8 +1383,13 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
                message->frame_length += xfer->len;
                if (!xfer->bits_per_word)
                        xfer->bits_per_word = spi->bits_per_word;
-               if (!xfer->speed_hz)
+               if (!xfer->speed_hz) {
                        xfer->speed_hz = spi->max_speed_hz;
+                       if (master->max_speed_hz &&
+                           xfer->speed_hz > master->max_speed_hz)
+                               xfer->speed_hz = master->max_speed_hz;
+               }
+
                if (master->bits_per_word_mask) {
                        /* Only 32 bits fit in the mask */
                        if (xfer->bits_per_word > 32)
@@ -1388,6 +1398,13 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
                                        BIT(xfer->bits_per_word - 1)))
                                return -EINVAL;
                }
+
+               if (xfer->speed_hz && master->min_speed_hz &&
+                   xfer->speed_hz < master->min_speed_hz)
+                       return -EINVAL;
+               if (xfer->speed_hz && master->max_speed_hz &&
+                   xfer->speed_hz > master->max_speed_hz)
+                       return -EINVAL;
        }
 
        message->spi = spi;