[PATCH 2/11] New convenience function: get_cpumask_buf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make a convenience function for allocating a cpumask buffer and 
put it into tools.c. Since any caller of make_cpumask() needs
such a buffer, it is better to isolate the code in a function
rather than copy it all over the place.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>
[PATCH 2/11] New convenience function: get_cpumask_buf

Make a convenience function for allocating a cpumask buffer and
put it into tools.c. Since any caller of make_cpumask() needs
such a buffer, it is better to isolate the code in a function
rather than copy it all over the place.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>

---
 defs.h   |    1 +
 kernel.c |    5 +----
 tools.c  |   13 +++++++++++++
 3 files changed, 15 insertions(+), 4 deletions(-)

--- a/defs.h
+++ b/defs.h
@@ -4321,6 +4321,7 @@ int calculate(char *, ulong *, ulonglong
 int endian_mismatch(char *, char, ulong);
 uint16_t swap16(uint16_t, int);
 uint32_t swap32(uint32_t, int);
+ulong *get_cpumask_buf(void);
 int make_cpumask(char *, ulong *, int, int *);
 size_t strlcpy(char *, char *, size_t);
 struct rb_node *rb_first(struct rb_root *);
--- a/kernel.c
+++ b/kernel.c
@@ -5377,7 +5377,6 @@ cmd_irq(void)
         int i, c;
 	int nr_irqs;
 	ulong *cpus;
-	int len;
 	int show_intr, choose_cpu;
 	char buf[10];
 	char arg_buf[BUFSIZE];
@@ -5485,9 +5484,7 @@ cmd_irq(void)
 		error(FATAL, "cannot determine number of IRQs\n");
 
 	if (show_intr) {
-		if ((len = STRUCT_SIZE("cpumask_t")) < 0)
-			len = DIV_ROUND_UP(kt->cpus, BITS_PER_LONG) * sizeof(ulong);
-		cpus = (ulong *)GETBUF(len);
+		cpus = get_cpumask_buf();
 
 		if (choose_cpu) {
 			make_cpumask(arg_buf, cpus, FAULT_ON_ERROR, NULL);
--- a/tools.c
+++ b/tools.c
@@ -5489,6 +5489,19 @@ swap32(uint32_t val, int swap)
 		return val;
 }
 
+/*
+ *  Get a sufficiently large buffer for cpumask.
+ *  You should call FREEBUF() on the result when you no longer need it.
+ */
+ulong *
+get_cpumask_buf(void)
+{
+	int cpulen;
+	if ((cpulen = STRUCT_SIZE("cpumask_t")) < 0)
+		cpulen = DIV_ROUND_UP(kt->cpus, BITS_PER_LONG) * sizeof(ulong);
+	return (ulong *)GETBUF(cpulen);
+}
+
 int
 make_cpumask(char *s, ulong *mask, int flags, int *errptr)
 {
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux