hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/kernel/profile.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/kernel/profile.c
34 * Simple profiling. Manages a direct-mapped profile hit count buffer,
....@@ -16,7 +17,7 @@
1617
1718 #include <linux/export.h>
1819 #include <linux/profile.h>
19
-#include <linux/bootmem.h>
20
+#include <linux/memblock.h>
2021 #include <linux/notifier.h>
2122 #include <linux/mm.h>
2223 #include <linux/cpumask.h>
....@@ -108,6 +109,13 @@
108109
109110 /* only text is profiled */
110111 prof_len = (_etext - _stext) >> prof_shift;
112
+
113
+ if (!prof_len) {
114
+ pr_warn("profiling shift: %u too large\n", prof_shift);
115
+ prof_on = 0;
116
+ return -EINVAL;
117
+ }
118
+
111119 buffer_bytes = prof_len*sizeof(atomic_t);
112120
113121 if (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL))
....@@ -336,7 +344,7 @@
336344 struct page *page;
337345 int i;
338346
339
- if (prof_cpu_mask != NULL)
347
+ if (cpumask_available(prof_cpu_mask))
340348 cpumask_clear_cpu(cpu, prof_cpu_mask);
341349
342350 for (i = 0; i < 2; i++) {
....@@ -373,7 +381,7 @@
373381
374382 static int profile_online_cpu(unsigned int cpu)
375383 {
376
- if (prof_cpu_mask != NULL)
384
+ if (cpumask_available(prof_cpu_mask))
377385 cpumask_set_cpu(cpu, prof_cpu_mask);
378386
379387 return 0;
....@@ -403,7 +411,7 @@
403411 {
404412 struct pt_regs *regs = get_irq_regs();
405413
406
- if (!user_mode(regs) && prof_cpu_mask != NULL &&
414
+ if (!user_mode(regs) && cpumask_available(prof_cpu_mask) &&
407415 cpumask_test_cpu(smp_processor_id(), prof_cpu_mask))
408416 profile_hit(type, (void *)profile_pc(regs));
409417 }
....@@ -442,18 +450,18 @@
442450 return err;
443451 }
444452
445
-static const struct file_operations prof_cpu_mask_proc_fops = {
446
- .open = prof_cpu_mask_proc_open,
447
- .read = seq_read,
448
- .llseek = seq_lseek,
449
- .release = single_release,
450
- .write = prof_cpu_mask_proc_write,
453
+static const struct proc_ops prof_cpu_mask_proc_ops = {
454
+ .proc_open = prof_cpu_mask_proc_open,
455
+ .proc_read = seq_read,
456
+ .proc_lseek = seq_lseek,
457
+ .proc_release = single_release,
458
+ .proc_write = prof_cpu_mask_proc_write,
451459 };
452460
453461 void create_prof_cpu_mask(void)
454462 {
455463 /* create /proc/irq/prof_cpu_mask */
456
- proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_fops);
464
+ proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_ops);
457465 }
458466
459467 /*
....@@ -517,10 +525,10 @@
517525 return count;
518526 }
519527
520
-static const struct file_operations proc_profile_operations = {
521
- .read = read_profile,
522
- .write = write_profile,
523
- .llseek = default_llseek,
528
+static const struct proc_ops profile_proc_ops = {
529
+ .proc_read = read_profile,
530
+ .proc_write = write_profile,
531
+ .proc_lseek = default_llseek,
524532 };
525533
526534 int __ref create_proc_profile(void)
....@@ -548,7 +556,7 @@
548556 err = 0;
549557 #endif
550558 entry = proc_create("profile", S_IWUSR | S_IRUGO,
551
- NULL, &proc_profile_operations);
559
+ NULL, &profile_proc_ops);
552560 if (!entry)
553561 goto err_state_onl;
554562 proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));