[PATCH] uml: multicast driver cleanup

Byte-swapping of the port and IP address passed in to the multicast driver by
the user used to happen in different places, which was a bug in itself. The
port also was swapped before being printk-ed, which led to a misleading
message. This patch moves the port swapping to the same place as the IP
address swapping. It also cleans up the error paths of mcast_open.

Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: <viro@parcelfarce.linux.theplanet.co.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Jeff Dike and committed by Linus Torvalds 7c00c31f 060e3522

+16 -35
+1 -3
arch/um/drivers/mcast_kern.c
··· 73 73 struct mcast_init *init = data; 74 74 char *port_str = NULL, *ttl_str = NULL, *remain; 75 75 char *last; 76 - int n; 77 76 78 77 *init = ((struct mcast_init) 79 78 { .addr = "239.192.168.1", ··· 88 89 } 89 90 90 91 if(port_str != NULL){ 91 - n = simple_strtoul(port_str, &last, 10); 92 + init->port = simple_strtoul(port_str, &last, 10); 92 93 if((*last != '\0') || (last == port_str)){ 93 94 printk(KERN_ERR "mcast_setup - Bad port : '%s'\n", 94 95 port_str); 95 96 return(0); 96 97 } 97 - init->port = htons(n); 98 98 } 99 99 100 100 if(ttl_str != NULL){
+15 -32
arch/um/drivers/mcast_user.c
··· 38 38 } 39 39 sin->sin_family = AF_INET; 40 40 sin->sin_addr.s_addr = in_aton(addr); 41 - sin->sin_port = port; 41 + sin->sin_port = htons(port); 42 42 return(sin); 43 43 } 44 44 ··· 55 55 struct mcast_data *pri = data; 56 56 struct sockaddr_in *sin = pri->mcast_addr; 57 57 struct ip_mreq mreq; 58 - int fd, yes = 1; 58 + int fd = -EINVAL, yes = 1, err = -EINVAL;; 59 59 60 60 61 - if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0)) { 62 - fd = -EINVAL; 61 + if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0)) 63 62 goto out; 64 - } 65 63 66 64 fd = socket(AF_INET, SOCK_DGRAM, 0); 65 + 67 66 if (fd < 0){ 68 67 printk("mcast_open : data socket failed, errno = %d\n", 69 68 errno); 70 - fd = -ENOMEM; 69 + fd = -errno; 71 70 goto out; 72 71 } 73 72 74 73 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { 75 74 printk("mcast_open: SO_REUSEADDR failed, errno = %d\n", 76 75 errno); 77 - os_close_file(fd); 78 - fd = -EINVAL; 79 - goto out; 76 + goto out_close; 80 77 } 81 78 82 79 /* set ttl according to config */ ··· 81 84 sizeof(pri->ttl)) < 0) { 82 85 printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n", 83 86 errno); 84 - os_close_file(fd); 85 - fd = -EINVAL; 86 - goto out; 87 + goto out_close; 87 88 } 88 89 89 90 /* set LOOP, so data does get fed back to local sockets */ 90 91 if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) { 91 92 printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n", 92 93 errno); 93 - os_close_file(fd); 94 - fd = -EINVAL; 95 - goto out; 94 + goto out_close; 96 95 } 97 96 98 97 /* bind socket to mcast address */ 99 98 if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) { 100 99 printk("mcast_open : data bind failed, errno = %d\n", errno); 101 - os_close_file(fd); 102 - fd = -EINVAL; 103 - goto out; 100 + goto out_close; 104 101 } 105 102 106 103 /* subscribe to the multicast group */ ··· 108 117 "interface on the host.\n"); 109 118 printk("eth0 should be configured in order to use the " 110 119 "multicast transport.\n"); 111 - os_close_file(fd); 112 - fd = -EINVAL; 120 + goto out_close; 113 121 } 114 122 115 123 out: 116 - return(fd); 124 + return fd; 125 + 126 + out_close: 127 + os_close_file(fd); 128 + return err; 117 129 } 118 130 119 131 static void mcast_close(int fd, void *data) ··· 158 164 .delete_address = NULL, 159 165 .max_packet = MAX_PACKET - ETH_HEADER_OTHER 160 166 }; 161 - 162 - /* 163 - * Overrides for Emacs so that we follow Linus's tabbing style. 164 - * Emacs will notice this stuff at the end of the file and automatically 165 - * adjust the settings for this buffer only. This must remain at the end 166 - * of the file. 167 - * --------------------------------------------------------------------------- 168 - * Local variables: 169 - * c-file-style: "linux" 170 - * End: 171 - */