mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Elder <elder@linaro.org>
To: davem@davemloft.net, kuba@kernel.org
Cc: bjorn.andersson@linaro.org, evgreen@chromium.org,
	cpratapa@codeaurora.org, subashab@codeaurora.org,
	elder@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next 04/11] net: ipa: separate memory validation from initialization
Date: Wed,  9 Jun 2021 17:34:56 -0500	[thread overview]
Message-ID: <20210609223503.2649114-5-elder@linaro.org> (raw)
In-Reply-To: <20210609223503.2649114-1-elder@linaro.org>

Currently, memory regions are validated in the loop that initializes
them.  Instead, validate them separately.

Rename ipa_mem_valid() to be ipa_mem_valid_one().  Define a *new*
function named ipa_mem_valid() that performs validation of the array
of memory regions provided.  This function calls ipa_mem_valid_one()
for each region in turn.

Skip validation for any "empty" region descriptors, which have zero
size and are not preceded by any canary values.  Issue a warning for
such descriptors if the offset is non-zero.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_mem.c | 40 +++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ipa/ipa_mem.c b/drivers/net/ipa/ipa_mem.c
index effaa745a4061..62e1b8280d982 100644
--- a/drivers/net/ipa/ipa_mem.c
+++ b/drivers/net/ipa/ipa_mem.c
@@ -99,7 +99,7 @@ int ipa_mem_setup(struct ipa *ipa)
 	return 0;
 }
 
-static bool ipa_mem_valid(struct ipa *ipa, const struct ipa_mem *mem)
+static bool ipa_mem_valid_one(struct ipa *ipa, const struct ipa_mem *mem)
 {
 	struct device *dev = &ipa->pdev->dev;
 	enum ipa_mem_id mem_id = mem->id;
@@ -126,6 +126,31 @@ static bool ipa_mem_valid(struct ipa *ipa, const struct ipa_mem *mem)
 	return false;
 }
 
+/* Verify each defined memory region is valid. */
+static bool ipa_mem_valid(struct ipa *ipa)
+{
+	struct device *dev = &ipa->pdev->dev;
+	enum ipa_mem_id mem_id;
+
+	for (mem_id = 0; mem_id < ipa->mem_count; mem_id++) {
+		const struct ipa_mem *mem = &ipa->mem[mem_id];
+
+		/* Defined regions have non-zero size and/or canary count */
+		if (mem->size || mem->canary_count) {
+			if (ipa_mem_valid_one(ipa, mem))
+				continue;
+			return false;
+		}
+
+		/* It's harmless, but warn if an offset is provided */
+		if (mem->offset)
+			dev_warn(dev, "empty region %u has non-zero offset\n",
+				 mem_id);
+	}
+
+	return true;
+}
+
 /**
  * ipa_mem_config() - Configure IPA shared memory
  * @ipa:	IPA pointer
@@ -167,19 +192,18 @@ int ipa_mem_config(struct ipa *ipa)
 	ipa->zero_virt = virt;
 	ipa->zero_size = IPA_MEM_MAX;
 
-	/* Verify each defined memory region is valid, and if indicated
-	 * for the region, write "canary" values in the space prior to
-	 * the region's base address.
+	/* Make sure all defined memory regions are valid */
+	if (!ipa_mem_valid(ipa))
+		goto err_dma_free;
+
+	/* For each region, write "canary" values in the space prior to
+	 * the region's base address if indicated.
 	 */
 	for (mem_id = 0; mem_id < ipa->mem_count; mem_id++) {
 		const struct ipa_mem *mem = &ipa->mem[mem_id];
 		u16 canary_count;
 		__le32 *canary;
 
-		/* Validate all regions (even undefined ones) */
-		if (!ipa_mem_valid(ipa, mem))
-			goto err_dma_free;
-
 		/* Skip over undefined regions */
 		if (!mem->offset && !mem->size)
 			continue;
-- 
2.27.0


  parent reply	other threads:[~2021-06-09 22:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 22:34 [PATCH net-next 00/11] net: ipa: memory region rework, part 1 Alex Elder
2021-06-09 22:34 ` [PATCH net-next 01/11] net: ipa: define IPA_MEM_END_MARKER Alex Elder
2021-06-09 22:34 ` [PATCH net-next 02/11] net: ipa: store memory region id in descriptor Alex Elder
2021-06-09 22:34 ` [PATCH net-next 03/11] net: ipa: validate memory regions unconditionally Alex Elder
2021-06-09 22:34 ` Alex Elder [this message]
2021-06-09 22:34 ` [PATCH net-next 05/11] net: ipa: separate region range check from other validation Alex Elder
2021-06-09 22:34 ` [PATCH net-next 06/11] net: ipa: validate memory regions at init time Alex Elder
2021-06-09 22:34 ` [PATCH net-next 07/11] net: ipa: pass memory configuration data to ipa_mem_valid() Alex Elder
2021-06-09 22:35 ` [PATCH net-next 08/11] net: ipa: introduce ipa_mem_id_optional() Alex Elder
2021-06-09 22:35 ` [PATCH net-next 09/11] net: ipa: validate memory regions based on version Alex Elder
2021-06-09 22:35 ` [PATCH net-next 10/11] net: ipa: flag duplicate memory regions Alex Elder
2021-06-09 22:35 ` [PATCH net-next 11/11] net: ipa: use bitmap to check for missing regions Alex Elder
2021-06-09 23:10 ` [PATCH net-next 00/11] net: ipa: memory region rework, part 1 patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210609223503.2649114-5-elder@linaro.org \
    --to=elder@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=cpratapa@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=elder@kernel.org \
    --cc=evgreen@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=subashab@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®