Skip to content

Commit ef0470c

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: tidy libc code
This patch lays some groundwork for the next one, which converts calls to os_{read,write}_file into {read,write}, by doing some tidying in the affected areas. do_not_aio gets restructured to make the final result a bit cleaner. There are also whitespace and other formatting fixes, fixes in error messages, and a typo fix. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3d56404 commit ef0470c

7 files changed

Lines changed: 47 additions & 46 deletions

File tree

‎arch/um/os-Linux/aio.c‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,21 @@ static int aio_thread(void *arg)
146146
static int do_not_aio(struct aio_thread_req *req)
147147
{
148148
char c;
149+
unsigned long long actual;
149150
int err;
150151

152+
actual = lseek64(req->io_fd, req->offset, SEEK_SET);
153+
if(actual != req->offset)
154+
return -errno;
155+
151156
switch(req->type){
152157
case AIO_READ:
153-
err = os_seek_file(req->io_fd, req->offset);
154-
if(err)
155-
goto out;
156-
157158
err = os_read_file(req->io_fd, req->buf, req->len);
158159
break;
159160
case AIO_WRITE:
160-
err = os_seek_file(req->io_fd, req->offset);
161-
if(err)
162-
goto out;
163-
164161
err = os_write_file(req->io_fd, req->buf, req->len);
165162
break;
166163
case AIO_MMAP:
167-
err = os_seek_file(req->io_fd, req->offset);
168-
if(err)
169-
goto out;
170-
171164
err = os_read_file(req->io_fd, &c, sizeof(c));
172165
break;
173166
default:
@@ -176,7 +169,6 @@ static int do_not_aio(struct aio_thread_req *req)
176169
break;
177170
}
178171

179-
out:
180172
return err;
181173
}
182174

@@ -207,7 +199,7 @@ static int not_aio_thread(void *arg)
207199
}
208200
err = do_not_aio(&req);
209201
reply = ((struct aio_thread_reply) { .data = req.aio,
210-
.err = err });
202+
.err = err });
211203
err = os_write_file(req.aio->reply_fd, &reply, sizeof(reply));
212204
if(err != sizeof(reply))
213205
printk("not_aio_thread - write failed, fd = %d, "

‎arch/um/os-Linux/drivers/ethertap_user.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
2+
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
33
* James Leu (jleu@mindspring.net).
44
* Copyright (C) 2001 by various other people who didn't put their name here.
55
* Licensed under the GPL.
@@ -49,8 +49,11 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
4949
memcpy(change.addr, addr, sizeof(change.addr));
5050
memcpy(change.netmask, netmask, sizeof(change.netmask));
5151
n = os_write_file(fd, &change, sizeof(change));
52-
if(n != sizeof(change))
52+
if(n != sizeof(change)){
5353
printk("etap_change - request failed, err = %d\n", -n);
54+
return;
55+
}
56+
5457
output = um_kmalloc(UM_KERN_PAGE_SIZE);
5558
if(output == NULL)
5659
printk("etap_change : Failed to allocate output buffer\n");
@@ -116,7 +119,8 @@ static int etap_tramp(char *dev, char *gate, int control_me,
116119
pe_data.data_me = data_me;
117120
pid = run_helper(etap_pre_exec, &pe_data, args, NULL);
118121

119-
if(pid < 0) err = pid;
122+
if(pid < 0)
123+
err = pid;
120124
os_close_file(data_remote);
121125
os_close_file(control_remote);
122126
n = os_read_file(control_me, &c, sizeof(c));

‎arch/um/os-Linux/helper.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static int helper_child(void *arg)
3434
if (data->pre_exec != NULL)
3535
(*data->pre_exec)(data->pre_data);
3636
errval = execvp_noalloc(data->buf, argv[0], argv);
37-
printk("helper_child - execvp of '%s' failed - errno = %d\n", argv[0], -errval);
37+
printk("helper_child - execvp of '%s' failed - errno = %d\n", argv[0],
38+
-errval);
3839
os_write_file(data->fd, &errval, sizeof(errval));
3940
kill(os_getpid(), SIGKILL);
4041
return 0;
@@ -87,8 +88,10 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
8788
close(fds[1]);
8889
fds[1] = -1;
8990

90-
/* Read the errno value from the child, if the exec failed, or get 0 if
91-
* the exec succeeded because the pipe fd was set as close-on-exec. */
91+
/*
92+
* Read the errno value from the child, if the exec failed, or get 0 if
93+
* the exec succeeded because the pipe fd was set as close-on-exec.
94+
*/
9295
n = os_read_file(fds[0], &ret, sizeof(ret));
9396
if (n == 0) {
9497
ret = pid;

‎arch/um/os-Linux/process.c‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ unsigned long os_process_pc(int pid)
4040
if(fd < 0){
4141
printk("os_process_pc - couldn't open '%s', err = %d\n",
4242
proc_stat, -fd);
43-
return(ARBITRARY_ADDR);
43+
return ARBITRARY_ADDR;
4444
}
4545
err = os_read_file(fd, buf, sizeof(buf));
4646
if(err < 0){
4747
printk("os_process_pc - couldn't read '%s', err = %d\n",
4848
proc_stat, -err);
4949
os_close_file(fd);
50-
return(ARBITRARY_ADDR);
50+
return ARBITRARY_ADDR;
5151
}
5252
os_close_file(fd);
5353
pc = ARBITRARY_ADDR;
@@ -56,7 +56,7 @@ unsigned long os_process_pc(int pid)
5656
"%*d %*d %*d %*d %*d %lu", &pc) != 1){
5757
printk("os_process_pc - couldn't find pc in '%s'\n", buf);
5858
}
59-
return(pc);
59+
return pc;
6060
}
6161

