Extended maximal board count to 7. Added board index validation.
authormartyy <triska@unipi.technology>
Thu, 7 Oct 2021 14:06:16 +0000 (14:06 +0000)
committermartyy <triska@unipi.technology>
Thu, 7 Oct 2021 14:06:16 +0000 (14:06 +0000)
modules/unipi/src/unipi_common.h
modules/unipi/src/unipi_platform.c
modules/unipi/src/unipi_spi.c

index 997f6447672ac0beeaff675fa122520f5a32499f..5294ba2a7eed9241e846761776d9b70a12f179f9 100644 (file)
@@ -54,7 +54,7 @@
 #endif
 #define NEURONSPI_MAJOR_VERSIONSTRING "Version 1.61:2021:07:13"
 
-#define NEURONSPI_MAX_DEVS                             3
+#define NEURONSPI_MAX_DEVS                             7       //Maximal SPI card count
 #define NEURONSPI_MAX_UART                             16
 #define NEURONSPI_BUFFER_MAX                   1152
 #define NEURONSPI_HEADER_LENGTH                10
index dd91d2f1350d4e2b00bec77cb87cbaa3ee029fd5..d482af7a88ff1ac2a7ee0e22bf4e3a14199d9c5d 100644 (file)
@@ -1603,7 +1603,7 @@ static u32 NEURONSPI_BOARD_E4AI4AOU4DI5RO_HW_DEFINITION_BLOCK[NEURONSPI_BOARD_E4
 struct neuronspi_board_combination NEURONSPI_BOARD_E4AI4AOU4DI5RO_HW_COMBINATION[] = {NEURONSPI_BOARD_E4AI4AOU4DI5RO_HW_DEFINITION};
 
 
-// E-16Di_U-14Di (M303)
+// IRIS_BOARD_ICDIS4
 #define IRIS_BOARD_ICDIS4_HW_DEFINITION_BLOCK_SIZE 28 //Reg count + 4
 static u32 IRIS_BOARD_ICDIS4_HW_DEFINITION_BLOCK[IRIS_BOARD_ICDIS4_HW_DEFINITION_BLOCK_SIZE] = {
                0, 10,  // Register block beginning and size
index 1b53e064ec507cecfde6464e8820cb2cd331fae1..a65ace3a33f330a9b698dea725481ca01df0bd07 100644 (file)
@@ -1282,6 +1282,19 @@ s32 neuronspi_spi_probe(struct spi_device *spi)
                //devtype = (struct neuronspi_devtype *)id_entry->driver_data;
        }
 
+       //Validate board index range
+       if ((n_spi->neuron_index < 0) || ((n_spi->neuron_index > NEURONSPI_MAX_DEVS))) {
+               printk(KERN_ERR "UNIPISPI: %s has invalid board index (%d)!\n", *(&spi->dev.of_node->full_name), n_spi->neuron_index);
+        kfree(n_spi);
+               return -ENODEV;
+       }
+
+       //Check if board index is not already assigned
+       if (neuronspi_s_dev[n_spi->neuron_index] != NULL) {
+               printk(KERN_ERR "UNIPISPI: %s has duplicit board index (%d)!\n", *(&spi->dev.of_node->full_name), n_spi->neuron_index);
+        kfree(n_spi);
+               return -ENODEV;
+       }
 
        // We perform an initial probe of registers 1000-1004 to identify the device, using a premade message
        neuronspi_spi_send_const_op(spi, &UNIPISPI_IDLE_MESSAGE, &recv_op, 0, NEURONSPI_DEFAULT_FREQ, 25);
@@ -1379,7 +1392,7 @@ s32 neuronspi_spi_probe(struct spi_device *spi)
        spi_set_drvdata(spi, n_spi);
        neuronspi_s_dev[n_spi->neuron_index] = spi;
 
-       if (neuronspi_probe_count == NEURONSPI_MAX_DEVS) {
+       if (neuronspi_probe_count == NEURONSPI_MAX_DEVS) {      //TODO - model guess procedure is obsolete - will be removed
                neuronspi_model_id = neuronspi_find_model_id(neuronspi_probe_count);
        }
        spin_unlock_irqrestore(neuronspi_probe_spinlock, flags);