From: martyy Date: Thu, 7 Oct 2021 14:06:16 +0000 (+0000) Subject: Extended maximal board count to 7. Added board index validation. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=9051273318fa2c97cad3766397cd14faad6bd642;p=graphit%2Funipi-kernel.git Extended maximal board count to 7. Added board index validation. --- diff --git a/modules/unipi/src/unipi_common.h b/modules/unipi/src/unipi_common.h index 997f644..5294ba2 100644 --- a/modules/unipi/src/unipi_common.h +++ b/modules/unipi/src/unipi_common.h @@ -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 diff --git a/modules/unipi/src/unipi_platform.c b/modules/unipi/src/unipi_platform.c index dd91d2f..d482af7 100644 --- a/modules/unipi/src/unipi_platform.c +++ b/modules/unipi/src/unipi_platform.c @@ -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 diff --git a/modules/unipi/src/unipi_spi.c b/modules/unipi/src/unipi_spi.c index 1b53e06..a65ace3 100644 --- a/modules/unipi/src/unipi_spi.c +++ b/modules/unipi/src/unipi_spi.c @@ -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);