6262
int os_process_parent(int pid)
@@ -65,29 +65,30 @@ int os_process_parent(int pid)
6565
char data[256];
6666
int parent, n, fd;
6767

68-
if(pid == -1) return(-1);
68+
if(pid == -1)
69+
return -1;
6970

7071
snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
7172
fd = os_open_file(stat, of_read(OPENFLAGS()), 0);
7273
if(fd < 0){
7374
printk("Couldn't open '%s', err = %d\n", stat, -fd);
74-
return(FAILURE_PID);
75+
return FAILURE_PID;
7576
}
7677

7778
n = os_read_file(fd, data, sizeof(data));
7879
os_close_file(fd);
7980

8081
if(n < 0){
8182
printk("Couldn't read '%s', err = %d\n", stat, -n);
82-
return(FAILURE_PID);
83+
return FAILURE_PID;
8384
}
8485

8586
parent = FAILURE_PID;
8687
n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent);
8788
if(n != 1)
8889
printk("Failed to scan '%s'\n", data);
8990

90-
return(parent);
91+
return parent;
9192
}
9293

9394
void os_stop_process(int pid)
@@ -145,7 +146,7 @@ void os_usr1_process(int pid)
145146

146147
int os_getpid(void)
147148
{
148-
return(syscall(__NR_getpid));
149+
return syscall(__NR_getpid);
149150
}
150151

151152
int os_getpgrp(void)
@@ -165,8 +166,8 @@ int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len,
165166
loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
166167
fd, off);
167168
if(loc == MAP_FAILED)
168-
return(-errno);
169-
return(0);
169+
return -errno;
170+
return 0;
170171
}
171172

172173
int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
@@ -175,8 +176,8 @@ int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
175176
(x ? PROT_EXEC : 0));
176177

177178
if(mprotect(addr, len, prot) < 0)
178-
return(-errno);
179-
return(0);
179+
return -errno;
180+
return 0;
180181
}
181182

