Commit a8147d73 authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

net/atm/common.c: checkpatch cleanups

Convert #include <asm... to #include <linux...
Move EXPORT_SYMBOL
Spacing cleanups
Use __func__ in printks
Indent switch/case statements
Move trailing statements to new line
Hoist assigns from if tests
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e956ea1b
...@@ -19,11 +19,10 @@ ...@@ -19,11 +19,10 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/init.h> #include <linux/init.h>
#include <net/sock.h> /* struct sock */ #include <net/sock.h> /* struct sock */
#include <linux/uaccess.h>
#include <linux/poll.h>
#include <asm/uaccess.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/poll.h>
#include "resources.h" /* atm_find_dev */ #include "resources.h" /* atm_find_dev */
#include "common.h" /* prototypes */ #include "common.h" /* prototypes */
...@@ -32,13 +31,15 @@ ...@@ -32,13 +31,15 @@
#include "signaling.h" /* for WAITING and sigd_attach */ #include "signaling.h" /* for WAITING and sigd_attach */
struct hlist_head vcc_hash[VCC_HTABLE_SIZE]; struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
EXPORT_SYMBOL(vcc_hash);
DEFINE_RWLOCK(vcc_sklist_lock); DEFINE_RWLOCK(vcc_sklist_lock);
EXPORT_SYMBOL(vcc_sklist_lock);
static void __vcc_insert_socket(struct sock *sk) static void __vcc_insert_socket(struct sock *sk)
{ {
struct atm_vcc *vcc = atm_sk(sk); struct atm_vcc *vcc = atm_sk(sk);
struct hlist_head *head = &vcc_hash[vcc->vci & struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
(VCC_HTABLE_SIZE - 1)];
sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1); sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
sk_add_node(sk, head); sk_add_node(sk, head);
} }
...@@ -49,6 +50,7 @@ void vcc_insert_socket(struct sock *sk) ...@@ -49,6 +50,7 @@ void vcc_insert_socket(struct sock *sk)
__vcc_insert_socket(sk); __vcc_insert_socket(sk);
write_unlock_irq(&vcc_sklist_lock); write_unlock_irq(&vcc_sklist_lock);
} }
EXPORT_SYMBOL(vcc_insert_socket);
static void vcc_remove_socket(struct sock *sk) static void vcc_remove_socket(struct sock *sk)
{ {
...@@ -57,8 +59,7 @@ static void vcc_remove_socket(struct sock *sk) ...@@ -57,8 +59,7 @@ static void vcc_remove_socket(struct sock *sk)
write_unlock_irq(&vcc_sklist_lock); write_unlock_irq(&vcc_sklist_lock);
} }
static struct sk_buff *alloc_tx(struct atm_vcc *vcc, unsigned int size)
static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct sock *sk = sk_atm(vcc); struct sock *sk = sk_atm(vcc);
...@@ -70,23 +71,20 @@ static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size) ...@@ -70,23 +71,20 @@ static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
} }
while (!(skb = alloc_skb(size, GFP_KERNEL))) while (!(skb = alloc_skb(size, GFP_KERNEL)))
schedule(); schedule();
pr_debug("AlTx %d += %d\n", sk_wmem_alloc_get(sk), skb->truesize); pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
atomic_add(skb->truesize, &sk->sk_wmem_alloc); atomic_add(skb->truesize, &sk->sk_wmem_alloc);
return skb; return skb;
} }
EXPORT_SYMBOL(vcc_hash);
EXPORT_SYMBOL(vcc_sklist_lock);
EXPORT_SYMBOL(vcc_insert_socket);
static void vcc_sock_destruct(struct sock *sk) static void vcc_sock_destruct(struct sock *sk)
{ {
if (atomic_read(&sk->sk_rmem_alloc)) if (atomic_read(&sk->sk_rmem_alloc))
printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_rmem_alloc)); printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
__func__, atomic_read(&sk->sk_rmem_alloc));
if (atomic_read(&sk->sk_wmem_alloc)) if (atomic_read(&sk->sk_wmem_alloc))
printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_wmem_alloc)); printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
__func__, atomic_read(&sk->sk_wmem_alloc));
} }
static void vcc_def_wakeup(struct sock *sk) static void vcc_def_wakeup(struct sock *sk)
...@@ -142,8 +140,8 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family) ...@@ -142,8 +140,8 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
vcc = atm_sk(sk); vcc = atm_sk(sk);
vcc->dev = NULL; vcc->dev = NULL;
memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc)); memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc)); memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */ vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
atomic_set(&sk->sk_wmem_alloc, 1); atomic_set(&sk->sk_wmem_alloc, 1);
atomic_set(&sk->sk_rmem_alloc, 0); atomic_set(&sk->sk_rmem_alloc, 0);
...@@ -156,7 +154,6 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family) ...@@ -156,7 +154,6 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
return 0; return 0;
} }
static void vcc_destroy_socket(struct sock *sk) static void vcc_destroy_socket(struct sock *sk)
{ {
struct atm_vcc *vcc = atm_sk(sk); struct atm_vcc *vcc = atm_sk(sk);
...@@ -171,7 +168,7 @@ static void vcc_destroy_socket(struct sock *sk) ...@@ -171,7 +168,7 @@ static void vcc_destroy_socket(struct sock *sk)
vcc->push(vcc, NULL); /* atmarpd has no push */ vcc->push(vcc, NULL); /* atmarpd has no push */
while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
atm_return(vcc,skb->truesize); atm_return(vcc, skb->truesize);
kfree_skb(skb); kfree_skb(skb);
} }
...@@ -182,7 +179,6 @@ static void vcc_destroy_socket(struct sock *sk) ...@@ -182,7 +179,6 @@ static void vcc_destroy_socket(struct sock *sk)
vcc_remove_socket(sk); vcc_remove_socket(sk);
} }
int vcc_release(struct socket *sock) int vcc_release(struct socket *sock)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -197,7 +193,6 @@ int vcc_release(struct socket *sock) ...@@ -197,7 +193,6 @@ int vcc_release(struct socket *sock)
return 0; return 0;
} }
void vcc_release_async(struct atm_vcc *vcc, int reply) void vcc_release_async(struct atm_vcc *vcc, int reply)
{ {
struct sock *sk = sk_atm(vcc); struct sock *sk = sk_atm(vcc);
...@@ -208,8 +203,6 @@ void vcc_release_async(struct atm_vcc *vcc, int reply) ...@@ -208,8 +203,6 @@ void vcc_release_async(struct atm_vcc *vcc, int reply)
clear_bit(ATM_VF_WAITING, &vcc->flags); clear_bit(ATM_VF_WAITING, &vcc->flags);
sk->sk_state_change(sk); sk->sk_state_change(sk);
} }
EXPORT_SYMBOL(vcc_release_async); EXPORT_SYMBOL(vcc_release_async);
...@@ -235,12 +228,12 @@ void atm_dev_release_vccs(struct atm_dev *dev) ...@@ -235,12 +228,12 @@ void atm_dev_release_vccs(struct atm_dev *dev)
write_unlock_irq(&vcc_sklist_lock); write_unlock_irq(&vcc_sklist_lock);
} }
static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
{ {
int max_sdu; int max_sdu;
if (!tp->traffic_class) return 0; if (!tp->traffic_class)
return 0;
switch (aal) { switch (aal) {
case ATM_AAL0: case ATM_AAL0:
max_sdu = ATM_CELL_SIZE-1; max_sdu = ATM_CELL_SIZE-1;
...@@ -254,17 +247,18 @@ static int adjust_tp(struct atm_trafprm *tp,unsigned char aal) ...@@ -254,17 +247,18 @@ static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
case ATM_AAL5: case ATM_AAL5:
max_sdu = ATM_MAX_AAL5_PDU; max_sdu = ATM_MAX_AAL5_PDU;
} }
if (!tp->max_sdu) tp->max_sdu = max_sdu; if (!tp->max_sdu)
else if (tp->max_sdu > max_sdu) return -EINVAL; tp->max_sdu = max_sdu;
if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV; else if (tp->max_sdu > max_sdu)
return -EINVAL;
if (!tp->max_cdv)
tp->max_cdv = ATM_MAX_CDV;
return 0; return 0;
} }
static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
{ {
struct hlist_head *head = &vcc_hash[vci & struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
(VCC_HTABLE_SIZE - 1)];
struct hlist_node *node; struct hlist_node *node;
struct sock *s; struct sock *s;
struct atm_vcc *walk; struct atm_vcc *walk;
...@@ -288,7 +282,6 @@ static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) ...@@ -288,7 +282,6 @@ static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
return 0; return 0;
} }
static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
{ {
static short p; /* poor man's per-device cache */ static short p; /* poor man's per-device cache */
...@@ -326,14 +319,13 @@ static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) ...@@ -326,14 +319,13 @@ static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) && if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
*vpi == ATM_VPI_ANY) { *vpi == ATM_VPI_ANY) {
p++; p++;
if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0; if (p >= 1 << vcc->dev->ci_range.vpi_bits)
} p = 0;
} }
while (old_p != p || old_c != c); } while (old_p != p || old_c != c);
return -EADDRINUSE; return -EADDRINUSE;
} }
static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
int vci) int vci)
{ {
...@@ -380,8 +372,10 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, ...@@ -380,8 +372,10 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
default: default:
error = -EPROTOTYPE; error = -EPROTOTYPE;
} }
if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal); if (!error)
if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal); error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
if (!error)
error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
if (error) if (error)
goto fail; goto fail;
pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal); pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
...@@ -397,7 +391,8 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, ...@@ -397,7 +391,8 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
vcc->qos.rxtp.max_sdu); vcc->qos.rxtp.max_sdu);
if (dev->ops->open) { if (dev->ops->open) {
if ((error = dev->ops->open(vcc))) error = dev->ops->open(vcc);
if (error)
goto fail; goto fail;
} }
return 0; return 0;
...@@ -411,7 +406,6 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, ...@@ -411,7 +406,6 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
return error; return error;
} }
int vcc_connect(struct socket *sock, int itf, short vpi, int vci) int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
{ {
struct atm_dev *dev; struct atm_dev *dev;
...@@ -427,16 +421,16 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci) ...@@ -427,16 +421,16 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
return -EINVAL; return -EINVAL;
if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC) if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
clear_bit(ATM_VF_PARTIAL,&vcc->flags); clear_bit(ATM_VF_PARTIAL, &vcc->flags);
else else
if (test_bit(ATM_VF_PARTIAL,&vcc->flags)) if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
return -EINVAL; return -EINVAL;
pr_debug("(TX: cl %d,bw %d-%d,sdu %d; " pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
"RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n", "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr, vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu, vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr, vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu, vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL5 ? "" :
vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ", vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal); vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
...@@ -446,12 +440,14 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci) ...@@ -446,12 +440,14 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
return -EINVAL; return -EINVAL;
if (likely(itf != ATM_ITF_ANY)) { if (likely(itf != ATM_ITF_ANY)) {
dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf); dev = try_then_request_module(atm_dev_lookup(itf),
"atm-device-%d", itf);
} else { } else {
dev = NULL; dev = NULL;
mutex_lock(&atm_dev_mutex); mutex_lock(&atm_dev_mutex);
if (!list_empty(&atm_devs)) { if (!list_empty(&atm_devs)) {
dev = list_entry(atm_devs.next, struct atm_dev, dev_list); dev = list_entry(atm_devs.next,
struct atm_dev, dev_list);
atm_dev_hold(dev); atm_dev_hold(dev);
} }
mutex_unlock(&atm_dev_mutex); mutex_unlock(&atm_dev_mutex);
...@@ -464,13 +460,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci) ...@@ -464,13 +460,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
return error; return error;
} }
if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
set_bit(ATM_VF_PARTIAL,&vcc->flags); set_bit(ATM_VF_PARTIAL, &vcc->flags);
if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags)) if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
sock->state = SS_CONNECTED; sock->state = SS_CONNECTED;
return 0; return 0;
} }
int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
size_t size, int flags) size_t size, int flags)
{ {
...@@ -484,8 +479,8 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -484,8 +479,8 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */ if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */
return -EOPNOTSUPP; return -EOPNOTSUPP;
vcc = ATM_SD(sock); vcc = ATM_SD(sock);
if (test_bit(ATM_VF_RELEASED,&vcc->flags) || if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
test_bit(ATM_VF_CLOSE,&vcc->flags) || test_bit(ATM_VF_CLOSE, &vcc->flags) ||
!test_bit(ATM_VF_READY, &vcc->flags)) !test_bit(ATM_VF_READY, &vcc->flags))
return 0; return 0;
...@@ -509,7 +504,6 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -509,7 +504,6 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
return copied; return copied;
} }
int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
size_t total_len) size_t total_len)
{ {
...@@ -517,7 +511,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, ...@@ -517,7 +511,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
struct atm_vcc *vcc; struct atm_vcc *vcc;
struct sk_buff *skb; struct sk_buff *skb;
int eff,error; int eff, error;
const void __user *buff; const void __user *buff;
int size; int size;
...@@ -556,7 +550,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, ...@@ -556,7 +550,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
eff = (size+3) & ~3; /* align to word boundary */ eff = (size+3) & ~3; /* align to word boundary */
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
error = 0; error = 0;
while (!(skb = alloc_tx(vcc,eff))) { while (!(skb = alloc_tx(vcc, eff))) {
if (m->msg_flags & MSG_DONTWAIT) { if (m->msg_flags & MSG_DONTWAIT) {
error = -EAGAIN; error = -EAGAIN;
break; break;
...@@ -566,9 +560,9 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, ...@@ -566,9 +560,9 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
error = -ERESTARTSYS; error = -ERESTARTSYS;
break; break;
} }
if (test_bit(ATM_VF_RELEASED,&vcc->flags) || if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
test_bit(ATM_VF_CLOSE,&vcc->flags) || test_bit(ATM_VF_CLOSE, &vcc->flags) ||
!test_bit(ATM_VF_READY,&vcc->flags)) { !test_bit(ATM_VF_READY, &vcc->flags)) {
error = -EPIPE; error = -EPIPE;
send_sig(SIGPIPE, current, 0); send_sig(SIGPIPE, current, 0);
break; break;
...@@ -580,20 +574,20 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, ...@@ -580,20 +574,20 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
goto out; goto out;
skb->dev = NULL; /* for paths shared with net_device interfaces */ skb->dev = NULL; /* for paths shared with net_device interfaces */
ATM_SKB(skb)->atm_options = vcc->atm_options; ATM_SKB(skb)->atm_options = vcc->atm_options;
if (copy_from_user(skb_put(skb,size),buff,size)) { if (copy_from_user(skb_put(skb, size), buff, size)) {
kfree_skb(skb); kfree_skb(skb);
error = -EFAULT; error = -EFAULT;
goto out; goto out;
} }
if (eff != size) memset(skb->data+size,0,eff-size); if (eff != size)
error = vcc->dev->ops->send(vcc,skb); memset(skb->data + size, 0, eff-size);
error = vcc->dev->ops->send(vcc, skb);
error = error ? error : size; error = error ? error : size;
out: out:
release_sock(sk); release_sock(sk);
return error; return error;
} }
unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -629,8 +623,7 @@ unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) ...@@ -629,8 +623,7 @@ unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
return mask; return mask;
} }
static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
{ {
int error; int error;
...@@ -642,25 +635,31 @@ static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos) ...@@ -642,25 +635,31 @@ static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class || qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
qos->txtp.traffic_class != vcc->qos.txtp.traffic_class) qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
return -EINVAL; return -EINVAL;
error = adjust_tp(&qos->txtp,qos->aal); error = adjust_tp(&qos->txtp, qos->aal);
if (!error) error = adjust_tp(&qos->rxtp,qos->aal); if (!error)
if (error) return error; error = adjust_tp(&qos->rxtp, qos->aal);
if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP; if (error)
return error;
if (!vcc->dev->ops->change_qos)
return -EOPNOTSUPP;
if (sk_atm(vcc)->sk_family == AF_ATMPVC) if (sk_atm(vcc)->sk_family == AF_ATMPVC)
return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET); return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
return svc_change_qos(vcc,qos); return svc_change_qos(vcc, qos);
} }
static int check_tp(const struct atm_trafprm *tp) static int check_tp(const struct atm_trafprm *tp)
{ {
/* @@@ Should be merged with adjust_tp */ /* @@@ Should be merged with adjust_tp */
if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0; if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
return 0;
if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr && if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
!tp->max_pcr) return -EINVAL; !tp->max_pcr)
if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL; return -EINVAL;
if (tp->min_pcr == ATM_MAX_PCR)
return -EINVAL;
if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
tp->min_pcr > tp->max_pcr) return -EINVAL; tp->min_pcr > tp->max_pcr)
return -EINVAL;
/* /*
* We allow pcr to be outside [min_pcr,max_pcr], because later * We allow pcr to be outside [min_pcr,max_pcr], because later
* adjustment may still push it in the valid range. * adjustment may still push it in the valid range.
...@@ -668,7 +667,6 @@ static int check_tp(const struct atm_trafprm *tp) ...@@ -668,7 +667,6 @@ static int check_tp(const struct atm_trafprm *tp)
return 0; return 0;
} }
static int check_qos(const struct atm_qos *qos) static int check_qos(const struct atm_qos *qos)
{ {
int error; int error;
...@@ -678,9 +676,11 @@ static int check_qos(const struct atm_qos *qos) ...@@ -678,9 +676,11 @@ static int check_qos(const struct atm_qos *qos)
if (qos->txtp.traffic_class != qos->rxtp.traffic_class && if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
qos->txtp.traffic_class && qos->rxtp.traffic_class && qos->txtp.traffic_class && qos->rxtp.traffic_class &&
qos->txtp.traffic_class != ATM_ANYCLASS && qos->txtp.traffic_class != ATM_ANYCLASS &&
qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL; qos->rxtp.traffic_class != ATM_ANYCLASS)
return -EINVAL;
error = check_tp(&qos->txtp); error = check_tp(&qos->txtp);
if (error) return error; if (error)
return error;
return check_tp(&qos->rxtp); return check_tp(&qos->rxtp);
} }
...@@ -700,33 +700,37 @@ int vcc_setsockopt(struct socket *sock, int level, int optname, ...@@ -700,33 +700,37 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
{ {
struct atm_qos qos; struct atm_qos qos;
if (copy_from_user(&qos,optval,sizeof(qos))) if (copy_from_user(&qos, optval, sizeof(qos)))
return -EFAULT; return -EFAULT;
error = check_qos(&qos); error = check_qos(&qos);
if (error) return error; if (error)
return error;
if (sock->state == SS_CONNECTED) if (sock->state == SS_CONNECTED)
return atm_change_qos(vcc,&qos); return atm_change_qos(vcc, &qos);
if (sock->state != SS_UNCONNECTED) if (sock->state != SS_UNCONNECTED)
return -EBADFD; return -EBADFD;
vcc->qos = qos; vcc->qos = qos;
set_bit(ATM_VF_HASQOS,&vcc->flags); set_bit(ATM_VF_HASQOS, &vcc->flags);
return 0; return 0;
} }
case SO_SETCLP: case SO_SETCLP:
if (get_user(value,(unsigned long __user *)optval)) if (get_user(value, (unsigned long __user *)optval))
return -EFAULT; return -EFAULT;
if (value) vcc->atm_options |= ATM_ATMOPT_CLP; if (value)
else vcc->atm_options &= ~ATM_ATMOPT_CLP; vcc->atm_options |= ATM_ATMOPT_CLP;
else
vcc->atm_options &= ~ATM_ATMOPT_CLP;
return 0; return 0;
default: default:
if (level == SOL_SOCKET) return -EINVAL; if (level == SOL_SOCKET)
return -EINVAL;
break; break;
} }
if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL; if (!vcc->dev || !vcc->dev->ops->setsockopt)
return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen); return -EINVAL;
return vcc->dev->ops->setsockopt(vcc, level, optname, optval, optlen);
} }
int vcc_getsockopt(struct socket *sock, int level, int optname, int vcc_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen) char __user *optval, int __user *optlen)
{ {
...@@ -741,32 +745,32 @@ int vcc_getsockopt(struct socket *sock, int level, int optname, ...@@ -741,32 +745,32 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
vcc = ATM_SD(sock); vcc = ATM_SD(sock);
switch (optname) { switch (optname) {
case SO_ATMQOS: case SO_ATMQOS:
if (!test_bit(ATM_VF_HASQOS,&vcc->flags)) if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
return -EINVAL; return -EINVAL;
return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ? return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
-EFAULT : 0; ? -EFAULT : 0;
case SO_SETCLP: case SO_SETCLP:
return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
0,(unsigned long __user *)optval) ? -EFAULT : 0; (unsigned long __user *)optval) ? -EFAULT : 0;
case SO_ATMPVC: case SO_ATMPVC:
{ {
struct sockaddr_atmpvc pvc; struct sockaddr_atmpvc pvc;
if (!vcc->dev || if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
!test_bit(ATM_VF_ADDR,&vcc->flags))
return -ENOTCONN; return -ENOTCONN;
pvc.sap_family = AF_ATMPVC; pvc.sap_family = AF_ATMPVC;
pvc.sap_addr.itf = vcc->dev->number; pvc.sap_addr.itf = vcc->dev->number;
pvc.sap_addr.vpi = vcc->vpi; pvc.sap_addr.vpi = vcc->vpi;
pvc.sap_addr.vci = vcc->vci; pvc.sap_addr.vci = vcc->vci;
return copy_to_user(optval,&pvc,sizeof(pvc)) ? return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
-EFAULT : 0;
} }
default: default:
if (level == SOL_SOCKET) return -EINVAL; if (level == SOL_SOCKET)
return -EINVAL;
break; break;
} }
if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL; if (!vcc->dev || !vcc->dev->ops->getsockopt)
return -EINVAL;
return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len); return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
} }
...@@ -774,22 +778,26 @@ static int __init atm_init(void) ...@@ -774,22 +778,26 @@ static int __init atm_init(void)
{ {
int error; int error;
if ((error = proto_register(&vcc_proto, 0)) < 0) error = proto_register(&vcc_proto, 0);
if (error < 0)
goto out; goto out;
error = atmpvc_init();
if ((error = atmpvc_init()) < 0) { if (error < 0) {
pr_err("atmpvc_init() failed with %d\n", error); pr_err("atmpvc_init() failed with %d\n", error);
goto out_unregister_vcc_proto; goto out_unregister_vcc_proto;
} }
if ((error = atmsvc_init()) < 0) { error = atmsvc_init();
if (error < 0) {
pr_err("atmsvc_init() failed with %d\n", error); pr_err("atmsvc_init() failed with %d\n", error);
goto out_atmpvc_exit; goto out_atmpvc_exit;
} }
if ((error = atm_proc_init()) < 0) { error = atm_proc_init();
if (error < 0) {
pr_err("atm_proc_init() failed with %d\n", error); pr_err("atm_proc_init() failed with %d\n", error);
goto out_atmsvc_exit; goto out_atmsvc_exit;
} }
if ((error = atm_sysfs_init()) < 0) { error = atm_sysfs_init();
if (error < 0) {
pr_err("atm_sysfs_init() failed with %d\n", error); pr_err("atm_sysfs_init() failed with %d\n", error);
goto out_atmproc_exit; goto out_atmproc_exit;
} }
......
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