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

Commit 4d2982a4 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "diag: Free the buffer for failed entry addition to buf table"

parents 08b61f51 0503da5d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define DIAG_DEBUG_POWER	0x0020
#define DIAG_DEBUG_BRIDGE	0x0040
#define DIAG_DEBUG_CMD_INFO	0x0080
#define DIAG_DEBUG_MHI		0x0100

#ifdef CONFIG_IPC_LOGGING
extern uint16_t diag_debug_mask;
+5 −1
Original line number Diff line number Diff line
@@ -112,8 +112,12 @@ static int diagfwd_bridge_mux_write_done(unsigned char *buf, int len,
	if (id < 0 || id >= NUM_REMOTE_DEV)
		return -EINVAL;
	ch = &bridge_info[buf_ctx];
	if (ch->dev_ops && ch->dev_ops->fwd_complete)
	if (ch->dev_ops && ch->dev_ops->fwd_complete) {
		DIAG_LOG(DIAG_DEBUG_MHI,
		"Write done completion received for buf %pK len:%d\n",
			buf, len);
		ch->dev_ops->fwd_complete(ch->id, ch->ctxt, buf, len, 0);
	}
	return 0;
}

+32 −4
Original line number Diff line number Diff line
@@ -151,6 +151,8 @@ static int mhi_buf_tbl_add(struct diag_mhi_info *mhi_info, int type,
	kmemleak_not_leak(item);

	item->buf = buf;
	DIAG_LOG(DIAG_DEBUG_MHI,
		 "buffer %pK added to table of ch: %s\n", buf, mhi_info->name);
	item->len = len;
	list_add_tail(&item->link, &ch->buf_tbl);

@@ -188,8 +190,11 @@ static void mhi_buf_tbl_remove(struct diag_mhi_info *mhi_info, int type,
		if (item->buf != buf)
			continue;
		list_del(&item->link);
		if (type == TYPE_MHI_READ_CH)
		if (type == TYPE_MHI_READ_CH) {
			DIAG_LOG(DIAG_DEBUG_MHI,
			"Callback received on buffer:%pK from mhi\n", buf);
			diagmem_free(driver, item->buf, mhi_info->mempool);
		}
		kfree(item);
		found = 1;
	}
@@ -226,6 +231,9 @@ static void mhi_buf_tbl_clear(struct diag_mhi_info *mhi_info)
			list_for_each_entry_safe(tp, tp_temp,
				&mhi_info->read_done_list, link) {
				if (tp->buf == buf) {
					DIAG_LOG(DIAG_DEBUG_MHI,
						"buffer:%pK removed from table for ch:%s\n",
						buf, mhi_info->name);
					list_del(&tp->link);
					kfree(tp);
					tp = NULL;
@@ -438,11 +446,17 @@ static void mhi_read_done_work_fn(struct work_struct *work)
			err = diag_remote_dev_read_done(mhi_info->dev_id, buf,
						  len);
			if (err) {
				DIAG_LOG(DIAG_DEBUG_MHI,
				"diag: remove buf entry %pK for failing flush to sink\n",
				buf);
				mhi_buf_tbl_remove(mhi_info, TYPE_MHI_READ_CH,
					buf, len);
				break;
			}
		} else {
			DIAG_LOG(DIAG_DEBUG_MHI,
			"diag: remove buf entry %pK if channel is closed\n",
				buf);
			mhi_buf_tbl_remove(mhi_info, TYPE_MHI_READ_CH, buf,
					   len);
			break;
@@ -475,10 +489,13 @@ static void mhi_read_work_fn(struct work_struct *work)
			spin_unlock_irqrestore(&read_ch->lock, flags);
			break;
		}
		DIAG_LOG(DIAG_DEBUG_MHI,
			 "Allocated buffer %pK, ch: %s\n", buf, mhi_info->name);

		err = mhi_buf_tbl_add(mhi_info, TYPE_MHI_READ_CH, buf,
				      DIAG_MDM_BUF_SIZE);
		if (err) {
			diagmem_free(driver, buf, mhi_info->mempool);
			spin_unlock_irqrestore(&read_ch->lock, flags);
			goto fail;
		}
@@ -499,6 +516,8 @@ static void mhi_read_work_fn(struct work_struct *work)

	return;
fail:
	DIAG_LOG(DIAG_DEBUG_MHI,
		"diag: remove buf entry %pK for error\n", buf);
	mhi_buf_tbl_remove(mhi_info, TYPE_MHI_READ_CH, buf, DIAG_MDM_BUF_SIZE);
	queue_work(mhi_info->mhi_wq, &mhi_info->read_work);
}
@@ -574,9 +593,9 @@ static int mhi_write(int token, int ch, unsigned char *buf, int len, int ctxt)
					buf, len, mhi_flags);
	spin_unlock_irqrestore(&ch_info->lock, flags);
	if (err) {
		pr_err_ratelimited("diag: In %s, cannot write to MHI channel %s, len %d, err: %d\n",
					__func__, diag_mhi[dev_idx][ch].name,
					len, err);
		DIAG_LOG(DIAG_DEBUG_MHI,
			"diag: Cannot write to MHI channel %s, len %d, err: %d\n",
			__func__, diag_mhi[dev_idx][ch].name, len, err);
		mhi_buf_tbl_remove(&diag_mhi[dev_idx][ch], TYPE_MHI_WRITE_CH,
					buf, len);
		goto fail;
@@ -606,6 +625,9 @@ static int mhi_fwd_complete(int token, int ch, unsigned char *buf,
	if (!buf)
		return -EINVAL;

	DIAG_LOG(DIAG_DEBUG_MHI,
		"Remove buffer from mhi read table after write completion %pK len:%d\n",
		buf, len);
	mhi_buf_tbl_remove(&diag_mhi[dev_idx][ch], TYPE_MHI_READ_CH,
				buf, len);
	queue_work(diag_mhi[dev_idx][ch].mhi_wq,
@@ -670,6 +692,9 @@ static void diag_mhi_read_cb(struct mhi_device *mhi_dev,
		list_for_each_entry_safe(item, temp,
				&mhi_info->read_ch.buf_tbl, link) {
			if (item->buf == buf) {
				DIAG_LOG(DIAG_DEBUG_MHI,
				"Callback received on buffer:%pK from mhi\n",
					buf);
				tp->buf = buf;
				tp->len = result->bytes_xferd;
				list_add_tail(&tp->link,
@@ -683,6 +708,9 @@ static void diag_mhi_read_cb(struct mhi_device *mhi_dev,
			queue_work(mhi_info->mhi_wq,
			&(mhi_info->read_done_work));
	} else {
		DIAG_LOG(DIAG_DEBUG_MHI,
		"Removing buf entry from read table if ch is not open %pK\n",
		buf);
		mhi_buf_tbl_remove(mhi_info, TYPE_MHI_READ_CH, buf,
					result->bytes_xferd);
	}