tree: Check properly if libusb is initialized

The dediprog, developerbox_spi and stlinkv3_spi programmers only check
if the libusb_context is not NULL after the initialization. But
following the API documentation from libusb, the context is undefined
unless the init function returns 0. Fix this by checking the return
value instead of the libusb_context to see if the initialization was
successful.

https://libusb.sourceforge.io/api-1.0/group__libusb__lib.html

Change-Id: Ia45ccd3fa2239dfccd821be46a09c86426cb22e5
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/66460
Original-Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71475
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/dediprog.c b/dediprog.c
index 2d266d4..e18356b 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1205,8 +1205,8 @@
 	dp_data->devicetype = DEV_UNKNOWN;
 
 	/* Here comes the USB stuff. */
-	libusb_init(&dp_data->usb_ctx);
-	if (!dp_data->usb_ctx) {
+	ret = libusb_init(&dp_data->usb_ctx);
+	if (ret) {
 		msg_perr("Could not initialize libusb!\n");
 		goto init_err_exit;
 	}
diff --git a/developerbox_spi.c b/developerbox_spi.c
index 5a9c08d..d15cc7a 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -138,8 +138,7 @@
 
 static int developerbox_spi_init(void)
 {
-	libusb_init(&usb_ctx);
-	if (!usb_ctx) {
+	if (libusb_init(&usb_ctx)) {
 		msg_perr("Could not initialize libusb!\n");
 		return 1;
 	}
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 2d3ce22..68790cf 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -456,8 +456,7 @@
 	int ret = 1;
 	int devIndex = 0;
 
-	libusb_init(&usb_ctx);
-	if (!usb_ctx) {
+	if (libusb_init(&usb_ctx)) {
 		msg_perr("Could not initialize libusb!\n");
 		return 1;
 	}