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

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

diag: Add protection while allocating memory during usb write



Add spin lock protection while allocating memory in diag_usb_write()
 to avoid race condition while allocating/freeing up the memory.

Change-Id: I0f068f163f6363b991413fad3d1e52cfc9d6af08
Signed-off-by: default avatarSreelakshmi Gownipalli <sgownipa@codeaurora.org>
parent ef4b332e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -529,6 +529,7 @@ int diag_usb_write(int id, unsigned char *buf, int len, int ctxt)
		return diag_usb_write_ext(usb_info, buf, len, ctxt);
	}

	spin_lock_irqsave(&usb_info->write_lock, flags);
	req = diagmem_alloc(driver, sizeof(struct diag_request),
			    usb_info->mempool);
	if (!req) {
@@ -542,6 +543,7 @@ int diag_usb_write(int id, unsigned char *buf, int len, int ctxt)
		pr_err_ratelimited("diag: In %s, cannot retrieve USB write ptrs for USB channel %s\n",
				   __func__, usb_info->name);
		diag_usb_buf_tbl_remove(usb_info, buf);
		spin_unlock_irqrestore(&usb_info->write_lock, flags);
		return -ENOMEM;
	}

@@ -554,10 +556,10 @@ int diag_usb_write(int id, unsigned char *buf, int len, int ctxt)
		pr_debug_ratelimited("diag: USB ch %s is not connected\n",
				     usb_info->name);
		diagmem_free(driver, req, usb_info->mempool);
		spin_unlock_irqrestore(&usb_info->write_lock, flags);
		return -ENODEV;
	}

	spin_lock_irqsave(&usb_info->write_lock, flags);
	if (diag_usb_buf_tbl_add(usb_info, buf, len, ctxt)) {
		DIAG_LOG(DIAG_DEBUG_MUX,
					"ERR! unable to add buf %pK to table\n",