mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
In preparation for removing the strlcat API[1], replace the char *pp_buf
with a struct seq_buf, which tracks the current write position and
remaining space internally. This allows for:
- Direct use of seq_buf_printf() in place of snprintf()+strlcat()
pairs, eliminating local tmp buffers throughout.
- Adjacent strlcat() calls that build strings piece-by-piece
(e.g., strlcat("["); strlcat(name); strlcat("]")) to be collapsed
into single seq_buf_printf() calls.
- Simpler call sites: seq_buf_puts() takes only the buffer and string,
with no need to pass PAGE_SIZE at every call.
The backing buffer allocation is unchanged (__get_free_page), and the
output path uses seq_buf_str() to NUL-terminate before passing to
printk().
Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Josh Law <objecting@objecting.org>
Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: Josh Law <objecting@objecting.org>
Link: https://patch.msgid.link/20260321004840.work.670-kees@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* fs/partitions/sgi.c
|
|
*
|
|
* Code extracted from drivers/block/genhd.c
|
|
*/
|
|
|
|
#include "check.h"
|
|
|
|
#define SGI_LABEL_MAGIC 0x0be5a941
|
|
|
|
enum {
|
|
LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
|
|
};
|
|
|
|
struct sgi_disklabel {
|
|
__be32 magic_mushroom; /* Big fat spliff... */
|
|
__be16 root_part_num; /* Root partition number */
|
|
__be16 swap_part_num; /* Swap partition number */
|
|
s8 boot_file[16]; /* Name of boot file for ARCS */
|
|
u8 _unused0[48]; /* Device parameter useless crapola.. */
|
|
struct sgi_volume {
|
|
s8 name[8]; /* Name of volume */
|
|
__be32 block_num; /* Logical block number */
|
|
__be32 num_bytes; /* How big, in bytes */
|
|
} volume[15];
|
|
struct sgi_partition {
|
|
__be32 num_blocks; /* Size in logical blocks */
|
|
__be32 first_block; /* First logical block */
|
|
__be32 type; /* Type of this partition */
|
|
} partitions[16];
|
|
__be32 csum; /* Disk label checksum */
|
|
__be32 _unused1; /* Padding */
|
|
};
|
|
|
|
int sgi_partition(struct parsed_partitions *state)
|
|
{
|
|
int i, csum;
|
|
__be32 magic;
|
|
int slot = 1;
|
|
unsigned int start, blocks;
|
|
__be32 *ui, cs;
|
|
Sector sect;
|
|
struct sgi_disklabel *label;
|
|
struct sgi_partition *p;
|
|
|
|
label = read_part_sector(state, 0, §);
|
|
if (!label)
|
|
return -1;
|
|
p = &label->partitions[0];
|
|
magic = label->magic_mushroom;
|
|
if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) {
|
|
put_dev_sector(sect);
|
|
return 0;
|
|
}
|
|
ui = ((__be32 *) (label + 1)) - 1;
|
|
for(csum = 0; ui >= ((__be32 *) label);) {
|
|
cs = *ui--;
|
|
csum += be32_to_cpu(cs);
|
|
}
|
|
if(csum) {
|
|
printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n",
|
|
state->disk->disk_name);
|
|
put_dev_sector(sect);
|
|
return 0;
|
|
}
|
|
/* All SGI disk labels have 16 partitions, disks under Linux only
|
|
* have 15 minor's. Luckily there are always a few zero length
|
|
* partitions which we don't care about so we never overflow the
|
|
* current_minor.
|
|
*/
|
|
for(i = 0; i < 16; i++, p++) {
|
|
blocks = be32_to_cpu(p->num_blocks);
|
|
start = be32_to_cpu(p->first_block);
|
|
if (blocks) {
|
|
put_partition(state, slot, start, blocks);
|
|
if (be32_to_cpu(p->type) == LINUX_RAID_PARTITION)
|
|
state->parts[slot].flags = ADDPART_FLAG_RAID;
|
|
}
|
|
slot++;
|
|
}
|
|
seq_buf_puts(&state->pp_buf, "\n");
|
|
put_dev_sector(sect);
|
|
return 1;
|
|
}
|