diff --git a/ui/events/devices/x11/device_data_manager_x11.cc b/ui/events/devices/x11/device_data_manager_x11.cc
index 584add043f7dd..b07e64944dd05 100644
--- a/ui/events/devices/x11/device_data_manager_x11.cc
+++ b/ui/events/devices/x11/device_data_manager_x11.cc
@@ -2,25 +2,24 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "ui/events/devices/x11/device_data_manager_x11.h"
 
 #include <stddef.h>
 
 #include <algorithm>
 #include <array>
+#include <cstdint>
 #include <utility>
 
 #include "base/at_exit.h"
 #include "base/command_line.h"
+#include "base/containers/auto_spanification_helper.h"
+#include "base/containers/span.h"
 #include "base/functional/bind.h"
 #include "base/functional/callback_helpers.h"
 #include "base/logging.h"
 #include "base/memory/singleton.h"
+#include "base/numerics/safe_conversions.h"
 #include "base/system/sys_info.h"
 #include "base/version.h"
 #include "build/build_config.h"
@@ -274,7 +273,7 @@ void DeviceDataManagerX11::UpdateDeviceList(x11::Connection* connection) {
   // Update the structs with new valuator information
   const XIDeviceList& info_list =
       ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(connection);
-  x11::Atom atoms[DT_LAST_ENTRY];
+  std::array<x11::Atom, DT_LAST_ENTRY> atoms;
   for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type)
     atoms[data_type] = x11::GetAtom(kCachedAtoms[data_type]);
 
@@ -760,17 +759,13 @@ void DeviceDataManagerX11::SetValuatorDataForTest(
   CHECK(index >= 0 && index < valuator_count_[device]);
   SetXinputMask(devev->valuator_mask.data(), index);
 
-  x11::Input::Fp3232* valuators = devev->axisvalues.data();
+  int valuator_offset = 0;
   for (int i = 0; i < index; ++i) {
     if (IsXinputMaskSet(devev->valuator_mask.data(), i))
-      valuators++;
-  }
-  for (int i = DT_LAST_ENTRY - 1; i > valuators - devev->axisvalues.data();
-       --i) {
-    devev->axisvalues[i] = devev->axisvalues[i - 1];
+      valuator_offset++;
   }
-
-  *valuators = DoubleToFp3232(value);
+  devev->axisvalues.insert(devev->axisvalues.begin() + valuator_offset,
+                           DoubleToFp3232(value));
 }
 
 void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid,
@@ -794,14 +789,14 @@ void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid,
 
 DeviceDataManagerX11::DataType DeviceDataManagerX11::UpdateValuatorClassDevice(
     const x11::Input::DeviceClass::Valuator& valuator_class_info,
-    x11::Atom* atoms,
+    base::span<x11::Atom> atoms,
     uint16_t deviceid) {
   DCHECK_LT(deviceid, kMaxDeviceNum);
-  x11::Atom* label =
-      std::find(atoms, atoms + DT_LAST_ENTRY, valuator_class_info.label);
-  if (label == atoms + DT_LAST_ENTRY)
+  auto it = std::find(atoms.begin(), atoms.end(), valuator_class_info.label);
+  if (it == atoms.end()) {
     return DT_LAST_ENTRY;
-  int data_type = label - atoms;
+  }
+  int data_type = it - atoms.begin();
   DCHECK_GE(data_type, 0);
   DCHECK_LT(data_type, DT_LAST_ENTRY);
 
diff --git a/ui/events/devices/x11/device_data_manager_x11.h b/ui/events/devices/x11/device_data_manager_x11.h
index 2717b042f86c1..114c98cf09267 100644
--- a/ui/events/devices/x11/device_data_manager_x11.h
+++ b/ui/events/devices/x11/device_data_manager_x11.h
@@ -13,6 +13,7 @@
 #include <set>
 #include <vector>
 
+#include "base/containers/span.h"
 #include "ui/events/devices/device_data_manager.h"
 #include "ui/events/devices/keyboard_device.h"
 #include "ui/events/devices/x11/events_devices_x11_export.h"
@@ -330,7 +331,7 @@ class EVENTS_DEVICES_X11_EXPORT DeviceDataManagerX11
   // Updates a device based on a Valuator class info.
   DataType UpdateValuatorClassDevice(
       const x11::Input::DeviceClass::Valuator& valuator_class_info,
-      x11::Atom* atoms,
+      base::span<x11::Atom> atoms,
       uint16_t deviceid);
 
   // Updates a device based on a Scroll class info.
