[Nexus 6  Original Android Development] AlxMAX:
Half a year ago, I have discovered some functions in the arch/arm/mach-msm sources where not all the return paths unlock the previously locked mutexes. I have produced a patch file which I have included at the end of this message because I could not find a way to attach it. Prior to the these corrections, my phone rebooted quite often. This patch seems to solve the problem. Could you, please have a look and tell me if the patch really solved problems or it was only my impression? As far as I could understand, the rule is to lock and unlock the mutex in the function where the resource is accessed and regulated by the mutex and not to let them locked when the function ends.

The patch looks like this:

diff -Naurp -x .git kernel_orig/arch/arm/mach-msm/msm_bus/msm_bus_arb.c kernel_modif/arch/arm/mach-msm/msm_bus/msm_bus_arb.c
--- kernel_orig/arch/arm/mach-msm/msm_bus/msm_bus_arb.c	2016-02-04 18:20:25.656691030 +0200
+++ kernel_modif/arch/arm/mach-msm/msm_bus/msm_bus_arb.c	2016-04-15 15:23:13.405028960 +0300
@@ -926,7 +926,8 @@ int msm_bus_scale_client_update_request(
pdata = client->pdata;
if (!pdata) {
MSM_BUS_ERR("Null pdata passed to update-request\n");
-	return -ENXIO;
+	ret = -ENXIO;
+	goto err;
}

if (index >= pdata->num_usecases) {
diff -Naurp -x .git kernel_orig/arch/arm/mach-msm/msm_bus/msm_bus_dbg.c kernel_modif/arch/arm/mach-msm/msm_bus/msm_bus_dbg.c
--- kernel_orig/arch/arm/mach-msm/msm_bus/msm_bus_dbg.c	2016-02-04 18:20:25.656691030 +0200
+++ kernel_modif/arch/arm/mach-msm/msm_bus/msm_bus_dbg.c	2016-04-15 15:23:13.405028960 +0300
@@ -708,6 +708,7 @@ static int __init msm_bus_debugfs_init(v
commit, (void *)fablist->name, &fabric_data_fops);
if (fablist->file == NULL) {
MSM_BUS_DBG("Cannot create files for commit data\n");
+ mutex_unlock(&msm_bus_dbg_fablist_lock);
goto err;
}
}
diff -Naurp -x .git kernel_orig/arch/arm/mach-msm/ocmem_sched.c kernel_modif/arch/arm/mach-msm/ocmem_sched.c
--- kernel_orig/arch/arm/mach-msm/ocmem_sched.c	2016-02-04 18:20:25.656691030 +0200
+++ kernel_modif/arch/arm/mach-msm/ocmem_sched.c	2016-04-15 15:23:13.417029178 +0300
@@ -1564,7 +1564,7 @@ int process_free(int id, struct ocmem_ha
/* free the allocation */
rc = do_free(req);
if (rc < 0)
-	return -EINVAL;
+ goto free_fail;
}

inc_ocmem_stat(zone_of(req), NR_FREES);
@@ -2147,7 +2147,10 @@ retry_allocate:

if (rc == OP_FAIL) {
inc_ocmem_stat(zone_of(req), NR_ALLOCATION_FAILS);
-	goto err_allocate_fail;
+ // avoid unnecessary mutex_unlock
+	// goto err_allocate_fail;
+ up_write(&req->rw_sem);
+ return -EINVAL;
}

if (rc == OP_RESCHED) {
diff -Naurp -x .git kernel_orig/arch/arm/mach-msm/subsystem_restart.c kernel_modif/arch/arm/mach-msm/subsystem_restart.c
--- kernel_orig/arch/arm/mach-msm/subsystem_restart.c	2016-02-04 18:20:25.664691179 +0200
+++ kernel_modif/arch/arm/mach-msm/subsystem_restart.c	2016-04-15 15:23:13.417029178 +0300
@@ -1229,10 +1229,14 @@ static struct subsys_soc_restart_order *
}
}

-	if (num == count && tmp->count == count)
+	if (num == count && tmp->count == count) {
+ mutex_unlock(&ssr_order_mutex);
return tmp;
-	else if (num)
+ }
+	else if (num) {
+ mutex_unlock(&ssr_order_mutex);
return ERR_PTR(-EINVAL);
+ }
}

order->count = count;