e_devicemgr: add missing mutex for device_list 46/303646/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 2 Jan 2024 02:48:20 +0000 (11:48 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Wed, 3 Jan 2024 04:19:03 +0000 (13:19 +0900)
missing_lock: Accessing e_devicemgr->device_list without holding lock _E_Devicemgr.device_list_mutex.
Elsewhere, _E_Devicemgr.device_list is written to with _E_Devicemgr.device_list_mutex held 2 out of 4 times
(2 of these accesses strongly imply that it is necessary).

Change-Id: I27bd2c6d7f1dd40cb18291164b87d9d75746c407
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_devicemgr_inputgen.c
src/bin/e_devicemgr_wl.c
src/bin/e_info_server.c

index f0accbf..4acac26 100644 (file)
@@ -801,6 +801,7 @@ _e_devicemgr_inputgen_hw_device_check(E_Devicemgr_Inputgen_Device_Data *device)
    if (!e_devicemgr_detent_is_detent(device->name))
      clas = device->clas;
 
+   g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
      {
         if ((dev->clas == clas) &&
@@ -808,9 +809,11 @@ _e_devicemgr_inputgen_hw_device_check(E_Devicemgr_Inputgen_Device_Data *device)
           {
              E_FREE(device->identifier);
              if (dev->identifier) device->identifier = strdup(dev->identifier);
+             g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
              return EINA_TRUE;
           }
      }
+   g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
 
    return EINA_FALSE;
 }
index d3baeda..87c2be5 100644 (file)
@@ -251,6 +251,7 @@ e_devicemgr_wl_detent_send_event(int detent)
    f_value = wl_fixed_from_double(detent * 1.0);
    wc = wl_resource_get_client(surface);
 
+   g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, input_dev)
      {
         if (!strncmp(input_dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
@@ -265,6 +266,7 @@ e_devicemgr_wl_detent_send_event(int detent)
                }
           }
      }
+   g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
 }
 
 void
@@ -698,6 +700,7 @@ _e_devicemgr_wl_cb_bind(struct wl_client *client, void *data, uint32_t version,
              continue;
           }
 
+        g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
         EINA_LIST_FOREACH(e_devicemgr->device_list, ll, dev)
           {
              device_res = wl_resource_create(client, &tizen_input_device_interface, 1, 0);
@@ -705,6 +708,7 @@ _e_devicemgr_wl_cb_bind(struct wl_client *client, void *data, uint32_t version,
                {
                   DMERR("Could not create tizen_input_device resource: %m");
                   wl_client_post_no_memory(client);
+                  g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
                   return;
                }
              device_user_data = E_NEW(E_Devicemgr_Input_Device_User_Data, 1);
@@ -713,6 +717,7 @@ _e_devicemgr_wl_cb_bind(struct wl_client *client, void *data, uint32_t version,
                   DMERR("Failed to allocate memory for input device user data\n");
                   wl_client_post_no_memory(client);
                   wl_resource_destroy(device_res);
+                  g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
                   return;
                }
              device_user_data->dev = dev;
@@ -730,6 +735,7 @@ _e_devicemgr_wl_cb_bind(struct wl_client *client, void *data, uint32_t version,
              tizen_input_device_manager_send_device_add(res, serial, dev->identifier, device_res, seat_res);
              tizen_input_device_send_device_info(device_res, dev->name, dev->clas, dev->subclas, &axes);
           }
+        g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
      }
 }
 
index 5f3b25b..d021d0c 100644 (file)
@@ -912,6 +912,7 @@ _input_msg_clients_append(Eldbus_Message_Iter *iter)
 
    eldbus_message_iter_arguments_append(iter, "a("VALUE_TYPE_FOR_INPUTDEV")", &array_of_input);
 
+   g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
    EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
      {
         Eldbus_Message_Iter *struct_of_input;
@@ -926,6 +927,7 @@ _input_msg_clients_append(Eldbus_Message_Iter *iter)
 
         eldbus_message_iter_container_close(array_of_input, struct_of_input);
      }
+   g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
    eldbus_message_iter_container_close(iter, array_of_input);
 }