Skip to content

Commit 933a62b

Browse files
committed
program: refactor program_find_bootable_partition
Refactor program_find_bootable_partition() function implementation. Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
1 parent 30ac3a8 commit 933a62b

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

program.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
219219
return 0;
220220
}
221221

222+
static struct program *program_find_partition(const char *partition)
223+
{
224+
struct program *program;
225+
const char *label;
226+
227+
for (program = programes; program; program = program->next) {
228+
label = program->label;
229+
if (!label)
230+
continue;
231+
232+
if (!strcmp(label, partition))
233+
return program;
234+
}
235+
236+
return NULL;
237+
}
238+
222239
/**
223240
* program_find_bootable_partition() - find one bootable partition
224241
*
@@ -232,25 +249,28 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
232249
int program_find_bootable_partition(bool *multiple_found)
233250
{
234251
struct program *program;
235-
const char *label;
236252
int part = -ENOENT;
237253

238254
*multiple_found = false;
239255

240-
for (program = programes; program; program = program->next) {
241-
label = program->label;
242-
if (!label)
243-
continue;
256+
program = program_find_partition("xbl");
257+
if (program)
258+
part = program->partition;
244259

245-
if (!strcmp(label, "xbl") || !strcmp(label, "xbl_a") ||
246-
!strcmp(label, "sbl1")) {
247-
if (part != -ENOENT) {
248-
*multiple_found = true;
249-
continue;
250-
}
260+
program = program_find_partition("xbl_a");
261+
if (program) {
262+
if (part != -ENOENT)
263+
*multiple_found = true;
264+
else
265+
part = program->partition;
266+
}
251267

268+
program = program_find_partition("sbl1");
269+
if (program) {
270+
if (part != -ENOENT)
271+
*multiple_found = true;
272+
else
252273
part = program->partition;
253-
}
254274
}
255275

256276
return part;

0 commit comments

Comments
 (0)