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

Commit c7913f24 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "diag: Do not add duplicate buffers to list in MEMORY_DEVICE_MODE"

parents ac7816da ca8bbfbd
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -110,14 +110,15 @@ void diag_md_close_all()
			entry = &ch->tbl[j];
			if (entry->len <= 0)
				continue;
			spin_lock_irqsave(&ch->lock, flags);
			if (ch->ops && ch->ops->write_done)
				ch->ops->write_done(entry->buf, entry->len,
						    entry->ctx, ch->ctx);
			spin_lock_irqsave(&entry->lock, flags);
						    entry->ctx,
						    DIAG_MEMORY_DEVICE_MODE);
			entry->buf = NULL;
			entry->len = 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;

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

	if (!found) {
		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++;
drop_data:
			spin_lock_irqsave(&ch->lock, flags);
			if (ch->ops && ch->ops->write_done)
				ch->ops->write_done(entry->buf, entry->len,
						    entry->ctx,
						    DIAG_MEMORY_DEVICE_MODE);
			diag_ws_on_copy(DIAG_WS_MUX);
			spin_lock_irqsave(&entry->lock, flags);
			entry->buf = NULL;
			entry->len = 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].len = 0;
			ch->tbl[j].ctx = 0;
			spin_lock_init(&(ch->tbl[j].lock));
			spin_lock_init(&(ch->lock));
		}
	}

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

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