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

Commit ca8bbfbd authored by Ravi Aravamudhan's avatar Ravi Aravamudhan
Browse files

diag: Do not add duplicate buffers to list in MEMORY_DEVICE_MODE



Diag maintains a buffer table in MEMORY_DEVICE_MODE for draining data
to userspace. Ensure that there are no duplicates while adding buffers
to this table. Also, remove an instance where the buffer used value
is incorrectly set as 0.

Change-Id: Idcfaed210ebb085b5086883375a2655dede10ba2
Signed-off-by: default avatarRavi Aravamudhan <aravamud@codeaurora.org>
parent 31f8dcc9
Loading
Loading
Loading
Loading
+28 −11
Original line number Original line Diff line number Diff line
@@ -110,14 +110,15 @@ void diag_md_close_all()
			entry = &ch->tbl[j];
			entry = &ch->tbl[j];
			if (entry->len <= 0)
			if (entry->len <= 0)
				continue;
				continue;
			spin_lock_irqsave(&ch->lock, flags);
			if (ch->ops && ch->ops->write_done)
			if (ch->ops && ch->ops->write_done)
				ch->ops->write_done(entry->buf, entry->len,
				ch->ops->write_done(entry->buf, entry->len,
						    entry->ctx, ch->ctx);
						    entry->ctx,
			spin_lock_irqsave(&entry->lock, flags);
						    DIAG_MEMORY_DEVICE_MODE);
			entry->buf = NULL;
			entry->buf = NULL;
			entry->len = 0;
			entry->len = 0;
			entry->ctx = 0;
			entry->ctx = 0;
			spin_unlock_irqrestore(&entry->lock, flags);
			spin_unlock_irqrestore(&ch->lock, flags);
		}
		}
	}
	}


@@ -138,8 +139,23 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx)
		return -EINVAL;
		return -EINVAL;


	ch = &diag_md[id];
	ch = &diag_md[id];

	spin_lock_irqsave(&ch->lock, flags);
	for (i = 0; i < ch->num_tbl_entries && !found; i++) {
		if (ch->tbl[i].buf != buf)
			continue;
		found = 1;
		pr_err_ratelimited("diag: trying to write the same buffer buf: %p, ctxt: %d len: %d at i: %d back to the table, proc: %d, mode: %d\n",
				   buf, ctx, ch->tbl[i].len,
				   i, id, driver->logging_mode);
	}
	spin_unlock_irqrestore(&ch->lock, flags);

	if (found)
		return -ENOMEM;

	spin_lock_irqsave(&ch->lock, flags);
	for (i = 0; i < ch->num_tbl_entries && !found; i++) {
	for (i = 0; i < ch->num_tbl_entries && !found; i++) {
		spin_lock_irqsave(&ch->tbl[i].lock, flags);
		if (ch->tbl[i].len == 0) {
		if (ch->tbl[i].len == 0) {
			ch->tbl[i].buf = buf;
			ch->tbl[i].buf = buf;
			ch->tbl[i].len = len;
			ch->tbl[i].len = len;
@@ -147,8 +163,8 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx)
			found = 1;
			found = 1;
			diag_ws_on_read(DIAG_WS_MUX, len);
			diag_ws_on_read(DIAG_WS_MUX, len);
		}
		}
		spin_unlock_irqrestore(&ch->tbl[i].lock, flags);
	}
	}
	spin_unlock_irqrestore(&ch->lock, flags);


	if (!found) {
	if (!found) {
		pr_err_ratelimited("diag: Unable to find an empty space in table, please reduce logging rate, proc: %d\n",
		pr_err_ratelimited("diag: Unable to find an empty space in table, please reduce logging rate, proc: %d\n",
@@ -240,15 +256,16 @@ int diag_md_copy_to_user(char __user *buf, int *pret, size_t buf_size)
			 */
			 */
			num_data++;
			num_data++;
drop_data:
drop_data:
			spin_lock_irqsave(&ch->lock, flags);
			if (ch->ops && ch->ops->write_done)
				ch->ops->write_done(entry->buf, entry->len,
				ch->ops->write_done(entry->buf, entry->len,
						    entry->ctx,
						    entry->ctx,
						    DIAG_MEMORY_DEVICE_MODE);
						    DIAG_MEMORY_DEVICE_MODE);
			diag_ws_on_copy(DIAG_WS_MUX);
			diag_ws_on_copy(DIAG_WS_MUX);
			spin_lock_irqsave(&entry->lock, flags);
			entry->buf = NULL;
			entry->buf = NULL;
			entry->len = 0;
			entry->len = 0;
			entry->ctx = 0;
			entry->ctx = 0;
			spin_unlock_irqrestore(&entry->lock, flags);
			spin_unlock_irqrestore(&ch->lock, flags);
		}
		}
	}
	}


@@ -279,7 +296,7 @@ int diag_md_init()
			ch->tbl[j].buf = NULL;
			ch->tbl[j].buf = NULL;
			ch->tbl[j].len = 0;
			ch->tbl[j].len = 0;
			ch->tbl[j].ctx = 0;
			ch->tbl[j].ctx = 0;
			spin_lock_init(&(ch->tbl[j].lock));
			spin_lock_init(&(ch->lock));
		}
		}
	}
	}


+1 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ struct diag_buf_tbl_t {
	unsigned char *buf;
	unsigned char *buf;
	int len;
	int len;
	int ctx;
	int ctx;
	spinlock_t lock;
};
};


struct diag_md_info {
struct diag_md_info {
@@ -39,6 +38,7 @@ struct diag_md_info {
	int ctx;
	int ctx;
	int mempool;
	int mempool;
	int num_tbl_entries;
	int num_tbl_entries;
	spinlock_t lock;
	struct diag_buf_tbl_t *tbl;
	struct diag_buf_tbl_t *tbl;
	struct diag_mux_ops *ops;
	struct diag_mux_ops *ops;
};
};