static uint profile_numbers[5] = {0, 1, 2, 3, 4};
 
+static void kone_profile_activated(struct kone_device *kone, uint new_profile)
+{
+       kone->actual_profile = new_profile;
+       kone->actual_dpi = kone->profiles[new_profile - 1].startup_dpi;
+}
+
 static int kone_receive(struct usb_device *usb_dev, uint usb_command,
                void *data, uint size)
 {
        if (difference) {
                retval = kone_set_settings(usb_dev,
                                (struct kone_settings const *)buf);
-               if (!retval)
-                       memcpy(&kone->settings, buf,
-                                       sizeof(struct kone_settings));
-       }
-       mutex_unlock(&kone->kone_lock);
+               if (retval) {
+                       mutex_unlock(&kone->kone_lock);
+                       return retval;
+               }
 
-       if (retval)
-               return retval;
+               memcpy(&kone->settings, buf, sizeof(struct kone_settings));
 
-       /*
-        * If we get here, treat settings as okay and update actual values
-        * according to startup_profile
-        */
-       kone->actual_profile = kone->settings.startup_profile;
-       kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
+               kone_profile_activated(kone, kone->settings.startup_profile);
+       }
+       mutex_unlock(&kone->kone_lock);
 
        return sizeof(struct kone_settings);
 }
                                goto exit_no_settings;
                        goto exit_unlock;
                }
+               /* calibration resets profile */
+               kone_profile_activated(kone, kone->settings.startup_profile);
        }
 
        retval = size;
        kone_set_settings_checksum(&kone->settings);
 
        retval = kone_set_settings(usb_dev, &kone->settings);
-
-       mutex_unlock(&kone->kone_lock);
-
-       if (retval)
+       if (retval) {
+               mutex_unlock(&kone->kone_lock);
                return retval;
+       }
 
        /* changing the startup profile immediately activates this profile */
-       kone->actual_profile = new_startup_profile;
-       kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi;
+       kone_profile_activated(kone, new_startup_profile);
 
+       mutex_unlock(&kone->kone_lock);
        return size;
 }
 
        if (retval)
                return retval;
 
-       kone->actual_profile = kone->settings.startup_profile;
-       kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi;
+       kone_profile_activated(kone, kone->settings.startup_profile);
 
        return 0;
 }