Commit 191ef966 authored by Jesper Juhl's avatar Jesper Juhl Committed by Linus Torvalds

[PATCH] uml: remove NULL checks and add some CodingStyle

Remove redundant NULL checks before [kv]free + small CodingStyle cleanup for
arch/
Signed-off-by: default avatarJesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 893bb96a
...@@ -89,16 +89,18 @@ void sigio_handler(int sig, union uml_pt_regs *regs) ...@@ -89,16 +89,18 @@ void sigio_handler(int sig, union uml_pt_regs *regs)
struct irq_fd *irq_fd; struct irq_fd *irq_fd;
int n; int n;
if(smp_sigio_handler()) return; if (smp_sigio_handler())
while(1){ return;
while (1) {
n = os_waiting_for_events(active_fds); n = os_waiting_for_events(active_fds);
if (n <= 0) { if (n <= 0) {
if(n == -EINTR) continue; if(n == -EINTR) continue;
else break; else break;
} }
for(irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next){ for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) {
if(irq_fd->current_events != 0){ if (irq_fd->current_events != 0) {
irq_fd->current_events = 0; irq_fd->current_events = 0;
do_IRQ(irq_fd->irq, regs); do_IRQ(irq_fd->irq, regs);
} }
...@@ -110,19 +112,17 @@ void sigio_handler(int sig, union uml_pt_regs *regs) ...@@ -110,19 +112,17 @@ void sigio_handler(int sig, union uml_pt_regs *regs)
static void maybe_sigio_broken(int fd, int type) static void maybe_sigio_broken(int fd, int type)
{ {
if(os_isatty(fd)){ if (os_isatty(fd)) {
if((type == IRQ_WRITE) && !pty_output_sigio){ if ((type == IRQ_WRITE) && !pty_output_sigio) {
write_sigio_workaround(); write_sigio_workaround();
add_sigio_fd(fd, 0); add_sigio_fd(fd, 0);
} } else if ((type == IRQ_READ) && !pty_close_sigio) {
else if((type == IRQ_READ) && !pty_close_sigio){
write_sigio_workaround(); write_sigio_workaround();
add_sigio_fd(fd, 1); add_sigio_fd(fd, 1);
} }
} }
} }
int activate_fd(int irq, int fd, int type, void *dev_id) int activate_fd(int irq, int fd, int type, void *dev_id)
{ {
struct pollfd *tmp_pfd; struct pollfd *tmp_pfd;
...@@ -132,16 +132,18 @@ int activate_fd(int irq, int fd, int type, void *dev_id) ...@@ -132,16 +132,18 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
pid = os_getpid(); pid = os_getpid();
err = os_set_fd_async(fd, pid); err = os_set_fd_async(fd, pid);
if(err < 0) if (err < 0)
goto out; goto out;
new_fd = um_kmalloc(sizeof(*new_fd)); new_fd = um_kmalloc(sizeof(*new_fd));
err = -ENOMEM; err = -ENOMEM;
if(new_fd == NULL) if (new_fd == NULL)
goto out; goto out;
if(type == IRQ_READ) events = UM_POLLIN | UM_POLLPRI; if (type == IRQ_READ)
else events = UM_POLLOUT; events = UM_POLLIN | UM_POLLPRI;
else
events = UM_POLLOUT;
*new_fd = ((struct irq_fd) { .next = NULL, *new_fd = ((struct irq_fd) { .next = NULL,
.id = dev_id, .id = dev_id,
.fd = fd, .fd = fd,
...@@ -165,8 +167,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id) ...@@ -165,8 +167,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
* a semaphore. * a semaphore.
*/ */
flags = irq_lock(); flags = irq_lock();
for(irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next){ for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) {
if((irq_fd->fd == fd) && (irq_fd->type == type)){ if ((irq_fd->fd == fd) && (irq_fd->type == type)) {
printk("Registering fd %d twice\n", fd); printk("Registering fd %d twice\n", fd);
printk("Irqs : %d, %d\n", irq_fd->irq, irq); printk("Irqs : %d, %d\n", irq_fd->irq, irq);
printk("Ids : 0x%p, 0x%p\n", irq_fd->id, dev_id); 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) ...@@ -175,13 +177,13 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
} }
/*-------------*/ /*-------------*/
if(type == IRQ_WRITE) if (type == IRQ_WRITE)
fd = -1; fd = -1;
tmp_pfd = NULL; tmp_pfd = NULL;
n = 0; n = 0;
while(1){ while (1) {
n = os_create_pollfd(fd, events, tmp_pfd, n); n = os_create_pollfd(fd, events, tmp_pfd, n);
if (n == 0) if (n == 0)
break; break;
...@@ -198,10 +200,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id) ...@@ -198,10 +200,8 @@ int activate_fd(int irq, int fd, int type, void *dev_id)
* then we free the buffer tmp_fds and try again. * then we free the buffer tmp_fds and try again.
*/ */
irq_unlock(flags); irq_unlock(flags);
if (tmp_pfd != NULL) { kfree(tmp_pfd);
kfree(tmp_pfd); tmp_pfd = NULL;
tmp_pfd = NULL;
}
tmp_pfd = um_kmalloc(n); tmp_pfd = um_kmalloc(n);
if (tmp_pfd == NULL) if (tmp_pfd == NULL)
...@@ -249,7 +249,7 @@ static int same_irq_and_dev(struct irq_fd *irq, void *d) ...@@ -249,7 +249,7 @@ static int same_irq_and_dev(struct irq_fd *irq, void *d)
{ {
struct irq_and_dev *data = d; struct irq_and_dev *data = d;
return((irq->irq == data->irq) && (irq->id == data->dev)); return ((irq->irq == data->irq) && (irq->id == data->dev));
} }
void free_irq_by_irq_and_dev(unsigned int irq, void *dev) 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) ...@@ -262,7 +262,7 @@ void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
static int same_fd(struct irq_fd *irq, void *fd) static int same_fd(struct irq_fd *irq, void *fd)
{ {
return(irq->fd == *((int *) fd)); return (irq->fd == *((int *)fd));
} }
void free_irq_by_fd(int fd) 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) ...@@ -276,16 +276,17 @@ static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out)
int i = 0; int i = 0;
int fdi; int fdi;
for(irq=active_fds; irq != NULL; irq = irq->next){ for (irq = active_fds; irq != NULL; irq = irq->next) {
if((irq->fd == fd) && (irq->irq == irqnum)) break; if ((irq->fd == fd) && (irq->irq == irqnum))
break;
i++; i++;
} }
if(irq == NULL){ if (irq == NULL) {
printk("find_irq_by_fd doesn't have descriptor %d\n", fd); printk("find_irq_by_fd doesn't have descriptor %d\n", fd);
goto out; goto out;
} }
fdi = os_get_pollfd(i); fdi = os_get_pollfd(i);
if((fdi != -1) && (fdi != fd)){ if ((fdi != -1) && (fdi != fd)) {
printk("find_irq_by_fd - mismatch between active_fds and " printk("find_irq_by_fd - mismatch between active_fds and "
"pollfds, fd %d vs %d, need %d\n", irq->fd, "pollfds, fd %d vs %d, need %d\n", irq->fd,
fdi, fd); fdi, fd);
...@@ -294,7 +295,7 @@ static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out) ...@@ -294,7 +295,7 @@ static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out)
} }
*index_out = i; *index_out = i;
out: out:
return(irq); return irq;
} }
void reactivate_fd(int fd, int irqnum) void reactivate_fd(int fd, int irqnum)
...@@ -305,7 +306,7 @@ void reactivate_fd(int fd, int irqnum) ...@@ -305,7 +306,7 @@ void reactivate_fd(int fd, int irqnum)
flags = irq_lock(); flags = irq_lock();
irq = find_irq_by_fd(fd, irqnum, &i); irq = find_irq_by_fd(fd, irqnum, &i);
if(irq == NULL){ if (irq == NULL) {
irq_unlock(flags); irq_unlock(flags);
return; return;
} }
...@@ -326,7 +327,7 @@ void deactivate_fd(int fd, int irqnum) ...@@ -326,7 +327,7 @@ void deactivate_fd(int fd, int irqnum)
flags = irq_lock(); flags = irq_lock();
irq = find_irq_by_fd(fd, irqnum, &i); irq = find_irq_by_fd(fd, irqnum, &i);
if(irq == NULL) if (irq == NULL)
goto out; goto out;
os_set_pollfd(i, -1); os_set_pollfd(i, -1);
out: out:
...@@ -338,15 +339,15 @@ int deactivate_all_fds(void) ...@@ -338,15 +339,15 @@ int deactivate_all_fds(void)
struct irq_fd *irq; struct irq_fd *irq;
int err; int err;
for(irq=active_fds;irq != NULL;irq = irq->next){ for (irq = active_fds; irq != NULL; irq = irq->next) {
err = os_clear_fd_async(irq->fd); err = os_clear_fd_async(irq->fd);
if(err) if (err)
return(err); return err;
} }
/* If there is a signal already queued, after unblocking ignore it */ /* If there is a signal already queued, after unblocking ignore it */
os_set_ioignore(); os_set_ioignore();
return(0); return 0;
} }
void forward_interrupts(int pid) void forward_interrupts(int pid)
...@@ -356,9 +357,9 @@ void forward_interrupts(int pid) ...@@ -356,9 +357,9 @@ void forward_interrupts(int pid)
int err; int err;
flags = irq_lock(); flags = irq_lock();
for(irq=active_fds;irq != NULL;irq = irq->next){ for (irq = active_fds; irq != NULL; irq = irq->next) {
err = os_set_owner(irq->fd, pid); err = os_set_owner(irq->fd, pid);
if(err < 0){ if (err < 0) {
/* XXX Just remove the irq rather than /* XXX Just remove the irq rather than
* print out an infinite stream of these * print out an infinite stream of these
*/ */
...@@ -379,7 +380,7 @@ void forward_interrupts(int pid) ...@@ -379,7 +380,7 @@ void forward_interrupts(int pid)
unsigned int do_IRQ(int irq, union uml_pt_regs *regs) unsigned int do_IRQ(int irq, union uml_pt_regs *regs)
{ {
irq_enter(); irq_enter();
__do_IRQ(irq, (struct pt_regs *) regs); __do_IRQ(irq, (struct pt_regs *)regs);
irq_exit(); irq_exit();
return 1; return 1;
} }
...@@ -392,12 +393,12 @@ int um_request_irq(unsigned int irq, int fd, int type, ...@@ -392,12 +393,12 @@ int um_request_irq(unsigned int irq, int fd, int type,
int err; int err;
err = request_irq(irq, handler, irqflags, devname, dev_id); err = request_irq(irq, handler, irqflags, devname, dev_id);
if(err) if (err)
return(err); return err;
if(fd != -1) if (fd != -1)
err = activate_fd(irq, fd, type, dev_id); err = activate_fd(irq, fd, type, dev_id);
return(err); return err;
} }
EXPORT_SYMBOL(um_request_irq); EXPORT_SYMBOL(um_request_irq);
EXPORT_SYMBOL(reactivate_fd); EXPORT_SYMBOL(reactivate_fd);
...@@ -409,7 +410,7 @@ unsigned long irq_lock(void) ...@@ -409,7 +410,7 @@ unsigned long irq_lock(void)
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&irq_spinlock, flags); spin_lock_irqsave(&irq_spinlock, flags);
return(flags); return flags;
} }
void irq_unlock(unsigned long flags) void irq_unlock(unsigned long flags)
...@@ -452,7 +453,7 @@ void __init init_IRQ(void) ...@@ -452,7 +453,7 @@ void __init init_IRQ(void)
irq_desc[TIMER_IRQ].depth = 1; irq_desc[TIMER_IRQ].depth = 1;
irq_desc[TIMER_IRQ].handler = &SIGVTALRM_irq_type; irq_desc[TIMER_IRQ].handler = &SIGVTALRM_irq_type;
enable_irq(TIMER_IRQ); enable_irq(TIMER_IRQ);
for(i=1;i<NR_IRQS;i++){ for (i = 1; i < NR_IRQS; i++) {
irq_desc[i].status = IRQ_DISABLED; irq_desc[i].status = IRQ_DISABLED;
irq_desc[i].action = NULL; irq_desc[i].action = NULL;
irq_desc[i].depth = 1; irq_desc[i].depth = 1;
...@@ -467,7 +468,7 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *, ...@@ -467,7 +468,7 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
int fds[2], err; int fds[2], err;
err = os_pipe(fds, 1, 1); err = os_pipe(fds, 1, 1);
if(err){ if (err) {
printk("init_aio_irq - os_pipe failed, err = %d\n", -err); printk("init_aio_irq - os_pipe failed, err = %d\n", -err);
goto out; goto out;
} }
...@@ -475,7 +476,7 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *, ...@@ -475,7 +476,7 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
err = um_request_irq(irq, fds[0], IRQ_READ, handler, err = um_request_irq(irq, fds[0], IRQ_READ, handler,
SA_INTERRUPT | SA_SAMPLE_RANDOM, name, SA_INTERRUPT | SA_SAMPLE_RANDOM, name,
(void *) (long) fds[0]); (void *) (long) fds[0]);
if(err){ if (err) {
printk("init_aio_irq - : um_request_irq failed, err = %d\n", printk("init_aio_irq - : um_request_irq failed, err = %d\n",
err); err);
goto out_close; goto out_close;
...@@ -488,5 +489,5 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *, ...@@ -488,5 +489,5 @@ int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
os_close_file(fds[0]); os_close_file(fds[0]);
os_close_file(fds[1]); os_close_file(fds[1]);
out: out:
return(err); return err;
} }
...@@ -29,21 +29,21 @@ int os_waiting_for_events(struct irq_fd *active_fds) ...@@ -29,21 +29,21 @@ int os_waiting_for_events(struct irq_fd *active_fds)
int i, n, err; int i, n, err;
n = poll(pollfds, pollfds_num, 0); n = poll(pollfds, pollfds_num, 0);
if(n < 0){ if (n < 0) {
err = -errno; err = -errno;
if(errno != EINTR) if (errno != EINTR)
printk("sigio_handler: os_waiting_for_events:" printk("sigio_handler: os_waiting_for_events:"
" poll returned %d, errno = %d\n", n, errno); " poll returned %d, errno = %d\n", n, errno);
return err; return err;
} }
if(n == 0) if (n == 0)
return 0; return 0;
irq_fd = active_fds; irq_fd = active_fds;
for(i = 0; i < pollfds_num; i++){ for (i = 0; i < pollfds_num; i++) {
if(pollfds[i].revents != 0){ if (pollfds[i].revents != 0) {
irq_fd->current_events = pollfds[i].revents; irq_fd->current_events = pollfds[i].revents;
pollfds[i].fd = -1; pollfds[i].fd = -1;
} }
...@@ -54,7 +54,7 @@ int os_waiting_for_events(struct irq_fd *active_fds) ...@@ -54,7 +54,7 @@ int os_waiting_for_events(struct irq_fd *active_fds)
int os_isatty(int fd) int os_isatty(int fd)
{ {
return(isatty(fd)); return isatty(fd);
} }
int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds) int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
...@@ -65,7 +65,7 @@ int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds) ...@@ -65,7 +65,7 @@ int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
return((pollfds_size + 1) * sizeof(pollfds[0])); return((pollfds_size + 1) * sizeof(pollfds[0]));
} }
if(pollfds != NULL){ if (pollfds != NULL) {
memcpy(tmp_pfd, pollfds, memcpy(tmp_pfd, pollfds,
sizeof(pollfds[0]) * pollfds_size); sizeof(pollfds[0]) * pollfds_size);
/* remove old pollfds */ /* remove old pollfds */
...@@ -73,18 +73,15 @@ int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds) ...@@ -73,18 +73,15 @@ int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
} }
pollfds = tmp_pfd; pollfds = tmp_pfd;
pollfds_size++; pollfds_size++;
} else { } else
/* remove not used tmp_pfd */ kfree(tmp_pfd); /* remove not used tmp_pfd */
if (tmp_pfd != NULL)
kfree(tmp_pfd);
}
pollfds[pollfds_num] = ((struct pollfd) { .fd = fd, pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
.events = events, .events = events,
.revents = 0 }); .revents = 0 });
pollfds_num++; pollfds_num++;
return(0); return 0;
} }
void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg, 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, ...@@ -94,11 +91,11 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
int i = 0; int i = 0;
prev = &active_fds; prev = &active_fds;
while(*prev != NULL){ while (*prev != NULL) {
if((*test)(*prev, arg)){ if ((*test)(*prev, arg)) {
struct irq_fd *old_fd = *prev; struct irq_fd *old_fd = *prev;
if((pollfds[i].fd != -1) && if ((pollfds[i].fd != -1) &&
(pollfds[i].fd != (*prev)->fd)){ (pollfds[i].fd != (*prev)->fd)) {
printk("os_free_irq_by_cb - mismatch between " printk("os_free_irq_by_cb - mismatch between "
"active_fds and pollfds, fd %d vs %d\n", "active_fds and pollfds, fd %d vs %d\n",
(*prev)->fd, pollfds[i].fd); (*prev)->fd, pollfds[i].fd);
...@@ -110,7 +107,6 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg, ...@@ -110,7 +107,6 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
/* This moves the *whole* array after pollfds[i] /* This moves the *whole* array after pollfds[i]
* (though it doesn't spot as such)! * (though it doesn't spot as such)!
*/ */
memmove(&pollfds[i], &pollfds[i + 1], memmove(&pollfds[i], &pollfds[i + 1],
(pollfds_num - i) * sizeof(pollfds[0])); (pollfds_num - i) * sizeof(pollfds[0]));
if(*last_irq_ptr2 == &old_fd->next) 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, ...@@ -129,10 +125,9 @@ void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
return; return;
} }
int os_get_pollfd(int i) int os_get_pollfd(int i)
{ {
return(pollfds[i].fd); return pollfds[i].fd;
} }
void os_set_pollfd(int i, int fd) void os_set_pollfd(int i, int fd)
...@@ -151,8 +146,10 @@ void init_irq_signals(int on_sigstack) ...@@ -151,8 +146,10 @@ void init_irq_signals(int on_sigstack)
int flags; int flags;
flags = on_sigstack ? SA_ONSTACK : 0; flags = on_sigstack ? SA_ONSTACK : 0;
if(timer_irq_inited) h = (__sighandler_t) alarm_handler; if (timer_irq_inited)
else h = boot_timer_handler; h = (__sighandler_t)alarm_handler;
else
h = boot_timer_handler;
set_handler(SIGVTALRM, h, flags | SA_RESTART, set_handler(SIGVTALRM, h, flags | SA_RESTART,
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1); SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment