Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

uml: style fixes in arch/um/os-Linux

Style changes under arch/um/os-Linux:
include trimming
CodingStyle fixes
some printks needed severity indicators

make_tempfile turns out not to be used outside of mem.c, so it is now static.
Its declaration in tempfile.h is no longer needed, and tempfile.h itself is no
longer needed.

create_tmp_file was also made static.

checkpatch moans about an EXPORT_SYMBOL in user_syms.c which is part of a
macro definition - this is copying a bit of kernel infrastructure into the
libc side of UML because the kernel headers can't be included there.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jeff Dike and committed by
Linus Torvalds
5134d8fe 536788fe

+99 -130
-11
arch/um/include/tempfile.h
··· 1 - /* 2 - * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) 3 - * Licensed under the GPL 4 - */ 5 - 6 - #ifndef __TEMPFILE_H__ 7 - #define __TEMPFILE_H__ 8 - 9 - extern int make_tempfile(const char *template, char **tempname, int do_unlink); 10 - 11 - #endif
+1 -1
arch/um/os-Linux/aio.c
··· 142 142 if (actual != req->offset) 143 143 return -errno; 144 144 145 - switch(req->type) { 145 + switch (req->type) { 146 146 case AIO_READ: 147 147 n = read(req->io_fd, req->buf, req->len); 148 148 break;
+4 -4
arch/um/os-Linux/drivers/ethertap_kern.c
··· 6 6 * Licensed under the GPL. 7 7 */ 8 8 9 - #include "linux/init.h" 9 + #include <linux/init.h> 10 10 #include <linux/netdevice.h> 11 11 #include "etap.h" 12 12 #include "net_kern.h" ··· 30 30 epri->control_fd = -1; 31 31 epri->dev = dev; 32 32 33 - printk("ethertap backend - %s", epri->dev_name); 33 + printk(KERN_INFO "ethertap backend - %s", epri->dev_name); 34 34 if (epri->gate_addr != NULL) 35 - printk(", IP = %s", epri->gate_addr); 36 - printk("\n"); 35 + printk(KERN_CONT ", IP = %s", epri->gate_addr); 36 + printk(KERN_CONT "\n"); 37 37 } 38 38 39 39 static int etap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
+3 -3
arch/um/os-Linux/drivers/tuntap_kern.c
··· 29 29 tpri->fd = -1; 30 30 tpri->dev = dev; 31 31 32 - printk("TUN/TAP backend - "); 32 + printk(KERN_INFO "TUN/TAP backend - "); 33 33 if (tpri->gate_addr != NULL) 34 - printk("IP = %s", tpri->gate_addr); 35 - printk("\n"); 34 + printk(KERN_CONT "IP = %s", tpri->gate_addr); 35 + printk(KERN_CONT "\n"); 36 36 } 37 37 38 38 static int tuntap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
+1 -12
arch/um/os-Linux/include/file.h
··· 1 1 /* 2 - * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 + * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 3 * Licensed under the GPL 4 4 */ 5 5 ··· 9 9 #define DEV_NULL "/dev/null" 10 10 11 11 #endif 12 - 13 - /* 14 - * Overrides for Emacs so that we follow Linus's tabbing style. 15 - * Emacs will notice this stuff at the end of the file and automatically 16 - * adjust the settings for this buffer only. This must remain at the end 17 - * of the file. 18 - * --------------------------------------------------------------------------- 19 - * Local variables: 20 - * c-file-style: "linux" 21 - * End: 22 - */
+51 -52
arch/um/os-Linux/mem.c
··· 1 + /* 2 + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 + * Licensed under the GPL 4 + */ 5 + 1 6 #include <stdio.h> 2 - #include <stdlib.h> 3 7 #include <stddef.h> 4 - #include <stdarg.h> 8 + #include <stdlib.h> 5 9 #include <unistd.h> 6 10 #include <errno.h> 7 - #include <string.h> 8 11 #include <fcntl.h> 9 - #include <sys/types.h> 12 + #include <string.h> 10 13 #include <sys/mman.h> 11 - #include <sys/statfs.h> 12 - #include "user.h" 13 - #include "mem_user.h" 14 - #include "init.h" 15 - #include "os.h" 16 - #include "tempfile.h" 17 - #include "kern_constants.h" 18 - 19 14 #include <sys/param.h> 15 + #include "init.h" 16 + #include "kern_constants.h" 17 + #include "os.h" 18 + #include "user.h" 20 19 21 20 /* Modified by which_tmpdir, which is called during early boot */ 22 21 static char *default_tmpdir = "/tmp"; ··· 32 33 int i; 33 34 char *dir = NULL; 34 35 35 - if(tempdir != NULL) /* We've already been called */ 36 + if (tempdir != NULL) 37 + /* We've already been called */ 36 38 return; 37 - for(i = 0; dirs[i]; i++){ 39 + for (i = 0; dirs[i]; i++) { 38 40 dir = getenv(dirs[i]); 39 - if((dir != NULL) && (*dir != '\0')) 41 + if ((dir != NULL) && (*dir != '\0')) 40 42 break; 41 43 } 42 - if((dir == NULL) || (*dir == '\0')) 44 + if ((dir == NULL) || (*dir == '\0')) 43 45 dir = default_tmpdir; 44 46 45 47 tempdir = malloc(strlen(dir) + 2); 46 - if(tempdir == NULL){ 48 + if (tempdir == NULL) { 47 49 fprintf(stderr, "Failed to malloc tempdir, " 48 50 "errno = %d\n", errno); 49 51 return; ··· 53 53 strcat(tempdir, "/"); 54 54 } 55 55 56 - /* This will return 1, with the first character in buf being the 56 + /* 57 + * This will return 1, with the first character in buf being the 57 58 * character following the next instance of c in the file. This will 58 59 * read the file as needed. If there's an error, -errno is returned; 59 60 * if the end of the file is reached, 0 is returned. ··· 65 64 size_t len; 66 65 char *ptr; 67 66 68 - while((ptr = strchr(buf, c)) == NULL){ 67 + while ((ptr = strchr(buf, c)) == NULL) { 69 68 n = read(fd, buf, size - 1); 70 - if(n == 0) 69 + if (n == 0) 71 70 return 0; 72 - else if(n < 0) 71 + else if (n < 0) 73 72 return -errno; 74 73 75 74 buf[n] = '\0'; ··· 79 78 len = strlen(ptr); 80 79 memmove(buf, ptr, len + 1); 81 80 82 - /* Refill the buffer so that if there's a partial string that we care 81 + /* 82 + * Refill the buffer so that if there's a partial string that we care 83 83 * about, it will be completed, and we can recognize it. 84 84 */ 85 85 n = read(fd, &buf[len], size - len - 1); 86 - if(n < 0) 86 + if (n < 0) 87 87 return -errno; 88 88 89 89 buf[len + n] = '\0'; ··· 94 92 /* which_tmpdir is called only during early boot */ 95 93 static int checked_tmpdir = 0; 96 94 97 - /* Look for a tmpfs mounted at /dev/shm. I couldn't find a cleaner 95 + /* 96 + * Look for a tmpfs mounted at /dev/shm. I couldn't find a cleaner 98 97 * way to do this than to parse /proc/mounts. statfs will return the 99 98 * same filesystem magic number and fs id for both /dev and /dev/shm 100 99 * when they are both tmpfs, so you can't tell if they are different ··· 110 107 int fd, found; 111 108 char buf[128] = { '\0' }; 112 109 113 - if(checked_tmpdir) 110 + if (checked_tmpdir) 114 111 return; 115 112 116 113 checked_tmpdir = 1; ··· 118 115 printf("Checking for tmpfs mount on /dev/shm..."); 119 116 120 117 fd = open("/proc/mounts", O_RDONLY); 121 - if(fd < 0){ 118 + if (fd < 0) { 122 119 printf("failed to open /proc/mounts, errno = %d\n", errno); 123 120 return; 124 121 } 125 122 126 - while(1){ 123 + while (1) { 127 124 found = next(fd, buf, ARRAY_SIZE(buf), ' '); 128 - if(found != 1) 125 + if (found != 1) 129 126 break; 130 127 131 - if(!strncmp(buf, "/dev/shm", strlen("/dev/shm"))) 128 + if (!strncmp(buf, "/dev/shm", strlen("/dev/shm"))) 132 129 goto found; 133 130 134 131 found = next(fd, buf, ARRAY_SIZE(buf), '\n'); 135 - if(found != 1) 132 + if (found != 1) 136 133 break; 137 134 } 138 135 139 136 err: 140 - if(found == 0) 137 + if (found == 0) 141 138 printf("nothing mounted on /dev/shm\n"); 142 - else if(found < 0) 139 + else if (found < 0) 143 140 printf("read returned errno %d\n", -found); 144 141 145 142 out: ··· 149 146 150 147 found: 151 148 found = next(fd, buf, ARRAY_SIZE(buf), ' '); 152 - if(found != 1) 149 + if (found != 1) 153 150 goto err; 154 151 155 - if(strncmp(buf, "tmpfs", strlen("tmpfs"))){ 152 + if (strncmp(buf, "tmpfs", strlen("tmpfs"))) { 156 153 printf("not tmpfs\n"); 157 154 goto out; 158 155 } ··· 167 164 * (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger). 168 165 * So it isn't 'static' yet. 169 166 */ 170 - int __init make_tempfile(const char *template, char **out_tempname, 171 - int do_unlink) 167 + static int __init make_tempfile(const char *template, char **out_tempname, 168 + int do_unlink) 172 169 { 173 170 char *tempname; 174 171 int fd; ··· 185 182 tempname[0] = '\0'; 186 183 strncat(tempname, template, MAXPATHLEN-1-strlen(tempname)); 187 184 fd = mkstemp(tempname); 188 - if(fd < 0){ 185 + if (fd < 0) { 189 186 fprintf(stderr, "open - cannot create %s: %s\n", tempname, 190 187 strerror(errno)); 191 188 goto out; 192 189 } 193 - if(do_unlink && (unlink(tempname) < 0)){ 190 + if (do_unlink && (unlink(tempname) < 0)) { 194 191 perror("unlink"); 195 192 goto out; 196 193 } 197 - if(out_tempname){ 194 + if (out_tempname) { 198 195 *out_tempname = tempname; 199 196 } else { 200 197 free(tempname); ··· 207 204 208 205 #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" 209 206 210 - /* 211 - * This proc is used in start_up.c 212 - * So it isn't 'static'. 213 - */ 214 - int __init create_tmp_file(unsigned long long len) 207 + static int __init create_tmp_file(unsigned long long len) 215 208 { 216 209 int fd, err; 217 210 char zero; 218 211 219 212 fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1); 220 - if(fd < 0) { 213 + if (fd < 0) 221 214 exit(1); 222 - } 223 215 224 216 err = fchmod(fd, 0777); 225 - if(err < 0){ 217 + if (err < 0) { 226 218 perror("fchmod"); 227 219 exit(1); 228 220 } 229 221 230 - /* Seek to len - 1 because writing a character there will 222 + /* 223 + * Seek to len - 1 because writing a character there will 231 224 * increase the file size by one byte, to the desired length. 232 225 */ 233 226 if (lseek64(fd, len - 1, SEEK_SET) < 0) { ··· 234 235 zero = 0; 235 236 236 237 err = write(fd, &zero, 1); 237 - if(err != 1){ 238 + if (err != 1) { 238 239 perror("write"); 239 240 exit(1); 240 241 } ··· 249 250 fd = create_tmp_file(len); 250 251 251 252 err = os_set_exec_close(fd); 252 - if(err < 0){ 253 + if (err < 0) { 253 254 errno = -err; 254 255 perror("exec_close"); 255 256 } ··· 266 267 PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); 267 268 printf("Checking PROT_EXEC mmap in %s...",tempdir); 268 269 fflush(stdout); 269 - if(addr == MAP_FAILED){ 270 + if (addr == MAP_FAILED) { 270 271 err = errno; 271 272 perror("failed"); 272 273 close(fd); 273 - if(err == EPERM) 274 + if (err == EPERM) 274 275 printf("%s must be not mounted noexec\n",tempdir); 275 276 exit(1); 276 277 }
+1 -1
arch/um/os-Linux/process.c
··· 224 224 goto out_unmap; 225 225 } 226 226 227 - printk("OK\n"); 227 + printk(UM_KERN_CONT "OK\n"); 228 228 ok = 1; 229 229 230 230 out_unmap:
+1 -1
arch/um/os-Linux/signal.c
··· 237 237 * interrupts may have arrived and we need to re-enable them and 238 238 * recheck signals_pending. 239 239 */ 240 - while(1) { 240 + while (1) { 241 241 /* 242 242 * Save and reset save_pending after enabling signals. This 243 243 * way, signals_pending won't be changed while we're reading it.
+3 -3
arch/um/os-Linux/skas/process.c
··· 341 341 int local_using_sysemu; 342 342 343 343 if (getitimer(ITIMER_VIRTUAL, &timer)) 344 - printk("Failed to get itimer, errno = %d\n", errno); 344 + printk(UM_KERN_ERR "Failed to get itimer, errno = %d\n", errno); 345 345 nsecs = timer.it_value.tv_sec * UM_NSEC_PER_SEC + 346 346 timer.it_value.tv_usec * UM_NSEC_PER_USEC; 347 347 nsecs += os_nsecs(); ··· 388 388 389 389 if (WIFSTOPPED(status)) { 390 390 int sig = WSTOPSIG(status); 391 - switch(sig) { 391 + switch (sig) { 392 392 case SIGSEGV: 393 393 if (PTRACE_FULL_FAULTINFO || 394 394 !ptrace_faultinfo) { ··· 641 641 * after returning to the jumper. 642 642 */ 643 643 n = setjmp(initial_jmpbuf); 644 - switch(n) { 644 + switch (n) { 645 645 case INIT_JMP_NEW_THREAD: 646 646 (*switch_buf)[0].JB_IP = (unsigned long) new_thread_handler; 647 647 (*switch_buf)[0].JB_SP = (unsigned long) stack +
+2 -2
arch/um/os-Linux/sys-i386/registers.c
··· 62 62 int err; 63 63 64 64 err = ptrace(PTRACE_GETFPXREGS, pid, 0, fpx_regs); 65 - if(!err) 65 + if (!err) 66 66 return; 67 67 68 - if(errno != EIO) 68 + if (errno != EIO) 69 69 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d", 70 70 errno); 71 71
+13 -8
arch/um/os-Linux/sys-x86_64/registers.c
··· 1 1 /* 2 - * Copyright (C) 2006-2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 2 + * Copyright (C) 2006 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 3 * Licensed under the GPL 4 4 */ 5 5 ··· 7 7 #include <sys/ptrace.h> 8 8 #define __FRAME_OFFSETS 9 9 #include <asm/ptrace.h> 10 + #include "kern_constants.h" 10 11 #include "longjmp.h" 11 12 #include "user.h" 12 13 13 14 int save_fp_registers(int pid, unsigned long *fp_regs) 14 15 { 15 - if(ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0) 16 + if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0) 16 17 return -errno; 17 18 return 0; 18 19 } 19 20 20 21 int restore_fp_registers(int pid, unsigned long *fp_regs) 21 22 { 22 - if(ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0) 23 + if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0) 23 24 return -errno; 24 25 return 0; 25 26 } 26 27 27 28 unsigned long get_thread_reg(int reg, jmp_buf *buf) 28 29 { 29 - switch(reg){ 30 - case RIP: return buf[0]->__rip; 31 - case RSP: return buf[0]->__rsp; 32 - case RBP: return buf[0]->__rbp; 30 + switch (reg) { 31 + case RIP: 32 + return buf[0]->__rip; 33 + case RSP: 34 + return buf[0]->__rsp; 35 + case RBP: 36 + return buf[0]->__rbp; 33 37 default: 34 - printk("get_thread_regs - unknown register %d\n", reg); 38 + printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n", 39 + reg); 35 40 return 0; 36 41 } 37 42 }
+2 -2
arch/um/os-Linux/uaccess.c
··· 1 1 /* 2 2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk) 3 - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) 3 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 4 4 * Licensed under the GPL 5 5 */ 6 6 ··· 16 16 17 17 jmp_buf jbuf; 18 18 *fault_catcher = &jbuf; 19 - if(UML_SETJMP(&jbuf) == 0){ 19 + if (UML_SETJMP(&jbuf) == 0) { 20 20 (*op)(to, from, n); 21 21 ret = 0; 22 22 *faulted_out = 0;
+2 -2
arch/um/os-Linux/user_syms.c
··· 34 34 * good; so the versions of these symbols will always match 35 35 */ 36 36 #define EXPORT_SYMBOL_PROTO(sym) \ 37 - int sym(void); \ 38 - EXPORT_SYMBOL(sym); 37 + int sym(void); \ 38 + EXPORT_SYMBOL(sym); 39 39 40 40 extern void readdir64(void) __attribute__((weak)); 41 41 EXPORT_SYMBOL(readdir64);
+15 -28
arch/um/os-Linux/util.c
··· 1 1 /* 2 - * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) 2 + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 3 * Licensed under the GPL 4 4 */ 5 5 6 6 #include <stdio.h> 7 7 #include <stdlib.h> 8 - #include <unistd.h> 9 - #include <limits.h> 10 - #include <sys/mman.h> 11 - #include <sys/stat.h> 12 - #include <sys/utsname.h> 13 - #include <sys/param.h> 14 - #include <sys/time.h> 15 - #include "asm/types.h" 16 - #include <ctype.h> 17 - #include <signal.h> 18 - #include <wait.h> 19 8 #include <errno.h> 20 - #include <stdarg.h> 21 - #include <sched.h> 22 - #include <termios.h> 9 + #include <signal.h> 23 10 #include <string.h> 24 - #include "kern_util.h" 25 - #include "user.h" 26 - #include "mem_user.h" 27 - #include "init.h" 28 - #include "ptrace_user.h" 29 - #include "uml-config.h" 30 - #include "os.h" 31 - #include "longjmp.h" 11 + #include <termios.h> 12 + #include <wait.h> 13 + #include <sys/mman.h> 14 + #include <sys/utsname.h> 32 15 #include "kern_constants.h" 16 + #include "os.h" 17 + #include "user.h" 33 18 34 19 void stack_protections(unsigned long address) 35 20 { 36 - if(mprotect((void *) address, UM_THREAD_SIZE, 21 + if (mprotect((void *) address, UM_THREAD_SIZE, 37 22 PROT_READ | PROT_WRITE | PROT_EXEC) < 0) 38 23 panic("protecting stack failed, errno = %d", errno); 39 24 } ··· 29 44 int err; 30 45 31 46 CATCH_EINTR(err = tcgetattr(fd, &tt)); 32 - if(err < 0) 47 + if (err < 0) 33 48 return -errno; 34 49 35 50 cfmakeraw(&tt); 36 51 37 52 CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt)); 38 - if(err < 0) 53 + if (err < 0) 39 54 return -errno; 40 55 41 - /* XXX tcsetattr could have applied only some changes 42 - * (and cfmakeraw() is a set of changes) */ 56 + /* 57 + * XXX tcsetattr could have applied only some changes 58 + * (and cfmakeraw() is a set of changes) 59 + */ 43 60 return 0; 44 61 } 45 62