182183
int os_unmap_memory(void *addr, int len)
@@ -185,8 +186,8 @@ int os_unmap_memory(void *addr, int len)
185186

186187
err = munmap(addr, len);
187188
if(err < 0)
188-
return(-errno);
189-
return(0);
189+
return -errno;
190+
return 0;
190191
}
191192

192193
#ifndef MADV_REMOVE

‎arch/um/os-Linux/sigio.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,16 @@ static void tty_output(int master, int slave)
461461

462462
while(os_write_file(master, buf, sizeof(buf)) > 0) ;
463463
if(errno != EAGAIN)
464-
panic("check_sigio : write failed, errno = %d\n", errno);
464+
panic("tty_output : write failed, errno = %d\n", errno);
465465
while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
466466

467467
if(got_sigio){
468468
printk("Yes\n");
469469
pty_output_sigio = 1;
470470
}
471-
else if(n == -EAGAIN) printk("No, enabling workaround\n");
472-
else panic("check_sigio : read failed, err = %d\n", n);
471+
else if(n == -EAGAIN)
472+
printk("No, enabling workaround\n");
473+
else panic("tty_output : read failed, err = %d\n", n);
473474
}
474475

475476
static void tty_close(int master, int slave)

‎arch/um/os-Linux/skas/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ int copy_context_skas0(unsigned long new_stack, int pid)
409409

410410
/*
411411
* This is used only, if stub pages are needed, while proc_mm is
412-
* availabl. Opening /proc/mm creates a new mm_context, which lacks
412+
* available. Opening /proc/mm creates a new mm_context, which lacks
413413
* the stub-pages. Thus, we map them using /proc/mm-fd
414414
*/
415415
void map_stub_pages(int fd, unsigned long code,

‎arch/um/os-Linux/tty_log.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int open_tty_log(void *tty, void *current_tty)
5555
.usec = tv.tv_usec } );
5656
os_write_file(tty_log_fd, &data, sizeof(data));
5757
os_write_file(tty_log_fd, &current_tty, data.len);
58-
return(tty_log_fd);
58+
return tty_log_fd;
5959
}
6060

6161
sprintf(buf, "%s/%0u-%0u", tty_log_dir, (unsigned int) tv.tv_sec,
@@ -67,7 +67,7 @@ int open_tty_log(void *tty, void *current_tty)
6767
printk("open_tty_log : couldn't open '%s', errno = %d\n",
6868
buf, -fd);
6969
}
70-
return(fd);
70+
return fd;
7171
}
7272

7373
void close_tty_log(int fd, void *tty)
@@ -101,18 +101,18 @@ static int log_chunk(int fd, const char *buf, int len)
101101
n = os_write_file(fd, chunk, try);
102102
if(n != try) {
103103
if(n < 0)
104-
return(n);
105-
return(-EIO);
104+
return n;
105+
return -EIO;
106106
}
107107
if(missed != 0)
108-
return(-EFAULT);
108+
return -EFAULT;
109109

110110
len -= try;
111111
total += try;
112112
buf += try;
113113
}
114114

115-
return(total);
115+
return total;
116116
}
117117

118118
int write_tty_log(int fd, const char *buf, int len, void *tty, int is_read)
@@ -133,7 +133,7 @@ int write_tty_log(int fd, const char *buf, int len, void *tty, int is_read)
133133
os_write_file(tty_log_fd, &data, sizeof(data));
134134
}
135135

136-
return(log_chunk(fd, buf, len));
136+
return log_chunk(fd, buf, len);
137137
}
138138

139139
void log_exec(char **argv, void *tty)
@@ -179,7 +179,7 @@ extern void register_tty_logger(int (*opener)(void *, void *),
179179
static int register_logger(void)
180180
{
181181
register_tty_logger(open_tty_log, write_tty_log, close_tty_log);
182-
return(0);
182+
return 0;
183183
}
184184

185185
__uml_initcall(register_logger);

0 commit comments

Comments
 (0)