]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
drivers/linuxspidev: fix use of uninitialized speed variable
authorTomas Vanek <vanekt@fbl.cz>
Mon, 3 Feb 2025 19:28:49 +0000 (20:28 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Tue, 11 Feb 2025 11:56:39 +0000 (11:56 +0000)
Valgrind reported
== Syscall param ioctl(generic) points to uninitialised byte(s)
==    at 0x4ABF990: ioctl (ioctl.S:26)
==    by 0x19D00B: spidev_speed (linuxspidev.c:181)
==    by 0x19D00B: spidev_init (linuxspidev.c:307)

Indeed, spidev_init() uses adapter_get_speed(), it calls
adapter_khz_to_speed() and it returns early without setting
the output parameter if adapter is not initialized.
Of course the adapter initialized flag is not set until
spidev_init() returns.

Simply drop this code as the adapter infrastructure initializes
adapter speed just after spidev_init() return.

Change-Id: I26f011ae59fc942a34d9bb517f467c22f735091d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Fixes: 83e0293f7ba3 ("Add Linux SPI device SWD adapter support")
Reviewed-on: https://review.openocd.org/c/openocd/+/8733
Tested-by: jenkins
Reviewed-by: Richard Pasek <rpasek@google.com>
src/jtag/drivers/linuxspidev.c

index 94a0c510aff6e5d9720f3bcb97d5c9f7fce21a35..73d5e8bed4597b24b014bd5102ace4cf7cc85db4 100644 (file)
@@ -307,18 +307,6 @@ static int spidev_init(void)
        LOG_INFO("Opened SPI device at %s in mode 0x%" PRIx32 " with %" PRIu8 " bits ",
                spi_path, spi_mode, spi_bits);
 
-       // Set SPI read and write max speed.
-       int speed;
-       ret = adapter_get_speed(&speed);
-       if (ret != ERROR_OK) {
-               LOG_ERROR("Failed to get adapter speed");
-               return ERROR_JTAG_INIT_FAILED;
-       }
-
-       ret = spidev_speed(speed);
-       if (ret != ERROR_OK)
-               return ERROR_JTAG_INIT_FAILED;
-
        if (max_queue_entries == 0) {
                ret = spidev_alloc_queue(MAX_QUEUE_ENTRIES);
                if (ret != ERROR_OK)