pw_software_update: Fix recursive lock acquisition in nanopb service

This commit fixes the same recursive lock acquisition as
I0ee7994fa5e093a05e349876406d0a2bd89fc3e7, in the nanopb software update
service.

The NotifyTransferSucceeded method acquires the same lock, leading to a
recursive lock acquisition. This commit fixes the issue by
by moving the outer lock acquisition into
the if statement that calls SET_ERROR, which is mutually exclusive with
the call to NotifyTransferSucceeded.

Change-Id: I30db9cc47ceca8af5b724018ee8b29cef6fc58cd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/112114
Pigweed-Auto-Submit: Eli Lipsitz <elipsitz@google.com>
Reviewed-by: Ali Zhang <alizhang@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_software_update/bundled_update_service.cc b/pw_software_update/bundled_update_service.cc
index 9cc4558..b424fab 100644
--- a/pw_software_update/bundled_update_service.cc
+++ b/pw_software_update/bundled_update_service.cc
@@ -132,11 +132,11 @@
 
 Status BundledUpdateService::SetTransferred(const pw_protobuf_Empty&,
                                             BundledUpdateStatus& response) {
-  std::lock_guard lock(mutex_);
   const BundledUpdateState state = status_.acquire()->state;
 
   if (state != pw_software_update_BundledUpdateState_Enum_TRANSFERRING &&
       state != pw_software_update_BundledUpdateState_Enum_INACTIVE) {
+    std::lock_guard lock(mutex_);
     SET_ERROR(pw_software_update_BundledUpdateResult_Enum_UNKNOWN_ERROR,
               "SetTransferred() can only be called from TRANSFERRING or "
               "INACTIVE state. State: %d",