Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9077d704 authored by Sreelakshmi Gownipalli's avatar Sreelakshmi Gownipalli Committed by Gerrit - the friendly Code Review server
Browse files

diag: Check if usb is connected before usb_diag_write()



Check if usb is connected before writing to USB so
that there is no race condition  between usb_connected
variable update when usb is disconnected and
the time when we actually read the usb_connected variable.

Change-Id: I19135b0f7d1eb70e0aaa2be3beb62408aded34c2
Signed-off-by: default avatarSreelakshmi Gownipalli <sgownipa@codeaurora.org>
parent f94bee71
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -284,11 +284,6 @@ int diag_usb_write(int id, unsigned char *buf, int len, int ctxt)
	}

	usb_info = &diag_usb[id];
	if (!usb_info->hdl || !usb_info->connected) {
		pr_debug_ratelimited("diag: USB ch %s is not connected\n",
				     usb_info->name);
		return -ENODEV;
	}

	req = diagmem_alloc(driver, sizeof(struct diag_request),
			    usb_info->mempool);
@@ -308,6 +303,12 @@ int diag_usb_write(int id, unsigned char *buf, int len, int ctxt)
	req->length = len;
	req->context = (void *)(uintptr_t)ctxt;

	if (!usb_info->hdl || !usb_info->connected) {
		pr_debug_ratelimited("diag: USB ch %s is not connected\n",
				     usb_info->name);
		diagmem_free(driver, req, usb_info->mempool);
		return -ENODEV;
	}
	err = usb_diag_write(usb_info->hdl, req);
	if (err) {
		pr_err_ratelimited("diag: In %s, error writing to usb channel %s, err: %d\n",