Skip to content

Commit 191ef96

Browse files
Jesper JuhlLinus Torvalds
authored andcommitted
[PATCH] uml: remove NULL checks and add some CodingStyle
Remove redundant NULL checks before [kv]free + small CodingStyle cleanup for arch/ Signed-off-by: Jesper Juhl <[email protected]> Signed-off-by: Jeff Dike <[email protected]> Cc: Paolo 'Blaisorblade' Giarrusso <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 893bb96 commit 191ef96

File tree

2 files changed

+69
-71
lines changed

2 files changed

+69
-71
lines changed

arch/um/kernel/irq.c

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ void sigio_handler(int sig, union uml_pt_regs *regs)
8989
struct irq_fd *irq_fd;
9090
int n;
9191

92-
if(smp_sigio_handler()) return;
93-
while(1){
92+
if (smp_sigio_handler())
93+
return;
94+
95+
while (1) {
9496
n = os_waiting_for_events(active_fds);
9597
if (n <= 0) {
9698
if(n == -EINTR) continue;
9799
else break;
98100
}
99101

100-
for(irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next){
101-
if(irq_fd->current_events != 0){
102+
for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) {
103+
if (irq_fd->current_events != 0) {
102104
irq_fd->current_events = 0;
103105
do_IRQ(irq_fd->irq, regs);
104106
}
@@ -110,19 +112,17 @@ void sigio_handler(int sig, union uml_pt_regs *regs)
110112

111113
static void maybe_sigio_broken(int fd, int type)
112114
{
113-
if(os_isatty(fd)){
114-
if((type == IRQ_WRITE) && !pty_output_sigio){
115+
if (os_isatty(fd)) {
116+
if ((type == IRQ_WRITE) && !pty_output_sigio) {
115117
write_sigio_workaround();
116118
add_sigio_fd(fd, 0);
117-
}
118-
else if((type == IRQ_READ) && !pty_close_sigio){
119+
} else if ((type == IRQ_READ) && !pty_close_sigio) {
119120
write_sigio_workaround();
120121
add_sigio_fd(fd, 1);
121122
}
122123
}
123124
}
124125

125-
126126
int activate_fd(int irq, int fd, int type, void *dev_id)
127127
{
128128
struct pollfd *tmp_pfd;
@@ -132,16 +132,18 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
132132

133133
pid = os_getpid();
134134
err = os_set_fd_async(fd, pid);
135-
if(err < 0)
135+
if (err < 0)
136136
goto out;
137137

138138
new_fd = um_kmalloc(sizeof(*new_fd));
139139
err = -ENOMEM;
140-
if(new_fd == NULL)
140+
if (new_fd == NULL)
141141
goto out;
142142

143-
if(type == IRQ_READ) events = UM_POLLIN | UM_POLLPRI;
144-
else events = UM_POLLOUT;
143+
if (type == IRQ_READ)
144+
events = UM_POLLIN | UM_POLLPRI;
145+
else
146+
events = UM_POLLOUT;
145147
*new_fd = ((struct irq_fd) { .next = NULL,
146148
.id = dev_id,
147149
.fd = fd,
@@ -165,8 +167,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
165167
* a semaphore.
166168
*/
167169
flags = irq_lock();
168-
for(irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next){
169-
if((irq_fd->fd == fd) && (irq_fd->type == type)){
170+
for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) {
171+
if ((irq_fd->fd == fd) && (irq_fd->type == type)) {
170172
printk("Registering fd %d twice\n", fd);
171173
printk("Irqs : %d, %d\n", irq_fd->irq, irq);
172174
printk("Ids : 0x%p, 0x%p\n", irq_fd->id, dev_id);
@@ -175,13 +177,13 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
175177
}
176178

177179
/*-------------*/
178-
if(type == IRQ_WRITE)
180+
if (type == IRQ_WRITE)
179181
fd = -1;
180182

181183
tmp_pfd = NULL;
182184
n = 0;
183185

184-
while(1){
186+
while (1) {
185187
n = os_create_pollfd(fd, events, tmp_pfd, n);
186188
if (n == 0)
187189
break;
@@ -198,10 +200,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
198200
* then we free the buffer tmp_fds and try again.
199201
*/
200202
irq_unlock(flags);
201-
if (tmp_pfd != NULL) {
202-
kfree(tmp_pfd);
203-
tmp_pfd = NULL;
204-
}
203+
kfree(tmp_pfd);
204+
tmp_pfd = NULL;
205205

206206
tmp_pfd = um_kmalloc(n);
207207
if (tmp_pfd == NULL)
@@ -249,7 +249,7 @@ static int same_irq_and_dev(struct irq_fd *irq, void *d)
249249
{
250250
struct irq_and_dev *data = d;
251251

252-
return((irq->irq == data->irq) && (irq->id == data->dev));
252+
return ((irq->irq == data->irq) && (irq->id == data->dev));
253253
}
254254

255255
void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
@@ -262,7 +262,7 @@ void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
262262

263263
static int same_fd(struct irq_fd *irq, void *fd)
264264
{
265-
return(irq->fd == *((int *) fd));
265+
return (irq->fd == *((int *)fd));
266266
}
267267

268268
void free_irq_by_fd(int fd)
@@ -276,16 +276,17 @@ static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out)
276276
int i = 0;
277277
int fdi;
278278

279-
for(irq=active_fds; irq != NULL; irq = irq->next){
280-
if((irq->fd == fd) && (irq->irq == irqnum)) break;
279+
for (irq = active_fds; irq != NULL; irq = irq->next) {
280+
if ((irq->fd == fd) && (irq->irq == irqnum))
281+
break;
281282
i++;
282283
}
283-
if(irq == NULL){
284+
if (irq == NULL) {
284285
printk("find_irq_by_fd doesn't have descriptor %d\n", fd);
285286
goto out;
286287
}
287288
fdi = os_get_pollfd(i);
288-
if((fdi != -1) && (fdi != fd)){
289+
if ((fdi != -1) && (fdi != fd)) {
289290
printk("find_irq_by_fd - mismatch between active_fds and "
290291
"pollfds, fd %d vs %d, need %d\n", irq->fd,
291292
fdi, fd);
@@ -294,7 +295,7 @@ static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out)
294295
}
295296
*index_out = i;
296297
out:
297-
return(irq);
298+
return irq;
298299
}
299300

300301
void reactivate_fd(int fd, int irqnum)
@@ -305,7 +306,7 @@ void reactivate_fd(int fd, int irqnum)
305306

306307
flags = irq_lock();
307308
irq = find_irq_by_fd(fd, irqnum, &i);
308-
if(irq == NULL){
309+
if (irq == NULL) {
309310
irq_unlock(flags);
310311
return;
311312
}
@@ -326,7 +327,7 @@ void deactivate_fd(int fd, int irqnum)
326327

327328
flags = irq_lock();
328329
irq = find_irq_by_fd(fd, irqnum, &i);
329-
if(irq == NULL)
330+
if (irq == NULL)
330331
goto out;
331332
os_set_pollfd(i, -1);
332333
out:
@@ -338,15 +339,15 @@ int deactivate_all_fds(void)
338339
struct irq_fd *irq;
339340
int err;
340341

341-
for(irq=active_fds;irq != NULL;irq = irq->next){
342+
for (irq = active_fds; irq != NULL; irq = irq->next) {
342343
err = os_clear_fd_async(irq->fd);
343-
if(err)
344-
return(err);
344+
if (err)
345+
return err;
345346
}
346347
/* If there is a signal already queued, after unblocking ignore it */
347348
os_set_ioignore();
348349

349-
return(0);
350+
return 0;
350351
}
351352

352353
void forward_interrupts(int pid)
@@ -356,9 +357,9 @@ void forward_interrupts(int pid)
356357
int err;
357358

358359
flags = irq_lock();
359-
for(irq=active_fds;irq != NULL;irq = irq->next){
360+
for (irq = active_fds; irq != NULL; irq = irq->next) {
360361
err = os_set_owner(irq->fd, pid);
361-
if(err < 0){
362+
if (err < 0) {
362363
/* XXX Just remove the irq rather than
363364
* print out an infinite stream of these
364365
*/
@@ -379,7 +380,7 @@ void forward_interrupts(int pid)
379380
unsigned int do_IRQ(int irq, union uml_pt_regs *regs)
380381
{
381382
irq_enter();
382-
__do_IRQ(irq, (struct pt_regs *) regs);
383+
__do_IRQ(irq, (struct pt_regs *)regs);
383384
irq_exit();
384385
return 1;
385386
}
@@ -392,12 +393,12 @@ int um_request_irq(unsigned int irq, int fd, int type,
392393
int err;
393394

394395
err = request_irq(irq, handler, irqflags, devname, dev_id);
395-
if(err)
396-
return(err);
396+
if (err)
397+
return err;
397398

398-
if(fd != -1)
399+
if (fd != -1)
399400
err = activate_fd(irq, fd, type, dev_id);
400-
return(err);
401+
return err;
401402
}
402403
EXPORT_SYMBOL(um_request_irq);
403404
EXPORT_SYMBOL(reactivate_fd);
@@ -409,7 +410,7 @@ unsigned long irq_lock(void)
409410
unsigned long flags;
410411

411412
spin_lock_irqsave(&irq_spinlock, flags);
412-
return(flags);
413+
return flags;
413414
}
414415

415416
void irq_unlock(unsigned long flags)
@@ -452,7 +453,7 @@ void __init init_IRQ(void)
452453
irq_desc[TIMER_IRQ].depth = 1;
453454
irq_desc[TIMER_IRQ].handler = &SIGVTALRM_irq_type;
454455
enable_irq(TIMER_IRQ);
455-
for(i=1;i<NR_IRQS;i++){
456+
for (i = 1; i < NR_IRQS; i++) {
456457
irq_desc[i].status = IRQ_DISABLED;
457458
irq_desc[i].action = NULL;
458459
irq_desc[i].depth = 1;
@@ -467,15 +468,15 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
467468
int fds[2], err;
468469

469470
err = os_pipe(fds, 1, 1);
470-
if(err){
471+
if (err) {
471472
printk("init_aio_irq - os_pipe failed, err = %d\n", -err);
472473
goto out;
473474
}
474475

475476
err = um_request_irq(irq, fds[0], IRQ_READ, handler,
476477
SA_INTERRUPT | SA_SAMPLE_RANDOM, name,
477478
(void *) (long) fds[0]);
478-
if(err){
479+
if (err) {
479480
printk("init_aio_irq - : um_request_irq failed, err = %d\n",
480481
err);
481482
goto out_close;
@@ -488,5 +489,5 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
488489
os_close_file(fds[0]);
489490
os_close_file(fds[1]);
490491
out:
491-
return(err);
492+
return err;
492493
}

arch/um/os-Linux/irq.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ int os_waiting_for_events(struct irq_fd *active_fds)
2929
int i, n, err;
3030

3131
n = poll(pollfds, pollfds_num, 0);
32-
if(n < 0){
32+
if (n < 0) {
3333
err = -errno;
34-
if(errno != EINTR)
34+
if (errno != EINTR)
3535
printk("sigio_handler: os_waiting_for_events:"
3636
" poll returned %d, errno = %d\n", n, errno);
3737
return err;
3838
}
3939

40-
if(n == 0)
40+
if (n == 0)
4141
return 0;
4242

4343
irq_fd = active_fds;
4444

45-
for(i = 0; i < pollfds_num; i++){
46-
if(pollfds[i].revents != 0){
45+
for (i = 0; i < pollfds_num; i++) {
46+
if (pollfds[i].revents != 0) {
4747
irq_fd->current_events = pollfds[i].revents;
4848
pollfds[i].fd = -1;
4949
}
@@ -54,7 +54,7 @@ int os_waiting_for_events(struct irq_fd *active_fds)
5454

5555
int os_isatty(int fd)
5656
{
57-
return(isatty(fd));
57+
return isatty(fd);
5858
}
5959

6060
int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
@@ -65,26 +65,23 @@ int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
6565
return((pollfds_size + 1) * sizeof(pollfds[0]));
6666
}
6767

68-
if(pollfds != NULL){
68+
if (pollfds != NULL) {
6969
memcpy(tmp_pfd, pollfds,
7070
sizeof(pollfds[0]) * pollfds_size);
7171
/* remove old pollfds */
7272
kfree(pollfds);
7373
}
7474
pollfds = tmp_pfd;
7575
pollfds_size++;
76-
} else {
77-
/* remove not used tmp_pfd */
78-
if (tmp_pfd != NULL)
79-
kfree(tmp_pfd);
80-
}
76+
} else
77+
kfree(tmp_pfd); /* remove not used tmp_pfd */
8178

82-
pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
83-
.events = events,
84-
.revents = 0 });
79+
pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
80+
.events = events,
81+
.revents = 0 });
8582
pollfds_num++;
8683

87-
return(0);
84+
return 0;
8885
}
8986

9087
void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
@@ -94,11 +91,11 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
9491
int i = 0;
9592

9693
prev = &active_fds;
97-
while(*prev != NULL){
98-
if((*test)(*prev, arg)){
94+
while (*prev != NULL) {
95+
if ((*test)(*prev, arg)) {
9996
struct irq_fd *old_fd = *prev;
100-
if((pollfds[i].fd != -1) &&
101-
(pollfds[i].fd != (*prev)->fd)){
97+
if ((pollfds[i].fd != -1) &&
98+
(pollfds[i].fd != (*prev)->fd)) {
10299
printk("os_free_irq_by_cb - mismatch between "
103100
"active_fds and pollfds, fd %d vs %d\n",
104101
(*prev)->fd, pollfds[i].fd);
@@ -110,7 +107,6 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
110107
/* This moves the *whole* array after pollfds[i]
111108
* (though it doesn't spot as such)!
112109
*/
113-
114110
memmove(&pollfds[i], &pollfds[i + 1],
115111
(pollfds_num - i) * sizeof(pollfds[0]));
116112
if(*last_irq_ptr2 == &old_fd->next)
@@ -129,10 +125,9 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
129125
return;
130126
}
131127

132-
133128
int os_get_pollfd(int i)
134129
{
135-
return(pollfds[i].fd);
130+
return pollfds[i].fd;
136131
}
137132

138133
void os_set_pollfd(int i, int fd)
@@ -151,8 +146,10 @@ void init_irq_signals(int on_sigstack)
151146
int flags;
152147

153148
flags = on_sigstack ? SA_ONSTACK : 0;
154-
if(timer_irq_inited) h = (__sighandler_t) alarm_handler;
155-
else h = boot_timer_handler;
149+
if (timer_irq_inited)
150+
h = (__sighandler_t)alarm_handler;
151+
else
152+
h = boot_timer_handler;
156153

157154
set_handler(SIGVTALRM, h, flags | SA_RESTART,
158155
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1);

0 commit comments

Comments
 (0)