Skip to content

Commit 508364b

Browse files
committed
Fix SPI: IOError: [Errno 22] Invalid argument in xfer and xfer2 functions
1 parent bc37399 commit 508364b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

source/spimodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ SPI_xfer(SPI *self, PyObject *args)
237237
delay = 0;
238238
}
239239

240-
xferptr = (struct spi_ioc_transfer*) malloc(sizeof(struct spi_ioc_transfer) * len);
240+
xferptr = (struct spi_ioc_transfer*) calloc(len, sizeof(struct spi_ioc_transfer));
241241
txbuf = malloc(sizeof(__u8) * len);
242242
rxbuf = malloc(sizeof(__u8) * len);
243243

@@ -300,7 +300,7 @@ SPI_xfer2(SPI *self, PyObject *args)
300300
int status;
301301
uint16_t ii, len;
302302
PyObject *list;
303-
struct spi_ioc_transfer xfer;
303+
struct spi_ioc_transfer xfer = {0};
304304
uint8_t *txbuf, *rxbuf;
305305

306306
if (!PyArg_ParseTuple(args, "O:xfer2", &list))

0 commit comments

Comments
 (0)