Skip to content

Commit

Permalink
uml: network formatting
Browse files Browse the repository at this point in the history
Style and other non-functional changes in the UML networking code, including
	include tidying
	style violations
	copyright updates
	printks getting severities
	userspace code calling libc directly rather than using the os_*
wrappers

There's also a exit path cleanup in the pcap driver.

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>
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed Oct 16, 2007
1 parent 1a80521 commit cd1ae0e
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 616 deletions.
20 changes: 7 additions & 13 deletions arch/um/drivers/daemon.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
/*
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/

#ifndef __DAEMON_H__
#define __DAEMON_H__

#include "net_user.h"

#define SWITCH_VERSION 3
Expand All @@ -20,16 +23,7 @@ struct daemon_data {

extern const struct net_user_info daemon_user_info;

extern int daemon_user_write(int fd, void *buf, int len,
extern int daemon_user_write(int fd, void *buf, int len,
struct daemon_data *pri);

/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#endif
31 changes: 15 additions & 16 deletions arch/um/drivers/daemon_kern.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/

#include "linux/kernel.h"
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "daemon.h"

struct daemon_init {
Expand All @@ -36,25 +34,26 @@ static void daemon_init(struct net_device *dev, void *data)
dpri->data_addr = NULL;
dpri->local_addr = NULL;

printk("daemon backend (uml_switch version %d) - %s:%s",
printk("daemon backend (uml_switch version %d) - %s:%s",
SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
printk("\n");
}

static int daemon_read(int fd, struct sk_buff **skb,
static int daemon_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
if (*skb == NULL)
return -ENOMEM;
return net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER);
}

static int daemon_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
(struct daemon_data *) &lp->user));
return daemon_user_write(fd, (*skb)->data, (*skb)->len,
(struct daemon_data *) &lp->user);
}

static const struct net_kern_info daemon_kern_info = {
Expand All @@ -72,14 +71,14 @@ static int daemon_setup(char *str, char **mac_out, void *data)
*init = ((struct daemon_init)
{ .sock_type = "unix",
.ctl_sock = "/tmp/uml.ctl" });

remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
NULL);
if(remain != NULL)
if (remain != NULL)
printk(KERN_WARNING "daemon_setup : Ignoring data socket "
"specification\n");
return(1);

return 1;
}

static struct transport daemon_transport = {
Expand Down
81 changes: 42 additions & 39 deletions arch/um/drivers/daemon_user.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/

#include <errno.h>
#include <unistd.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include "net_user.h"
#include <sys/un.h>
#include "daemon.h"
#include "kern_util.h"
#include "user.h"
#include "net_user.h"
#include "os.h"
#include "um_malloc.h"
#include "user.h"

#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)

Expand All @@ -36,8 +37,9 @@ static struct sockaddr_un *new_addr(void *name, int len)
struct sockaddr_un *sun;

sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
if (sun == NULL) {
printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
"failed\n");
return NULL;
}
sun->sun_family = AF_UNIX;
Expand All @@ -54,38 +56,39 @@ static int connect_to_switch(struct daemon_data *pri)
int fd, n, err;

pri->control = socket(AF_UNIX, SOCK_STREAM, 0);
if(pri->control < 0){
if (pri->control < 0) {
err = -errno;
printk("daemon_open : control socket failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : control socket failed, "
"errno = %d\n", -err);
return err;
}

if(connect(pri->control, (struct sockaddr *) ctl_addr,
sizeof(*ctl_addr)) < 0){
if (connect(pri->control, (struct sockaddr *) ctl_addr,
sizeof(*ctl_addr)) < 0) {
err = -errno;
printk("daemon_open : control connect failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : control connect failed, "
"errno = %d\n", -err);
goto out;
}

fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if(fd < 0){
if (fd < 0) {
err = -errno;
printk("daemon_open : data socket failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : data socket failed, "
"errno = %d\n", -err);
goto out;
}
if(bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0){
if (bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0) {
err = -errno;
printk("daemon_open : data bind failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : data bind failed, "
"errno = %d\n", -err);
goto out_close;
}

sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
if (sun == NULL) {
printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
"failed\n");
err = -ENOMEM;
goto out_close;
}
Expand All @@ -94,18 +97,18 @@ static int connect_to_switch(struct daemon_data *pri)
req.version = SWITCH_VERSION;
req.type = REQ_NEW_CONTROL;
req.sock = *local_addr;
n = os_write_file(pri->control, &req, sizeof(req));
if(n != sizeof(req)){
printk("daemon_open : control setup request failed, err = %d\n",
-n);
n = write(pri->control, &req, sizeof(req));
if (n != sizeof(req)) {
printk(UM_KERN_ERR "daemon_open : control setup request "
"failed, err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}

n = os_read_file(pri->control, sun, sizeof(*sun));
if(n != sizeof(*sun)){
printk("daemon_open : read of data socket failed, err = %d\n",
-n);
n = read(pri->control, sun, sizeof(*sun));
if (n != sizeof(*sun)) {
printk(UM_KERN_ERR "daemon_open : read of data socket failed, "
"err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}
Expand All @@ -116,9 +119,9 @@ static int connect_to_switch(struct daemon_data *pri)
out_free:
kfree(sun);
out_close:
os_close_file(fd);
close(fd);
out:
os_close_file(pri->control);
close(pri->control);
return err;
}

Expand All @@ -132,8 +135,8 @@ static int daemon_user_init(void *data, void *dev)
int usecs;
} name;

if(!strcmp(pri->sock_type, "unix"))
pri->ctl_addr = new_addr(pri->ctl_sock,
if (!strcmp(pri->sock_type, "unix"))
pri->ctl_addr = new_addr(pri->ctl_sock,
strlen(pri->ctl_sock) + 1);
name.zero = 0;
name.pid = os_getpid();
Expand All @@ -142,7 +145,7 @@ static int daemon_user_init(void *data, void *dev)
pri->local_addr = new_addr(&name, sizeof(name));
pri->dev = dev;
pri->fd = connect_to_switch(pri);
if(pri->fd < 0){
if (pri->fd < 0) {
kfree(pri->local_addr);
pri->local_addr = NULL;
return pri->fd;
Expand All @@ -161,9 +164,9 @@ static void daemon_remove(void *data)
{
struct daemon_data *pri = data;

os_close_file(pri->fd);
close(pri->fd);
pri->fd = -1;
os_close_file(pri->control);
close(pri->control);
pri->control = -1;

kfree(pri->data_addr);
Expand Down
16 changes: 5 additions & 11 deletions arch/um/drivers/mcast.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/

#ifndef __DRIVERS_MCAST_H
#define __DRIVERS_MCAST_H

#include "net_user.h"

struct mcast_data {
Expand All @@ -18,13 +21,4 @@ extern const struct net_user_info mcast_user_info;
extern int mcast_user_write(int fd, void *buf, int len,
struct mcast_data *pri);

/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#endif
Loading

0 comments on commit cd1ae0e

Please sign in to comment.