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

Commit bc490d94 authored by Hemant Kumar's avatar Hemant Kumar
Browse files

usb: gadget: gsi: Fix error handling when memory allocation fails



gsi_ctrl_pkt_alloc() API may return ERR_PTR(-ENOMEM) if memory
allocation fails. gsi_ctrl_send_cpkt_tomodem() and
gsi_ctrl_dev_write() APIs are checking against NULL value only.
Hence make sure that list_add() operation is not performed with
unallocated cpkt. This change fixes NULL pointer dereference
with __list_add.

Change-Id: I449066ba4f257d3c9c1eae7da7d4d520d4793382
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
parent 184e2ced
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -980,7 +980,7 @@ static int gsi_ctrl_send_cpkt_tomodem(struct f_gsi *gsi, void *buf, size_t len)
	}

	cpkt = gsi_ctrl_pkt_alloc(len, GFP_ATOMIC);
	if (!cpkt) {
	if (IS_ERR(cpkt)) {
		log_event_err("%s: Reset func pkt allocation failed", __func__);
		spin_unlock_irqrestore(&c_port->lock, flags);
		return -ENOMEM;
@@ -1149,7 +1149,7 @@ static ssize_t gsi_ctrl_dev_write(struct file *fp, const char __user *buf,
	}

	cpkt = gsi_ctrl_pkt_alloc(count, GFP_KERNEL);
	if (!cpkt) {
	if (IS_ERR(cpkt)) {
		log_event_err("failed to allocate ctrl pkt");
		return -ENOMEM;
	}