+ int ret = SR_ERR;
+ struct sr_context *context;
+
+ /* + 1 to handle when struct sr_context has no members. */
+ context = g_try_malloc0(sizeof(struct sr_context) + 1);
+
+ if (!context) {
+ ret = SR_ERR_MALLOC;
+ goto done;
+ }
+
+#ifdef HAVE_LIBUSB_1_0
+ ret = libusb_init(&context->libusb_ctx);
+ if (LIBUSB_SUCCESS != ret) {
+ sr_err("libusb_init() returned %s\n", libusb_error_name(ret));
+ goto done;
+ }
+#endif
+
+ *ctx = context;
+ ret = SR_OK;
+
+done:
+ return ret;