Skip to content

Commit

Permalink
of: overlay: Fix (un)locking in of_overlay_apply()
Browse files Browse the repository at this point in the history
The special overlay mutex is taken first, hence it should be released
last in the error path.

of_resolve_phandles() must be called with of_mutex held.  Without it, a
node and new phandle could be added via of_attach_node(), making the max
phandle wrong.

free_overlay_changeset() must be called with of_mutex held, if any
non-trivial cleanup is to be done.

Hence move "mutex_lock(&of_mutex)" up, as suggested by Frank, and merge
the two tail statements of the success and error paths, now they became
identical.

Note that while the two mutexes are adjacent, we still need both:
__of_changeset_apply_notify(), which is called by __of_changeset_apply()
unlocks of_mutex, then does notifications then locks of_mutex.  So the
mutex get released in the middle of of_overlay_apply()

Fixes: f948d6d ("of: overlay: avoid race condition between applying multiple overlays")
Signed-off-by: Geert Uytterhoeven <[email protected]>
Reviewed-by: Frank Rowand <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
geertu authored and robherring committed Dec 6, 2017
1 parent 1352f09 commit 5e47481
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions drivers/of/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,11 @@ int of_overlay_apply(struct device_node *tree, int *ovcs_id)
}

of_overlay_mutex_lock();
mutex_lock(&of_mutex);

ret = of_resolve_phandles(tree);
if (ret)
goto err_overlay_unlock;

mutex_lock(&of_mutex);
goto err_free_overlay_changeset;

ret = init_overlay_changeset(ovcs, tree);
if (ret)
Expand Down Expand Up @@ -754,18 +753,14 @@ int of_overlay_apply(struct device_node *tree, int *ovcs_id)
ret = ret_tmp;
}

mutex_unlock(&of_mutex);
of_overlay_mutex_unlock();

goto out;

err_overlay_unlock:
of_overlay_mutex_unlock();
goto out_unlock;

err_free_overlay_changeset:
free_overlay_changeset(ovcs);

out_unlock:
mutex_unlock(&of_mutex);
of_overlay_mutex_unlock();

out:
pr_debug("%s() err=%d\n", __func__, ret);
Expand Down

0 comments on commit 5e47481

Please sign in to comment.