pickit2_spi.c: Add `pickit2_interrupt_transfer()` helper

Introduce the `pickit2_interrupt_transfer()` helper function to simplify
calls to the `libusb_interrupt_transfer()` function, as the last three
arguments are always the same: two constants and an unused output value.

Change-Id: I7ff704243b63a7ea2872fbc6e596190573dc13f6
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/65915
Original-Reviewed-by: Felix Singer <felixsinger@posteo.net>
Original-Tested-by: Thomas Heijligen <src@posteo.de>
Original-Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71471
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 0e189a9..e997163 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -89,20 +89,25 @@
 #define SCR_VDD_OFF             0xFE
 #define SCR_VDD_ON              0xFF
 
+static int pickit2_interrupt_transfer(libusb_device_handle *handle, unsigned char endpoint, unsigned char *data)
+{
+	int transferred;
+	return libusb_interrupt_transfer(handle, endpoint, data, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+}
+
 static int pickit2_get_firmware_version(void)
 {
 	int ret;
 	uint8_t command[CMD_LENGTH] = {CMD_GET_VERSION, CMD_END_OF_BUFFER};
-	int transferred;
 
-	ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command);
 
 	if (ret != 0) {
 		msg_perr("Command Get Firmware Version failed!\n");
 		return 1;
 	}
 
-	ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_IN, command, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_IN, command);
 
 	if (ret != 0) {
 		msg_perr("Command Get Firmware Version failed!\n");
@@ -148,8 +153,7 @@
 		voltage_selector * 13,
 		CMD_END_OF_BUFFER
 	};
-	int transferred;
-	int ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	int ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command);
 
 	if (ret != 0) {
 		msg_perr("Command Set Voltage failed!\n");
@@ -184,8 +188,7 @@
 		CMD_END_OF_BUFFER
 	};
 
-	int transferred;
-	int ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	int ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command);
 
 	if (ret != 0) {
 		msg_perr("Command Set SPI Speed failed!\n");
@@ -254,8 +257,7 @@
 	buf[i++] = CMD_UPLOAD_DATA;
 	buf[i++] = CMD_END_OF_BUFFER;
 
-	int transferred;
-	int ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	int ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf);
 
 	if (ret != 0) {
 		msg_perr("Send SPI failed!\n");
@@ -362,8 +364,7 @@
 		CMD_END_OF_BUFFER
 	};
 
-	int transferred;
-	int ret = libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command, CMD_LENGTH, &transferred, DFLT_TIMEOUT);
+	int ret = pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, command);
 
 	if (ret != 0) {
 		msg_perr("Command Shutdown failed!\n");
@@ -479,8 +480,7 @@
 
 	/* Perform basic setup.
 	 * Configure pin directions and logic levels, turn Vdd on, turn busy LED on and clear buffers. */
-	int transferred;
-	if (libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf, CMD_LENGTH, &transferred, DFLT_TIMEOUT) != 0) {
+	if (pickit2_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf) != 0) {
 		msg_perr("Command Setup failed!\n");
 		return 1;
 	}