msm: ocmem: Add zone initialization checks
Since OCMEM zones can vary based on the target
add an initialization flag for each zone.
Also restrict each client to only operate on
active zones.
Change-Id: Iccac64fea277f833034ddfe71cce084060cfa16d
Signed-off-by: Naveen Ramaraj <nramaraj@codeaurora.org>
diff --git a/arch/arm/mach-msm/include/mach/ocmem_priv.h b/arch/arm/mach-msm/include/mach/ocmem_priv.h
index 49e283d..e20e768 100644
--- a/arch/arm/mach-msm/include/mach/ocmem_priv.h
+++ b/arch/arm/mach-msm/include/mach/ocmem_priv.h
@@ -36,6 +36,7 @@
};
struct ocmem_zone {
+ bool active;
int owner;
int active_regions;
int max_regions;
@@ -178,6 +179,7 @@
}
struct ocmem_zone *get_zone(unsigned);
+int zone_active(int);
unsigned long offset_to_phys(unsigned long);
unsigned long phys_to_offset(unsigned long);
unsigned long allocate_head(struct ocmem_zone *, unsigned long);
diff --git a/arch/arm/mach-msm/ocmem.c b/arch/arm/mach-msm/ocmem.c
index a9c3f4c..8819bd2 100644
--- a/arch/arm/mach-msm/ocmem.c
+++ b/arch/arm/mach-msm/ocmem.c
@@ -103,7 +103,7 @@
const char *get_name(int id)
{
if (!check_id(id))
- return NULL;
+ return "Unknown";
return client_names[id];
}
@@ -126,6 +126,15 @@
return offset + ocmem_pdata->base;
}
+inline int zone_active(int id)
+{
+ struct ocmem_zone *z = get_zone(id);
+ if (z)
+ return z->active == true ? 1 : 0;
+ else
+ return 0;
+}
+
static struct ocmem_plat_data *parse_static_config(struct platform_device *pdev)
{
struct ocmem_plat_data *pdata = NULL;
@@ -444,6 +453,7 @@
for (i = 0; i < pdata->nr_parts; i++) {
struct ocmem_partition *part = &pdata->parts[i];
zone = get_zone(part->id);
+ zone->active = false;
dev_dbg(dev, "Partition %d, start %lx, size %lx for %s\n",
i, part->p_start, part->p_size,
@@ -501,6 +511,7 @@
z_ops->allocate = allocate_head;
z_ops->free = free_head;
}
+ zone->active = true;
active_zones++;
if (active_zones == 1)
diff --git a/arch/arm/mach-msm/ocmem_api.c b/arch/arm/mach-msm/ocmem_api.c
index a5aed5e..2604d47 100644
--- a/arch/arm/mach-msm/ocmem_api.c
+++ b/arch/arm/mach-msm/ocmem_api.c
@@ -110,6 +110,12 @@
return NULL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return NULL;
+ }
+
if (size < OCMEM_MIN_ALLOC) {
pr_err("ocmem: requested size %lx must be at least %x\n",
size, OCMEM_MIN_ALLOC);
@@ -136,6 +142,12 @@
return NULL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return NULL;
+ }
+
if (size < OCMEM_MIN_ALLOC) {
pr_err("ocmem: requested size %lx must be at least %x\n",
size, OCMEM_MIN_ALLOC);
@@ -162,6 +174,12 @@
return NULL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return NULL;
+ }
+
/* Asynchronous API requires notifier registration */
if (!check_notifier(client_id)) {
pr_err("ocmem: No notifier registered for client %d\n",
@@ -202,6 +220,12 @@
return NULL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return NULL;
+ }
+
if (size < OCMEM_MIN_ALLOC) {
pr_err("ocmem: requested size %lx must be at least %x\n",
size, OCMEM_MIN_ALLOC);
@@ -226,6 +250,12 @@
return -EINVAL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return -EINVAL;
+ }
+
if (!buffer) {
pr_err("ocmem: Invalid buffer\n");
return -EINVAL;
@@ -240,6 +270,13 @@
return -EINVAL;
if (len >= buffer->len)
return -EINVAL;
+
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return -EINVAL;
+ }
+
return __ocmem_shrink(client_id, buffer, len);
}
@@ -282,6 +319,12 @@
return -EINVAL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return -EINVAL;
+ }
+
/* Asynchronous API requires notifier registration */
if (!check_notifier(client_id)) {
pr_err("ocmem: No notifier registered for client %d\n",
@@ -320,6 +363,12 @@
return -EINVAL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return -EINVAL;
+ }
+
/* Asynchronous API requires notifier registration */
if (!check_notifier(client_id)) {
pr_err("ocmem: No notifier registered for client %d\n",
diff --git a/arch/arm/mach-msm/ocmem_notifier.c b/arch/arm/mach-msm/ocmem_notifier.c
index 9fbcd73..644c809 100644
--- a/arch/arm/mach-msm/ocmem_notifier.c
+++ b/arch/arm/mach-msm/ocmem_notifier.c
@@ -82,6 +82,12 @@
return NULL;
}
+ if (!zone_active(client_id)) {
+ pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
+ get_name(client_id), client_id);
+ return NULL;
+ }
+
if (!nb) {
pr_err("ocmem: Invalid Notifier Block\n");
return NULL;