@@ -25,12 +25,15 @@ static constexpr StringView format_numerical = "{:04x}:{:02x}:{:02x}.{} {}: {}:{
25
25
static constexpr StringView format_textual = " {:04x}:{:02x}:{:02x}.{} {}: {} {} (rev {:02x})" sv;
26
26
static constexpr StringView format_region = " \t BAR {}: {} region @ {:#x}" sv;
27
27
28
- static u32 read_hex_string_from_bytebuffer (ByteBuffer const & buf)
28
+ static ErrorOr< u32 > read_hex_string_from_bytebuffer (ByteBuffer const & buf)
29
29
{
30
- // FIXME: Propagate errors.
31
- return AK::StringUtils::convert_to_uint_from_hex (
32
- ByteString (MUST (buf.slice (2 , buf.size () - 2 )).bytes ()))
33
- .release_value ();
30
+ auto slice_result = TRY (buf.slice (2 , buf.size () - 2 ));
31
+ auto hex_string = ByteString (slice_result.bytes ());
32
+ auto result = AK::StringUtils::convert_to_uint_from_hex (hex_string);
33
+ if (!result.has_value ())
34
+ return Error::from_string_literal (" Failed to convert hex string to number" );
35
+
36
+ return result.release_value ();
34
37
}
35
38
36
39
static u32 convert_sysfs_value_to_uint (ByteString const & value)
@@ -125,35 +128,35 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
125
128
dbgln (" Error: Could not read {}: {}" , vendor_id_filename, vendor_id_contents.error ());
126
129
continue ;
127
130
}
128
- u32 vendor_id = read_hex_string_from_bytebuffer (vendor_id_contents.value ());
131
+ u32 vendor_id = TRY ( read_hex_string_from_bytebuffer (vendor_id_contents.value () ));
129
132
130
133
auto device_id_contents = device_id_file.value ()->read_until_eof ();
131
134
if (device_id_contents.is_error ()) {
132
135
dbgln (" Error: Could not read {}: {}" , device_id_filename, device_id_contents.error ());
133
136
continue ;
134
137
}
135
- u32 device_id = read_hex_string_from_bytebuffer (device_id_contents.value ());
138
+ u32 device_id = TRY ( read_hex_string_from_bytebuffer (device_id_contents.value () ));
136
139
137
140
auto revision_id_contents = revision_id_file.value ()->read_until_eof ();
138
141
if (revision_id_contents.is_error ()) {
139
142
dbgln (" Error: Could not read {}: {}" , revision_id_filename, revision_id_contents.error ());
140
143
continue ;
141
144
}
142
- u32 revision_id = read_hex_string_from_bytebuffer (revision_id_contents.value ());
145
+ u32 revision_id = TRY ( read_hex_string_from_bytebuffer (revision_id_contents.value () ));
143
146
144
147
auto class_id_contents = class_id_file.value ()->read_until_eof ();
145
148
if (class_id_contents.is_error ()) {
146
149
dbgln (" Error: Could not read {}: {}" , class_id_filename, class_id_contents.error ());
147
150
continue ;
148
151
}
149
- u32 class_id = read_hex_string_from_bytebuffer (class_id_contents.value ());
152
+ u32 class_id = TRY ( read_hex_string_from_bytebuffer (class_id_contents.value () ));
150
153
151
154
auto subclass_id_contents = subclass_id_file.value ()->read_until_eof ();
152
155
if (subclass_id_contents.is_error ()) {
153
156
dbgln (" Error: Could not read {}: {}" , subclass_id_filename, subclass_id_contents.error ());
154
157
continue ;
155
158
}
156
- u32 subclass_id = read_hex_string_from_bytebuffer (subclass_id_contents.value ());
159
+ u32 subclass_id = TRY ( read_hex_string_from_bytebuffer (subclass_id_contents.value () ));
157
160
158
161
ByteString vendor_name;
159
162
ByteString device_name;
@@ -190,7 +193,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
190
193
continue ;
191
194
}
192
195
193
- u32 bar_value = read_hex_string_from_bytebuffer (bar_value_contents.value ());
196
+ u32 bar_value = TRY ( read_hex_string_from_bytebuffer (bar_value_contents.value () ));
194
197
if (bar_value == 0 )
195
198
continue ;
196
199
bool memory_region = ((bar_value & 1 ) == 0 );
0 commit comments