Commit 98334d2a authored by Alex Elder's avatar Alex Elder Committed by David S. Miller

net: ipa: separate memory validation from initialization

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0300df2d
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment