Skip to content

Commit 2702e07

Browse files
Dishank Jogikawasaki
authored andcommitted
Fixed several coding style issues in the efi driver as reported by checkpatch.pl:
- Moved assignments out of 'if' conditions. - Removed trailing whitespaces. - Fixed indentation and spacing inconsistencies. - Replaced 'unsigned' with 'unsigned int'. These changes improve readability and follow kernel coding style guidelines. Reviewed-by: Manish Narani <[email protected]> Signed-off-by: Dishank Jogi <[email protected]>
1 parent 1cd470e commit 2702e07

File tree

1 file changed

+80
-73
lines changed

1 file changed

+80
-73
lines changed

block/partitions/efi.c

Lines changed: 80 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* - Ported to 2.5.7-pre1 and 2.5.7-dj2
2424
* - Applied patch to avoid fault in alternate header handling
2525
* - cleaned up find_valid_gpt
26-
* - On-disk structure and copy in memory is *always* LE now -
26+
* - On-disk structure and copy in memory is *always* LE now -
2727
* swab fields as needed
2828
* - remove print_gpt_header()
2929
* - only use first max_p partition entries, to keep the kernel minor number
@@ -40,7 +40,7 @@
4040
* - moved le_efi_guid_to_cpus() back into this file. GPT is the only
4141
* thing that keeps EFI GUIDs on disk.
4242
* - Changed gpt structure names and members to be simpler and more Linux-like.
43-
*
43+
*
4444
* Wed Oct 17 2001 Matt Domsch <[email protected]>
4545
* - Removed CONFIG_DEVFS_VOLUMES_UUID code entirely per Martin Wilck
4646
*
@@ -65,7 +65,7 @@
6565
*
6666
* Wed Jun 6 2001 Martin Wilck <[email protected]>
6767
* - added devfs volume UUID support (/dev/volumes/uuids) for
68-
* mounting file systems by the partition GUID.
68+
* mounting file systems by the partition GUID.
6969
*
7070
* Tue Dec 5 2000 Matt Domsch <[email protected]>
7171
* - Moved crc32() to linux/lib, added efi_crc32().
@@ -110,7 +110,7 @@ __setup("gpt", force_gpt_fn);
110110
* @len: length of buf
111111
*
112112
* Description: Returns EFI-style CRC32 value for @buf
113-
*
113+
*
114114
* This function uses the little endian Ethernet polynomial
115115
* but seeds the function with ~0, and xor's with ~0 at the end.
116116
* Note, the EFI Specification, v1.02, has a reference to
@@ -125,7 +125,7 @@ efi_crc32(const void *buf, unsigned long len)
125125
/**
126126
* last_lba(): return number of last logical block of device
127127
* @disk: block device
128-
*
128+
*
129129
* Description: Returns last LBA value on success, 0 on error.
130130
* This is stored (by sd and ide-geometry) in
131131
* the part[0] entry for this disk, and is the number of
@@ -240,20 +240,21 @@ static size_t read_lba(struct parsed_partitions *state,
240240
(queue_logical_block_size(state->disk->queue) / 512);
241241

242242
if (!buffer || lba > last_lba(state->disk))
243-
return 0;
243+
return 0;
244244

245245
while (count) {
246246
int copied = 512;
247247
Sector sect;
248248
unsigned char *data = read_part_sector(state, n++, &sect);
249+
249250
if (!data)
250251
break;
251252
if (copied > count)
252253
copied = count;
253254
memcpy(buffer, data, copied);
254255
put_dev_sector(sect);
255256
buffer += copied;
256-
totalreadcount +=copied;
257+
totalreadcount += copied;
257258
count -= copied;
258259
}
259260
return totalreadcount;
@@ -263,7 +264,7 @@ static size_t read_lba(struct parsed_partitions *state,
263264
* alloc_read_gpt_entries(): reads partition entries from disk
264265
* @state: disk parsed partitions
265266
* @gpt: GPT header
266-
*
267+
*
267268
* Description: Returns ptes on success, NULL on error.
268269
* Allocates space for PTEs based on information found in @gpt.
269270
* Notes: remember to free pte when you're done!
@@ -278,7 +279,7 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
278279
return NULL;
279280

280281
count = (size_t)le32_to_cpu(gpt->num_partition_entries) *
281-
le32_to_cpu(gpt->sizeof_partition_entry);
282+
le32_to_cpu(gpt->sizeof_partition_entry);
282283
if (!count)
283284
return NULL;
284285
pte = kmalloc(count, GFP_KERNEL);
@@ -288,7 +289,7 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
288289
if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
289290
(u8 *) pte, count) < count) {
290291
kfree(pte);
291-
pte=NULL;
292+
pte = NULL;
292293
return NULL;
293294
}
294295
return pte;
@@ -298,7 +299,7 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
298299
* alloc_read_gpt_header(): Allocates GPT header, reads into it from disk
299300
* @state: disk parsed partitions
300301
* @lba: the Logical Block Address of the partition table
301-
*
302+
*
302303
* Description: returns GPT header on success, NULL on error. Allocates
303304
* and fills a GPT header starting at @ from @state->disk.
304305
* Note: remember to free gpt when finished with it.
@@ -307,15 +308,15 @@ static gpt_header *alloc_read_gpt_header(struct parsed_partitions *state,
307308
u64 lba)
308309
{
309310
gpt_header *gpt;
310-
unsigned ssz = queue_logical_block_size(state->disk->queue);
311+
unsigned int ssz = queue_logical_block_size(state->disk->queue);
311312

312313
gpt = kmalloc(ssz, GFP_KERNEL);
313314
if (!gpt)
314315
return NULL;
315316

316317
if (read_lba(state, lba, (u8 *) gpt, ssz) < ssz) {
317318
kfree(gpt);
318-
gpt=NULL;
319+
gpt = NULL;
319320
return NULL;
320321
}
321322

@@ -340,7 +341,8 @@ static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
340341

341342
if (!ptes)
342343
return 0;
343-
if (!(*gpt = alloc_read_gpt_header(state, lba)))
344+
*gpt = alloc_read_gpt_header(state, lba);
345+
if (!*gpt)
344346
return 0;
345347

346348
/* Check the GUID Partition Table signature */
@@ -427,7 +429,8 @@ static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
427429
goto fail;
428430
}
429431

430-
if (!(*ptes = alloc_read_gpt_entries(state, *gpt)))
432+
*ptes = alloc_read_gpt_entries(state, *gpt);
433+
if (!*ptes)
431434
goto fail;
432435

433436
/* Check the GUID Partition Entry Array CRC */
@@ -475,69 +478,74 @@ is_pte_valid(const gpt_entry *pte, const u64 lastlba)
475478
*
476479
* Description: Returns nothing. Sanity checks pgpt and agpt fields
477480
* and prints warnings on discrepancies.
478-
*
481+
*
479482
*/
480483
static void
481484
compare_gpts(gpt_header *pgpt, gpt_header *agpt, u64 lastlba)
482485
{
483486
int error_found = 0;
487+
484488
if (!pgpt || !agpt)
485489
return;
490+
486491
if (le64_to_cpu(pgpt->my_lba) != le64_to_cpu(agpt->alternate_lba)) {
487492
pr_warn("GPT:Primary header LBA != Alt. header alternate_lba\n");
488493
pr_warn("GPT:%lld != %lld\n",
489-
(unsigned long long)le64_to_cpu(pgpt->my_lba),
490-
(unsigned long long)le64_to_cpu(agpt->alternate_lba));
494+
(unsigned long long)le64_to_cpu(pgpt->my_lba),
495+
(unsigned long long)le64_to_cpu(agpt->alternate_lba));
491496
error_found++;
492497
}
493498
if (le64_to_cpu(pgpt->alternate_lba) != le64_to_cpu(agpt->my_lba)) {
494499
pr_warn("GPT:Primary header alternate_lba != Alt. header my_lba\n");
495500
pr_warn("GPT:%lld != %lld\n",
496-
(unsigned long long)le64_to_cpu(pgpt->alternate_lba),
497-
(unsigned long long)le64_to_cpu(agpt->my_lba));
501+
(unsigned long long)le64_to_cpu(pgpt->alternate_lba),
502+
(unsigned long long)le64_to_cpu(agpt->my_lba));
498503
error_found++;
499504
}
505+
500506
if (le64_to_cpu(pgpt->first_usable_lba) !=
501-
le64_to_cpu(agpt->first_usable_lba)) {
507+
le64_to_cpu(agpt->first_usable_lba)) {
502508
pr_warn("GPT:first_usable_lbas don't match.\n");
503509
pr_warn("GPT:%lld != %lld\n",
504-
(unsigned long long)le64_to_cpu(pgpt->first_usable_lba),
505-
(unsigned long long)le64_to_cpu(agpt->first_usable_lba));
510+
(unsigned long long)le64_to_cpu(pgpt->first_usable_lba),
511+
(unsigned long long)le64_to_cpu(agpt->first_usable_lba));
506512
error_found++;
507513
}
514+
508515
if (le64_to_cpu(pgpt->last_usable_lba) !=
509-
le64_to_cpu(agpt->last_usable_lba)) {
516+
le64_to_cpu(agpt->last_usable_lba)) {
510517
pr_warn("GPT:last_usable_lbas don't match.\n");
511518
pr_warn("GPT:%lld != %lld\n",
512-
(unsigned long long)le64_to_cpu(pgpt->last_usable_lba),
513-
(unsigned long long)le64_to_cpu(agpt->last_usable_lba));
519+
(unsigned long long)le64_to_cpu(pgpt->last_usable_lba),
520+
(unsigned long long)le64_to_cpu(agpt->last_usable_lba));
514521
error_found++;
515522
}
516523
if (efi_guidcmp(pgpt->disk_guid, agpt->disk_guid)) {
517524
pr_warn("GPT:disk_guids don't match.\n");
518525
error_found++;
519526
}
520-
if (le32_to_cpu(pgpt->num_partition_entries) !=
521-
le32_to_cpu(agpt->num_partition_entries)) {
527+
if (le32_to_cpu(pgpt->num_partition_entries)
528+
!= le32_to_cpu(agpt->num_partition_entries)) {
522529
pr_warn("GPT:num_partition_entries don't match: "
523-
"0x%x != 0x%x\n",
524-
le32_to_cpu(pgpt->num_partition_entries),
525-
le32_to_cpu(agpt->num_partition_entries));
530+
"0x%x != 0x%x\n",
531+
le32_to_cpu(pgpt->num_partition_entries),
532+
le32_to_cpu(agpt->num_partition_entries));
526533
error_found++;
527534
}
535+
528536
if (le32_to_cpu(pgpt->sizeof_partition_entry) !=
529-
le32_to_cpu(agpt->sizeof_partition_entry)) {
530-
pr_warn("GPT:sizeof_partition_entry values don't match: "
537+
le32_to_cpu(agpt->sizeof_partition_entry)) {
538+
pr_warn("GPT:sizeof_partition_entry values don't match: "
531539
"0x%x != 0x%x\n",
532-
le32_to_cpu(pgpt->sizeof_partition_entry),
540+
le32_to_cpu(pgpt->sizeof_partition_entry),
533541
le32_to_cpu(agpt->sizeof_partition_entry));
534542
error_found++;
535543
}
536544
if (le32_to_cpu(pgpt->partition_entry_array_crc32) !=
537-
le32_to_cpu(agpt->partition_entry_array_crc32)) {
545+
le32_to_cpu(agpt->partition_entry_array_crc32)) {
538546
pr_warn("GPT:partition_entry_array_crc32 values don't match: "
539547
"0x%x != 0x%x\n",
540-
le32_to_cpu(pgpt->partition_entry_array_crc32),
548+
le32_to_cpu(pgpt->partition_entry_array_crc32),
541549
le32_to_cpu(agpt->partition_entry_array_crc32));
542550
error_found++;
543551
}
@@ -559,7 +567,6 @@ compare_gpts(gpt_header *pgpt, gpt_header *agpt, u64 lastlba)
559567

560568
if (error_found)
561569
pr_warn("GPT: Use GNU Parted to correct GPT errors.\n");
562-
return;
563570
}
564571

565572
/**
@@ -594,8 +601,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
594601
return 0;
595602

596603
lastlba = last_lba(state->disk);
597-
if (!force_gpt) {
598-
/* This will be added to the EFI Spec. per Intel after v1.02. */
604+
if (!force_gpt) {
605+
/* This will be added to the EFI Spec. per Intel after v1.02. */
599606
legacymbr = kzalloc(sizeof(*legacymbr), GFP_KERNEL);
600607
if (!legacymbr)
601608
goto fail;
@@ -614,12 +621,13 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
614621

615622
good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
616623
&pgpt, &pptes);
617-
if (good_pgpt)
624+
if (good_pgpt)
618625
good_agpt = is_gpt_valid(state,
619-
le64_to_cpu(pgpt->alternate_lba),
620-
&agpt, &aptes);
621-
if (!good_agpt && force_gpt)
622-
good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
626+
le64_to_cpu(pgpt->alternate_lba),
627+
&agpt, &aptes);
628+
629+
if (!good_agpt && force_gpt)
630+
good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
623631

624632
if (!good_agpt && force_gpt && fops->alternative_gpt_sector) {
625633
sector_t agpt_sector;
@@ -631,39 +639,38 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
631639
&agpt, &aptes);
632640
}
633641

634-
/* The obviously unsuccessful case */
635-
if (!good_pgpt && !good_agpt)
636-
goto fail;
642+
/* The obviously unsuccessful case */
643+
if (!good_pgpt && !good_agpt)
644+
goto fail;
637645

638-
compare_gpts(pgpt, agpt, lastlba);
646+
compare_gpts(pgpt, agpt, lastlba);
639647

640-
/* The good cases */
641-
if (good_pgpt) {
642-
*gpt = pgpt;
643-
*ptes = pptes;
644-
kfree(agpt);
645-
kfree(aptes);
648+
/* The good cases */
649+
if (good_pgpt) {
650+
*gpt = pgpt;
651+
*ptes = pptes;
652+
kfree(agpt);
653+
kfree(aptes);
646654
if (!good_agpt)
647-
pr_warn("Alternate GPT is invalid, using primary GPT.\n");
648-
return 1;
649-
}
650-
else if (good_agpt) {
651-
*gpt = agpt;
652-
*ptes = aptes;
653-
kfree(pgpt);
654-
kfree(pptes);
655+
pr_warn("Alternate GPT is invalid, using primary GPT.\n");
656+
return 1;
657+
} else if (good_agpt) {
658+
*gpt = agpt;
659+
*ptes = aptes;
660+
kfree(pgpt);
661+
kfree(pptes);
655662
pr_warn("Primary GPT is invalid, using alternate GPT.\n");
656-
return 1;
657-
}
663+
return 1;
664+
}
658665

659666
fail:
660-
kfree(pgpt);
661-
kfree(agpt);
662-
kfree(pptes);
663-
kfree(aptes);
664-
*gpt = NULL;
665-
*ptes = NULL;
666-
return 0;
667+
kfree(pgpt);
668+
kfree(agpt);
669+
kfree(pptes);
670+
kfree(aptes);
671+
*gpt = NULL;
672+
*ptes = NULL;
673+
return 0;
667674
}
668675

669676
/**
@@ -715,7 +722,7 @@ int efi_partition(struct parsed_partitions *state)
715722
gpt_header *gpt = NULL;
716723
gpt_entry *ptes = NULL;
717724
u32 i;
718-
unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
725+
unsigned int ssz = queue_logical_block_size(state->disk->queue) / 512;
719726

720727
if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
721728
kfree(gpt);
@@ -727,7 +734,7 @@ int efi_partition(struct parsed_partitions *state)
727734

728735
for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) {
729736
struct partition_meta_info *info;
730-
unsigned label_max;
737+
unsigned int label_max;
731738
u64 start = le64_to_cpu(ptes[i].starting_lba);
732739
u64 size = le64_to_cpu(ptes[i].ending_lba) -
733740
le64_to_cpu(ptes[i].starting_lba) + 1ULL;

0 commit comments

Comments
 (0)