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

Unverified Commit b8b3179c authored by Divisha Bisht's avatar Divisha Bisht Committed by Michael Bestas
Browse files

smcinvoke: Rename size_add to smci_size_add



Rename size_add api of smcivoke driver to smci_size_add, as
smcinvoke's size_add is giving redefinition error with the size_add
api recently added in upstream patch 'overflow: Implement size_t
saturating arithmetic helpers'.
cherry-pick hash 4dab23059f51e324451b8fe02debc3df8812afd8.

Change-Id: I864c3065e63f53a3f4473edc24dc96d067dbfe60
Signed-off-by: default avatarDivisha Bisht <quic_divibish@quicinc.com>
parent 10ae1dae
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#define pr_fmt(fmt) "smcinvoke: %s: " fmt, __func__
@@ -559,30 +559,30 @@ static struct smcinvoke_cb_txn *find_cbtxn_locked(
}

/*
 * size_add saturates at SIZE_MAX. If integer overflow is detected,
 * smci_size_add saturates at SIZE_MAX. If integer overflow is detected,
 * this function would return SIZE_MAX otherwise normal a+b is returned.
 */
static inline size_t size_add(size_t a, size_t b)
static inline size_t smci_size_add(size_t a, size_t b)
{
	return (b > (SIZE_MAX - a)) ? SIZE_MAX : a + b;
}

/*
 * pad_size is used along with size_align to define a buffer overflow
 * smci_pad_size is used along with smci_size_align to define a buffer overflow
 * protected version of ALIGN
 */
static inline size_t pad_size(size_t a, size_t b)
static inline size_t smci_pad_size(size_t a, size_t b)
{
	return (~a + 1) % b;
}

/*
 * size_align saturates at SIZE_MAX. If integer overflow is detected, this
 * smci_size_align saturates at SIZE_MAX. If integer overflow is detected, this
 * function would return SIZE_MAX otherwise next aligned size is returned.
 */
static inline size_t size_align(size_t a, size_t b)
static inline size_t smci_size_align(size_t a, size_t b)
{
	return size_add(a, pad_size(a, b));
	return smci_size_add(a, smci_pad_size(a, b));
}

static uint16_t get_server_id(int cb_server_fd)
@@ -1216,9 +1216,9 @@ static size_t compute_in_msg_size(const struct smcinvoke_cmd_req *req,

	/* each buffer has to be 8 bytes aligned */
	while (i < OBJECT_COUNTS_NUM_buffers(req->counts))
		total_size = size_add(total_size,
		size_align(args_buf[i++].b.size, SMCINVOKE_ARGS_ALIGN_SIZE));

		total_size = smci_size_add(total_size,
				smci_size_align(args_buf[i++].b.size,
				SMCINVOKE_ARGS_ALIGN_SIZE));
	return PAGE_ALIGN(total_size);
}

@@ -1246,7 +1246,7 @@ static int marshal_in_invoke_req(const struct smcinvoke_cmd_req *req,
		return 0;

	FOR_ARGS(i, req->counts, BI) {
		offset = size_align(offset, SMCINVOKE_ARGS_ALIGN_SIZE);
		offset = smci_size_align(offset, SMCINVOKE_ARGS_ALIGN_SIZE);
		if ((offset > buf_size) ||
			(args_buf[i].b.size > (buf_size - offset)))
			goto out;
@@ -1262,7 +1262,7 @@ static int marshal_in_invoke_req(const struct smcinvoke_cmd_req *req,
		offset += args_buf[i].b.size;
	}
	FOR_ARGS(i, req->counts, BO) {
		offset = size_align(offset, SMCINVOKE_ARGS_ALIGN_SIZE);
		offset = smci_size_align(offset, SMCINVOKE_ARGS_ALIGN_SIZE);
		if ((offset > buf_size) ||
			(args_buf[i].b.size > (buf_size - offset)))
			goto out;
@@ -1313,7 +1313,7 @@ static int marshal_in_tzcb_req(const struct smcinvoke_cb_txn *cb_txn,
	user_req->argsize = sizeof(union smcinvoke_arg);

	FOR_ARGS(i, tzcb_req->hdr.counts, BI) {
		user_req_buf_offset = size_align(user_req_buf_offset,
		user_req_buf_offset = smci_size_align(user_req_buf_offset,
				SMCINVOKE_ARGS_ALIGN_SIZE);
		tmp_arg.b.size = tz_args[i].b.size;
		if ((tz_args[i].b.offset > tzcb_req_len) ||
@@ -1339,7 +1339,7 @@ static int marshal_in_tzcb_req(const struct smcinvoke_cb_txn *cb_txn,
		user_req_buf_offset += tmp_arg.b.size;
	}
	FOR_ARGS(i, tzcb_req->hdr.counts, BO) {
		user_req_buf_offset = size_align(user_req_buf_offset,
		user_req_buf_offset = smci_size_align(user_req_buf_offset,
				SMCINVOKE_ARGS_ALIGN_SIZE);

		tmp_arg.b.size = tz_args[i].b.size;