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

Commit c456dce3 authored by Manoj Prabhu B's avatar Manoj Prabhu B Committed by Gerrit - the friendly Code Review server
Browse files

diag: Avoid reallocating if buffer supports hdlc max pkt size



Instead of reallocating memory every time max pkt size for
hdlc encoding exceeds peripheral buffer size of 16K, reallocate
32k buffer once and reuse it.

Change-Id: I89ee577f2159dd68005447d12d8495f028b07d97
Signed-off-by: default avatarManoj Prabhu B <bmanoj@codeaurora.org>
parent fe245fe8
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ static int diag_add_hdlc_encoding(unsigned char *dest_buf, int *dest_len,

static int check_bufsize_for_encoding(struct diagfwd_buf_t *buf, uint32_t len)
{
	int i, ctx = 0;
	int i, ctx = 0, flag_64k = 0;
	uint32_t max_size = 0;
	unsigned long flags;
	unsigned char *temp_buf = NULL;
@@ -189,10 +189,11 @@ static int check_bufsize_for_encoding(struct diagfwd_buf_t *buf, uint32_t len)

	max_size = (2 * len) + 3;
	if (max_size > PERIPHERAL_BUF_SZ) {
		if (max_size > MAX_PERIPHERAL_HDLC_BUF_SZ) {
			pr_err("diag: In %s, max_size is going beyond limit %d\n",
		if (max_size > MAX_PERIPHERAL_BUF_SZ) {
			pr_err("diag: In %s, max_size (%d) is going beyond 32k\n",
			       __func__, max_size);
			max_size = MAX_PERIPHERAL_HDLC_BUF_SZ;
			flag_64k = 1;
		}

		mutex_lock(&driver->md_session_lock);
@@ -229,11 +230,19 @@ static int check_bufsize_for_encoding(struct diagfwd_buf_t *buf, uint32_t len)
				mutex_unlock(&driver->md_session_lock);
				return -ENOMEM;
			}
			DIAG_LOG(DIAG_DEBUG_PERIPHERALS,
			"Reallocated data buffer: %pK with size: %d\n",
			temp_buf, max_size);
			buf->data = temp_buf;
			buf->len = max_size;

			if (flag_64k)
				buf->len = MAX_PERIPHERAL_HDLC_BUF_SZ;
			else
				buf->len = MAX_PERIPHERAL_BUF_SZ;

			DIAG_LOG(DIAG_DEBUG_PERIPHERALS,
			"diag: Reallocated data buffer: %pK with size: %d, max_buf_len: %d, p: %d, t: %d, n: %d\n",
			temp_buf, max_size, buf->len,
			GET_BUF_PERIPHERAL(buf->ctxt),
			GET_BUF_TYPE(buf->ctxt),
			GET_BUF_NUM(buf->ctxt));
		}
		mutex_unlock(&driver->md_session_lock);
	}
+2 −2
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2019, 2021 The Linux Foundation. All rights reserved.
 */

#ifndef DIAGFWD_PERIPHERAL_H
@@ -7,7 +7,7 @@

#define PERIPHERAL_BUF_SZ		16384
#define MAX_PERIPHERAL_BUF_SZ		32768
#define MAX_PERIPHERAL_HDLC_BUF_SZ	65539
#define MAX_PERIPHERAL_HDLC_BUF_SZ	65536

#define TRANSPORT_UNKNOWN		-1
#define TRANSPORT_SOCKET		0