[PATCH net-next] net: tcp: update mib LISTENOVERFLOWS if syn flood
From: yuan linyu it's better to update mib LISTENOVERFLOWS even if packet is flood Signed-off-by: yuan linyu --- net/ipv4/tcp_input.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 451ef3012636..581f5b03ae54 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6220,6 +6220,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, struct sock *fastopen_sk = NULL; struct request_sock *req; bool want_cookie = false; + bool want_drop = false; struct dst_entry *dst; struct flowi fl; @@ -6231,14 +6232,17 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, inet_csk_reqsk_queue_is_full(sk)) && !isn) { want_cookie = tcp_syn_flood_action(sk, skb, rsk_ops->slab_name); if (!want_cookie) - goto drop; + want_drop = true; } if (sk_acceptq_is_full(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); - goto drop; + want_drop = true; } + if (want_drop) + goto drop; + req = inet_reqsk_alloc(rsk_ops, sk, !want_cookie); if (!req) goto drop; -- 2.14.1
[PATCH net-next 0/2] net: tap: two minor issue
From: yuan linyu patch1: replay while() loop with % operator in tap_get_queue() patch2: fix POLLOUT condition in tap_poll() --- yuan linyu (2): net: tap: replay while() loop with % operator in tap_get_queue() net: tap: fix POLLOUT condition in tap_poll() drivers/net/tap.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) -- 2.7.4
[PATCH net-next 1/2] net: tap: replay while() loop with % operator in tap_get_queue()
From: yuan linyu Signed-off-by: yuan linyu --- drivers/net/tap.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 0a886fda..78900a0 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -275,11 +275,7 @@ static struct tap_queue *tap_get_queue(struct tap_dev *tap, if (likely(skb_rx_queue_recorded(skb))) { rxq = skb_get_rx_queue(skb); - - while (unlikely(rxq >= numvtaps)) - rxq -= numvtaps; - - queue = rcu_dereference(tap->taps[rxq]); + queue = rcu_dereference(tap->taps[rxq % numvtaps]); goto out; } -- 2.7.4
[PATCH net-next 2/2] net: tap: fix POLLOUT condition in tap_poll()
From: yuan linyu from logical view, if sock_writeable(&q->sk) return false, original second condition will false too, change it and make second condition can return true. Signed-off-by: yuan linyu --- drivers/net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 78900a0..b809405 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -583,8 +583,7 @@ static unsigned int tap_poll(struct file *file, poll_table *wait) mask |= POLLIN | POLLRDNORM; if (sock_writeable(&q->sk) || - (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &q->sock.flags) && -sock_writeable(&q->sk))) + !test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &q->sock.flags)) mask |= POLLOUT | POLLWRNORM; out: -- 2.7.4
[PATCH net-next] net: tap: fix POLLOUT condition in tap_poll()
From: yuan linyu from logical view, if sock_writeable(&q->sk) return false, original second condition will return false too, change it and make second condition can return true. Signed-off-by: yuan linyu --- drivers/net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 0a886fda..72212bf 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -587,8 +587,7 @@ static unsigned int tap_poll(struct file *file, poll_table *wait) mask |= POLLIN | POLLRDNORM; if (sock_writeable(&q->sk) || - (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &q->sock.flags) && -sock_writeable(&q->sk))) + !test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &q->sock.flags)) mask |= POLLOUT | POLLWRNORM; out: -- 2.7.4
[PATCH net-next] net: dpaa: change while() to if() in dpaa_fq_setup()
From: yuan linyu while loop is not needed, because list_for_each_entry() already check all fq. Signed-off-by: yuan linyu --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index 7caa8da..fd0e411 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -931,7 +931,7 @@ static void dpaa_fq_setup(struct dpaa_priv *priv, } /* Make sure all CPUs receive a corresponding Tx queue. */ - while (egress_cnt < DPAA_ETH_TXQ_NUM) { + if (egress_cnt < DPAA_ETH_TXQ_NUM) { list_for_each_entry(fq, &priv->dpaa_fq_list, list) { if (fq->fq_type != FQ_TYPE_TX) continue; -- 2.7.4
Re: [PATCH net-next] net: dpaa: change while() to if() in dpaa_fq_setup()
i am wrong, ignore it. On 六, 2018-01-13 at 17:15 +0800, yuan linyu wrote: > From: yuan linyu > > while loop is not needed, because list_for_each_entry() already check all fq. > > Signed-off-by: yuan linyu > --- > drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c > b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c > index 7caa8da..fd0e411 100644 > --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c > +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c > @@ -931,7 +931,7 @@ static void dpaa_fq_setup(struct dpaa_priv *priv, > } > > /* Make sure all CPUs receive a corresponding Tx queue. */ > - while (egress_cnt < DPAA_ETH_TXQ_NUM) { > + if (egress_cnt < DPAA_ETH_TXQ_NUM) { > list_for_each_entry(fq, &priv->dpaa_fq_list, list) { > if (fq->fq_type != FQ_TYPE_TX) > continue;
[PATCH net-next] net: packet: allow bind to device which is !IFF_UP
From: yuan linyu this try to allow tcpdump to capture packet once device IFF_UP Signed-off-by: yuan linyu --- net/packet/af_packet.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index da215e5..11b19fc 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3124,13 +3124,8 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex, if (proto == 0 || !need_rehook) goto out_unlock; - if (!unlisted && (!dev || (dev->flags & IFF_UP))) { + if (!unlisted) register_prot_hook(sk); - } else { - sk->sk_err = ENETDOWN; - if (!sock_flag(sk, SOCK_DEAD)) - sk->sk_error_report(sk); - } out_unlock: rcu_read_unlock(); -- 2.7.4
[PATCH] net: avoid put_cmsg() possible copy longer data than input
From: yuan linyu if CMSG_ALIGN(sizeof(struct cmsghdr)) > sizeof(struct cmsghdr), original (cmlen - sizeof(struct cmsghdr)) may greater than input len. --- include/linux/socket.h | 12 ++-- net/compat.c | 28 +++- net/core/scm.c | 10 +- net/ipv4/ip_sockglue.c | 2 +- net/rxrpc/sendmsg.c| 2 +- net/socket.c | 3 +-- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index b5cc5a6..72b61d8 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -78,8 +78,8 @@ struct mmsghdr { struct cmsghdr { __kernel_size_t cmsg_len; /* data byte count, including hdr */ -intcmsg_level; /* originating protocol */ -intcmsg_type; /* protocol-specific type */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ }; /* @@ -91,10 +91,10 @@ struct cmsghdr { #define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg)) #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) ) - -#define CMSG_DATA(cmsg)((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr -#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len)) -#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) +#define CMSG_ALIGN_HDR_LEN CMSG_ALIGN(sizeof(struct cmsghdr)) +#define CMSG_DATA(cmsg)((void *)((char *)(cmsg) + CMSG_ALIGN_HDR_LEN)) +#define CMSG_SPACE(len) (CMSG_ALIGN_HDR_LEN + CMSG_ALIGN(len)) +#define CMSG_LEN(len) (CMSG_ALIGN_HDR_LEN + (len)) #define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ? \ (struct cmsghdr *)(ctl) : \ diff --git a/net/compat.c b/net/compat.c index 96c544b..b291ff4 100644 --- a/net/compat.c +++ b/net/compat.c @@ -88,13 +88,13 @@ int get_compat_msghdr(struct msghdr *kmsg, /* Bleech... */ #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32)) - +#define CMSG_COMPAT_ALIGN_HDR_LEN CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) #define CMSG_COMPAT_DATA(cmsg) \ - ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr + ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN_HDR_LEN)) #define CMSG_COMPAT_SPACE(len) \ - (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len)) + (CMSG_COMPAT_ALIGN_HDR_LEN + CMSG_COMPAT_ALIGN(len)) #define CMSG_COMPAT_LEN(len) \ - (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len)) + (CMSG_COMPAT_ALIGN_HDR_LEN + (len)) #define CMSG_COMPAT_FIRSTHDR(msg) \ (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \ @@ -141,9 +141,8 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg)) return -EINVAL; - tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) + - CMSG_ALIGN(sizeof(struct cmsghdr))); - tmp = CMSG_ALIGN(tmp); + tmp = (ucmlen - CMSG_COMPAT_ALIGN_HDR_LEN); + tmp = CMSG_SPACE(tmp); kcmlen += tmp; ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen); } @@ -168,9 +167,8 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, goto Efault; if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg)) goto Einval; - tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) + - CMSG_ALIGN(sizeof(struct cmsghdr))); - if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp)) + tmp = (ucmlen - CMSG_COMPAT_ALIGN_HDR_LEN); + if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_SPACE(tmp)) goto Einval; kcmsg->cmsg_len = tmp; tmp = CMSG_ALIGN(tmp); @@ -178,7 +176,7 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, __get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) || copy_from_user(CMSG_DATA(kcmsg), CMSG_COMPAT_DATA(ucmsg), - (ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg) + (ucmlen - CMSG_COMPAT_ALIGN_HDR_LEN))) goto Efault; /* Advance. */ @@ -245,7 +243,8 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) return -EFAULT; - if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(stru
[PATCH] scm: fix possible control message header alignment issue
From: yuan linyu 1. put_cmsg{_compat}() may copy data to user when buffer free space less than control message header alignment size. 2. scm_detach_fds{_compat}() may calc wrong fdmax if control message header have greater alignment size. Signed-off-by: yuan linyu --- net/compat.c | 10 -- net/core/scm.c | 8 +--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/net/compat.c b/net/compat.c index 96c544b..fe1f41c 100644 --- a/net/compat.c +++ b/net/compat.c @@ -245,7 +245,9 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) return -EFAULT; - if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr))) + if (cmlen > CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) && + copy_to_user(CMSG_COMPAT_DATA(cm), data, + cmlen - CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr return -EFAULT; cmlen = CMSG_COMPAT_SPACE(len); if (kmsg->msg_controllen < cmlen) @@ -258,12 +260,16 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm) { struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; - int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int); + int fdmax = 0; int fdnum = scm->fp->count; struct file **fp = scm->fp->fp; int __user *cmfptr; int err = 0, i; + if (kmsg->msg_controllen > CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))) + fdmax = (kmsg->msg_controllen - +CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))) / sizeof(int); + if (fdnum < fdmax) fdmax = fdnum; diff --git a/net/core/scm.c b/net/core/scm.c index d882043..5d8ef4f 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -238,7 +238,9 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data) err = -EFAULT; if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) goto out; - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr))) + if (cmlen > CMSG_ALIGN(sizeof(struct cmsghdr)) && + copy_to_user(CMSG_DATA(cm), data, + cmlen - CMSG_ALIGN(sizeof(struct cmsghdr goto out; cmlen = CMSG_SPACE(len); if (msg->msg_controllen < cmlen) @@ -267,8 +269,8 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm) return; } - if (msg->msg_controllen > sizeof(struct cmsghdr)) - fdmax = ((msg->msg_controllen - sizeof(struct cmsghdr)) + if (msg->msg_controllen > CMSG_ALIGN(sizeof(struct cmsghdr))) + fdmax = ((msg->msg_controllen - CMSG_ALIGN(sizeof(struct cmsghdr))) / sizeof(int)); if (fdnum < fdmax) -- 2.7.4
[PATCH v2] scm: fix possible control message header alignment issue
From: yuan linyu 1. put_cmsg{_compat}() may copy data to user when buffer free space less than control message header alignment size. 2. scm_detach_fds{_compat}() may calc wrong fdmax if control message header have greater alignment size. Signed-off-by: yuan linyu --- net/compat.c | 10 -- net/core/scm.c | 8 +--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/net/compat.c b/net/compat.c index 96c544b..ffe7a04 100644 --- a/net/compat.c +++ b/net/compat.c @@ -245,7 +245,9 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) return -EFAULT; - if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr))) + if (cmlen > CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) && + copy_to_user(CMSG_COMPAT_DATA(cm), data, + cmlen - CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr return -EFAULT; cmlen = CMSG_COMPAT_SPACE(len); if (kmsg->msg_controllen < cmlen) @@ -258,12 +260,16 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm) { struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; - int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int); + int fdmax = 0; int fdnum = scm->fp->count; struct file **fp = scm->fp->fp; int __user *cmfptr; int err = 0, i; + if (kmsg->msg_controllen > CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))) + fdmax = (kmsg->msg_controllen - +CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))) / sizeof(int); + if (fdnum < fdmax) fdmax = fdnum; diff --git a/net/core/scm.c b/net/core/scm.c index d882043..b2e60fd 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -238,7 +238,9 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data) err = -EFAULT; if (copy_to_user(cm, &cmhdr, sizeof cmhdr)) goto out; - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr))) + if (cmlen > CMSG_ALIGN(sizeof(struct cmsghdr)) && + copy_to_user(CMSG_DATA(cm), data, + cmlen - CMSG_ALIGN(sizeof(struct cmsghdr goto out; cmlen = CMSG_SPACE(len); if (msg->msg_controllen < cmlen) @@ -267,8 +269,8 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm) return; } - if (msg->msg_controllen > sizeof(struct cmsghdr)) - fdmax = ((msg->msg_controllen - sizeof(struct cmsghdr)) + if (msg->msg_controllen > CMSG_ALIGN(sizeof(struct cmsghdr))) + fdmax = ((msg->msg_controllen - CMSG_ALIGN(sizeof(struct cmsghdr))) / sizeof(int)); if (fdnum < fdmax) -- 2.7.4
network packet kernel rate limit
User space application require linux kernel to do rate limit to some type of Ethernet packet(ARP, ICMP, TCP, for example 1000 packet/s) when system run under Ethernet packet flooding test. Do you know if kernel already exist a feature to implement this requirement? Thanks
[PATCH] net: ioctl SIOCSIFADDR minor cleanup
From: yuan linyu 1. set interface address label to ioctl request device name is enough 2. when address pass inet_abc_len check, prefixlen less than 31 is always true Signed-off-by: yuan linyu --- net/ipv4/devinet.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 062a67c..d491a7a 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1063,10 +1063,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!ifa) break; INIT_HLIST_NODE(&ifa->hash); - if (colon) - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); - else - memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); + memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); } else { ret = 0; if (ifa->ifa_local == sin->sin_addr.s_addr) @@ -1081,8 +1078,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!(dev->flags & IFF_POINTOPOINT)) { ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); - if ((dev->flags & IFF_BROADCAST) && - ifa->ifa_prefixlen < 31) + if (dev->flags & IFF_BROADCAST) ifa->ifa_broadcast = ifa->ifa_address | ~ifa->ifa_mask; } else { -- 2.7.4
[PATCH v2] net: ioctl SIOCSIFADDR minor cleanup
From: yuan linyu 1. set interface address label to ioctl request device name is enough 2. when address pass inet_abc_len check, prefixlen < 31 is always true Signed-off-by: yuan linyu --- net/ipv4/devinet.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 062a67c..d491a7a 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1063,10 +1063,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!ifa) break; INIT_HLIST_NODE(&ifa->hash); - if (colon) - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); - else - memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); + memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); } else { ret = 0; if (ifa->ifa_local == sin->sin_addr.s_addr) @@ -1081,8 +1078,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!(dev->flags & IFF_POINTOPOINT)) { ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); - if ((dev->flags & IFF_BROADCAST) && - ifa->ifa_prefixlen < 31) + if (dev->flags & IFF_BROADCAST) ifa->ifa_broadcast = ifa->ifa_address | ~ifa->ifa_mask; } else { -- 2.7.4 --
[PATCH] net: ioctl SIOCSIFADDR minor cleanup
From: yuan linyu 1. set interface address label to ioctl request device name is enough 2. when address pass inet_abc_len check, prefixlen < 31 is always true Signed-off-by: yuan linyu --- net/ipv4/devinet.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 062a67c..d491a7a 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1063,10 +1063,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!ifa) break; INIT_HLIST_NODE(&ifa->hash); - if (colon) - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); - else - memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); + memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); } else { ret = 0; if (ifa->ifa_local == sin->sin_addr.s_addr) @@ -1081,8 +1078,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) if (!(dev->flags & IFF_POINTOPOINT)) { ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); - if ((dev->flags & IFF_BROADCAST) && - ifa->ifa_prefixlen < 31) + if (dev->flags & IFF_BROADCAST) ifa->ifa_broadcast = ifa->ifa_address | ~ifa->ifa_mask; } else { -- 2.7.4
RE: [PATCH] net: ioctl SIOCSIFADDR minor cleanup
hi david, > -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of David Miller > Sent: Wednesday, November 16, 2016 11:01 AM > To: cug...@163.com > Cc: netdev@vger.kernel.org; YUAN Linyu > Subject: Re: [PATCH] net: ioctl SIOCSIFADDR minor cleanup > > From: yuan linyu > Date: Tue, 15 Nov 2016 20:44:59 +0800 > > > @@ -1063,10 +1063,7 @@ int devinet_ioctl(struct net *net, unsigned int > cmd, void __user *arg) > > if (!ifa) > > break; > > INIT_HLIST_NODE(&ifa->hash); > > - if (colon) > > - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); > > - else > > - memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); > > + memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); > > This is an incorrect and untested change. > > If there is a colon character in ifr.ifr_name, earlier in this function > we will: > > 1) First replace that colon with a NULL character. > > 2) Perform __dev_get_by_name() on the result. > > 3) Put the ":" colon character back into ifr.ifr_name > > So the two strings ifr.ifr_name and dev->name can in fact be different > here. Therefore the code has to be left as it is. Here we assign value to ifa->ifa_label. orginal code means when reqest name have colon, then label name will have colon. If request name have no colon, label name will same as dev-name, it's also have no colon. So assign label to request name will do same thing as original code. thanks
RE: [PATCH] net: ioctl SIOCSIFADDR minor cleanup
No, this patch will not change dev->name, It's care about ifa->ifa_label. > - if (colon) > - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); > - else > - memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); When ifr.ifr_name have no colon, dev->name must equal to ifr.ifr_name. So we change to > - else > - memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); Then if and else do same thing. Just one line is enough, memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); > -Original Message- > From: David Miller [mailto:da...@davemloft.net] > Sent: Wednesday, November 16, 2016 11:31 AM > To: YUAN Linyu > Cc: cug...@163.com; netdev@vger.kernel.org > Subject: Re: [PATCH] net: ioctl SIOCSIFADDR minor cleanup > > From: YUAN Linyu > Date: Wed, 16 Nov 2016 03:13:31 + > > > So assign label to request name will do same thing as original code. > > Nope. dev->name does not have the colon, it was trimmed from the > string for the device lookup. So the found device's dev->name does > not have the colon character, even if it was in ifr.ifr_name > > This was my entire point. > > You are changing the behvaior of the code in an invalid way.
RE: [PATCH] net: ioctl SIOCSIFADDR minor cleanup
I think there are newbie include me still use ifconfig utility. So when I check this code, it can be optimized. > -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Cong Wang > Sent: Tuesday, November 22, 2016 12:20 PM > To: YUAN Linyu > Cc: David Miller; cug...@163.com; netdev@vger.kernel.org > Subject: Re: [PATCH] net: ioctl SIOCSIFADDR minor cleanup > > On Tue, Nov 15, 2016 at 7:57 PM, YUAN Linyu > wrote: > > No, this patch will not change dev->name, > > It's care about ifa->ifa_label. > >> - if (colon) > >> - memcpy(ifa->ifa_label, ifr.ifr_name, > IFNAMSIZ); > >> - else > >> - memcpy(ifa->ifa_label, dev->name, > IFNAMSIZ); > > When ifr.ifr_name have no colon, dev->name must equal to ifr.ifr_name. > > So we change to > >> - else > >> - memcpy(ifa->ifa_label, ifr.ifr_name, > IFNAMSIZ); > > Then if and else do same thing. Just one line is enough, > > memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); > > > > I don't understand why you try to optimize a slow path and some kind of > obsolete code.
[PATCH net-next 0/2] net: add skb_memcpy_to[from]_msg()
From: yuan linyu yuan linyu (2): net: move memcpy_to[from]_msg() from skbuff.h to socket.h net: add skb_memcpy_to[from]_msg() to optimize skb code drivers/isdn/mISDN/socket.c| 2 +- drivers/staging/irda/net/af_irda.c | 2 +- include/linux/skbuff.h | 8 include/linux/socket.h | 12 +++- net/appletalk/ddp.c| 2 +- net/ax25/af_ax25.c | 2 +- net/bluetooth/hci_sock.c | 4 ++-- net/bluetooth/rfcomm/sock.c| 2 +- net/bluetooth/sco.c| 2 +- net/caif/caif_socket.c | 6 +++--- net/can/bcm.c | 4 ++-- net/can/raw.c | 4 ++-- net/dccp/proto.c | 2 +- net/decnet/af_decnet.c | 4 ++-- net/ieee802154/socket.c| 4 ++-- net/ipx/ipx_route.c| 2 +- net/key/af_key.c | 2 +- net/l2tp/l2tp_ip.c | 2 +- net/l2tp/l2tp_ppp.c| 2 +- net/llc/af_llc.c | 2 +- net/netlink/af_netlink.c | 2 +- net/nfc/rawsock.c | 2 +- net/packet/af_packet.c | 2 +- net/phonet/datagram.c | 2 +- net/phonet/pep.c | 2 +- 25 files changed, 45 insertions(+), 35 deletions(-) -- 2.7.4
[PATCH net-next 2/2] net: add skb_memcpy_to[from]_msg() to optimize skb code
From: yuan linyu add these two wrappers in skbuff.h which is better named than previous and only used for skb. Signed-off-by: yuan linyu --- drivers/isdn/mISDN/socket.c| 2 +- drivers/staging/irda/net/af_irda.c | 2 +- include/linux/skbuff.h | 10 ++ net/appletalk/ddp.c| 2 +- net/ax25/af_ax25.c | 2 +- net/bluetooth/hci_sock.c | 4 ++-- net/bluetooth/rfcomm/sock.c| 2 +- net/bluetooth/sco.c| 2 +- net/caif/caif_socket.c | 6 +++--- net/can/bcm.c | 4 ++-- net/can/raw.c | 4 ++-- net/dccp/proto.c | 2 +- net/decnet/af_decnet.c | 4 ++-- net/ieee802154/socket.c| 4 ++-- net/ipx/ipx_route.c| 2 +- net/key/af_key.c | 2 +- net/l2tp/l2tp_ip.c | 2 +- net/l2tp/l2tp_ppp.c| 2 +- net/llc/af_llc.c | 2 +- net/netlink/af_netlink.c | 2 +- net/nfc/rawsock.c | 2 +- net/packet/af_packet.c | 2 +- net/phonet/datagram.c | 2 +- net/phonet/pep.c | 2 +- 24 files changed, 40 insertions(+), 30 deletions(-) diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c index c5603d1..19ecf62 100644 --- a/drivers/isdn/mISDN/socket.c +++ b/drivers/isdn/mISDN/socket.c @@ -202,7 +202,7 @@ mISDN_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) if (!skb) goto done; - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; goto done; } diff --git a/drivers/staging/irda/net/af_irda.c b/drivers/staging/irda/net/af_irda.c index 23fa7c8..159fc1a 100644 --- a/drivers/staging/irda/net/af_irda.c +++ b/drivers/staging/irda/net/af_irda.c @@ -1469,7 +1469,7 @@ static int irda_recvmsg_stream(struct socket *sock, struct msghdr *msg, } chunk = min_t(unsigned int, skb->len, size); - if (memcpy_to_msg(msg, skb->data, chunk)) { + if (skb_memcpy_to_msg(msg, skb, chunk)) { skb_queue_head(&sk->sk_receive_queue, skb); if (copied == 0) copied = -EFAULT; diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 90868d1..901fa60 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3294,6 +3294,16 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, gfp_t gfp); +static inline int skb_memcpy_from_msg(struct sk_buff *skb, struct msghdr *msg, int len) +{ + return memcpy_from_msg(skb_put(skb, len), msg, len); +} + +static inline int skb_memcpy_to_msg(struct msghdr *msg, struct sk_buff *skb, int len) +{ + return memcpy_to_msg(msg, skb->data, len); +} + struct skb_checksum_ops { __wsum (*update)(const void *mem, int len, __wsum wsum); __wsum (*combine)(__wsum csum, __wsum csum2, int offset, int len); diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index 5d035c1..c7846c3 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -1658,7 +1658,7 @@ static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) SOCK_DEBUG(sk, "SK %p: Copy user data (%zd bytes).\n", sk, len); - err = memcpy_from_msg(skb_put(skb, len), msg, len); + err = skb_memcpy_from_msg(skb, msg, len); if (err) { kfree_skb(skb); err = -EFAULT; diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index f3f9d18..442763e 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -1552,7 +1552,7 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) skb_reserve(skb, size - len); /* User data follows immediately after the AX.25 data */ - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; kfree_skb(skb); goto out; diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 65d734c..349c79a 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -1601,7 +1601,7 @@ static int hci_logging_frame(struct sock *sk, struct msghdr *msg, int len) if (!skb) return err; - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; goto drop; } @@ -1726,7 +1726,7 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (!skb) goto done; - if (memcpy_from_msg(skb_put(skb, len
[PATCH net-next 1/2] net: move memcpy_to[from]_msg() from skbuff.h to socket.h
From: yuan linyu these two functions used by skb and other places, move to socket.h where struct msghdr defined. Signed-off-by: yuan linyu --- include/linux/skbuff.h | 10 -- include/linux/socket.h | 12 +++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 03634ec2..90868d1 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3294,16 +3294,6 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, gfp_t gfp); -static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len) -{ - return copy_from_iter_full(data, len, &msg->msg_iter) ? 0 : -EFAULT; -} - -static inline int memcpy_to_msg(struct msghdr *msg, void *data, int len) -{ - return copy_to_iter(data, len, &msg->msg_iter) == len ? 0 : -EFAULT; -} - struct skb_checksum_ops { __wsum (*update)(const void *mem, int len, __wsum wsum); __wsum (*combine)(__wsum csum, __wsum csum2, int offset, int len); diff --git a/include/linux/socket.h b/include/linux/socket.h index 8ad963c..c414f1f 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -53,7 +53,17 @@ struct msghdr { unsigned intmsg_flags; /* flags on received message */ struct kiocb*msg_iocb; /* ptr to iocb for async requests */ }; - + +static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len) +{ + return copy_from_iter_full(data, len, &msg->msg_iter) ? 0 : -EFAULT; +} + +static inline int memcpy_to_msg(struct msghdr *msg, void *data, int len) +{ + return copy_to_iter(data, len, &msg->msg_iter) == len ? 0 : -EFAULT; +} + struct user_msghdr { void__user *msg_name; /* ptr to socket address structure */ int msg_namelen;/* size of socket address structure */ -- 2.7.4
[PATCH net-next v2 0/2] net: add memcpy_to[from]_msg()
From: yuan linyu v2: fix kbuild warning yuan linyu (2): net: move memcpy_to[from]_msg() from skbuff.h to socket.h net: add skb_memcpy_to[from]_msg() to optimize skb code drivers/isdn/mISDN/socket.c| 2 +- drivers/staging/irda/net/af_irda.c | 2 +- include/linux/skbuff.h | 8 include/linux/socket.h | 13 - net/appletalk/ddp.c| 2 +- net/ax25/af_ax25.c | 2 +- net/bluetooth/hci_sock.c | 4 ++-- net/bluetooth/rfcomm/sock.c| 2 +- net/bluetooth/sco.c| 2 +- net/caif/caif_socket.c | 6 +++--- net/can/bcm.c | 4 ++-- net/can/raw.c | 4 ++-- net/dccp/proto.c | 2 +- net/decnet/af_decnet.c | 4 ++-- net/ieee802154/socket.c| 4 ++-- net/ipx/ipx_route.c| 2 +- net/key/af_key.c | 2 +- net/l2tp/l2tp_ip.c | 2 +- net/l2tp/l2tp_ppp.c| 2 +- net/llc/af_llc.c | 2 +- net/netlink/af_netlink.c | 2 +- net/nfc/rawsock.c | 2 +- net/packet/af_packet.c | 2 +- net/phonet/datagram.c | 2 +- net/phonet/pep.c | 2 +- 25 files changed, 46 insertions(+), 35 deletions(-) -- 2.7.4
[PATCH net-next v2 1/2] net: move memcpy_to[from]_msg() from skbuff.h to socket.h
From: yuan linyu these two functions used by skb and other places, move to socket.h where struct msghdr defined. Signed-off-by: yuan linyu --- include/linux/skbuff.h | 10 -- include/linux/socket.h | 13 - 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 03634ec2..90868d1 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3294,16 +3294,6 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, gfp_t gfp); -static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len) -{ - return copy_from_iter_full(data, len, &msg->msg_iter) ? 0 : -EFAULT; -} - -static inline int memcpy_to_msg(struct msghdr *msg, void *data, int len) -{ - return copy_to_iter(data, len, &msg->msg_iter) == len ? 0 : -EFAULT; -} - struct skb_checksum_ops { __wsum (*update)(const void *mem, int len, __wsum wsum); __wsum (*combine)(__wsum csum, __wsum csum2, int offset, int len); diff --git a/include/linux/socket.h b/include/linux/socket.h index 8ad963c..0a2048e 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -2,6 +2,7 @@ #define _LINUX_SOCKET_H +#include #include /* arch-dependent defines */ #include /* the SIOCxxx I/O controls */ #include /* iovec support*/ @@ -53,7 +54,17 @@ struct msghdr { unsigned intmsg_flags; /* flags on received message */ struct kiocb*msg_iocb; /* ptr to iocb for async requests */ }; - + +static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len) +{ + return copy_from_iter_full(data, len, &msg->msg_iter) ? 0 : -EFAULT; +} + +static inline int memcpy_to_msg(struct msghdr *msg, void *data, int len) +{ + return copy_to_iter(data, len, &msg->msg_iter) == len ? 0 : -EFAULT; +} + struct user_msghdr { void__user *msg_name; /* ptr to socket address structure */ int msg_namelen;/* size of socket address structure */ -- 2.7.4
[PATCH net-next v2 2/2] net: add skb_memcpy_to[from]_msg() to optimize skb code
From: yuan linyu add these two wrappers in skbuff.h which is better named than previous and only used for skb. Signed-off-by: yuan linyu --- drivers/isdn/mISDN/socket.c| 2 +- drivers/staging/irda/net/af_irda.c | 2 +- include/linux/skbuff.h | 10 ++ net/appletalk/ddp.c| 2 +- net/ax25/af_ax25.c | 2 +- net/bluetooth/hci_sock.c | 4 ++-- net/bluetooth/rfcomm/sock.c| 2 +- net/bluetooth/sco.c| 2 +- net/caif/caif_socket.c | 6 +++--- net/can/bcm.c | 4 ++-- net/can/raw.c | 4 ++-- net/dccp/proto.c | 2 +- net/decnet/af_decnet.c | 4 ++-- net/ieee802154/socket.c| 4 ++-- net/ipx/ipx_route.c| 2 +- net/key/af_key.c | 2 +- net/l2tp/l2tp_ip.c | 2 +- net/l2tp/l2tp_ppp.c| 2 +- net/llc/af_llc.c | 2 +- net/netlink/af_netlink.c | 2 +- net/nfc/rawsock.c | 2 +- net/packet/af_packet.c | 2 +- net/phonet/datagram.c | 2 +- net/phonet/pep.c | 2 +- 24 files changed, 40 insertions(+), 30 deletions(-) diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c index c5603d1..19ecf62 100644 --- a/drivers/isdn/mISDN/socket.c +++ b/drivers/isdn/mISDN/socket.c @@ -202,7 +202,7 @@ mISDN_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) if (!skb) goto done; - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; goto done; } diff --git a/drivers/staging/irda/net/af_irda.c b/drivers/staging/irda/net/af_irda.c index 23fa7c8..159fc1a 100644 --- a/drivers/staging/irda/net/af_irda.c +++ b/drivers/staging/irda/net/af_irda.c @@ -1469,7 +1469,7 @@ static int irda_recvmsg_stream(struct socket *sock, struct msghdr *msg, } chunk = min_t(unsigned int, skb->len, size); - if (memcpy_to_msg(msg, skb->data, chunk)) { + if (skb_memcpy_to_msg(msg, skb, chunk)) { skb_queue_head(&sk->sk_receive_queue, skb); if (copied == 0) copied = -EFAULT; diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 90868d1..901fa60 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3294,6 +3294,16 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, gfp_t gfp); +static inline int skb_memcpy_from_msg(struct sk_buff *skb, struct msghdr *msg, int len) +{ + return memcpy_from_msg(skb_put(skb, len), msg, len); +} + +static inline int skb_memcpy_to_msg(struct msghdr *msg, struct sk_buff *skb, int len) +{ + return memcpy_to_msg(msg, skb->data, len); +} + struct skb_checksum_ops { __wsum (*update)(const void *mem, int len, __wsum wsum); __wsum (*combine)(__wsum csum, __wsum csum2, int offset, int len); diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index 5d035c1..c7846c3 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -1658,7 +1658,7 @@ static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) SOCK_DEBUG(sk, "SK %p: Copy user data (%zd bytes).\n", sk, len); - err = memcpy_from_msg(skb_put(skb, len), msg, len); + err = skb_memcpy_from_msg(skb, msg, len); if (err) { kfree_skb(skb); err = -EFAULT; diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index f3f9d18..442763e 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -1552,7 +1552,7 @@ static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) skb_reserve(skb, size - len); /* User data follows immediately after the AX.25 data */ - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; kfree_skb(skb); goto out; diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 65d734c..349c79a 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -1601,7 +1601,7 @@ static int hci_logging_frame(struct sock *sk, struct msghdr *msg, int len) if (!skb) return err; - if (memcpy_from_msg(skb_put(skb, len), msg, len)) { + if (skb_memcpy_from_msg(skb, msg, len)) { err = -EFAULT; goto drop; } @@ -1726,7 +1726,7 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (!skb) goto done; - if (memcpy_from_msg(skb_put(skb, len
[PATCH net-next] tun: delete original tun_get() and rename __tun_get() to tun_get()
From: yuan linyu it seems no need to keep tun_get() and __tun_get() at same time. Signed-off-by: yuan linyu --- drivers/net/tun.c | 26 +++--- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 3c9985f..206bc6c 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -692,7 +692,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte return err; } -static struct tun_struct *__tun_get(struct tun_file *tfile) +static struct tun_struct *tun_get(struct tun_file *tfile) { struct tun_struct *tun; @@ -705,11 +705,6 @@ static struct tun_struct *__tun_get(struct tun_file *tfile) return tun; } -static struct tun_struct *tun_get(struct file *file) -{ - return __tun_get(file->private_data); -} - static void tun_put(struct tun_struct *tun) { dev_put(tun->dev); @@ -1149,7 +1144,7 @@ static void tun_net_init(struct net_device *dev) static unsigned int tun_chr_poll(struct file *file, poll_table *wait) { struct tun_file *tfile = file->private_data; - struct tun_struct *tun = __tun_get(tfile); + struct tun_struct *tun = tun_get(tfile); struct sock *sk; unsigned int mask = 0; @@ -1569,8 +1564,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, static ssize_t tun_chr_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; - struct tun_struct *tun = tun_get(file); struct tun_file *tfile = file->private_data; + struct tun_struct *tun = tun_get(tfile); ssize_t result; if (!tun) @@ -1754,7 +1749,7 @@ static ssize_t tun_chr_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct file *file = iocb->ki_filp; struct tun_file *tfile = file->private_data; - struct tun_struct *tun = __tun_get(tfile); + struct tun_struct *tun = tun_get(tfile); ssize_t len = iov_iter_count(to), ret; if (!tun) @@ -1831,7 +1826,7 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len) { int ret; struct tun_file *tfile = container_of(sock, struct tun_file, socket); - struct tun_struct *tun = __tun_get(tfile); + struct tun_struct *tun = tun_get(tfile); if (!tun) return -EBADFD; @@ -1847,7 +1842,7 @@ static int tun_recvmsg(struct socket *sock, struct msghdr *m, size_t total_len, int flags) { struct tun_file *tfile = container_of(sock, struct tun_file, socket); - struct tun_struct *tun = __tun_get(tfile); + struct tun_struct *tun = tun_get(tfile); int ret; if (!tun) @@ -1879,7 +1874,7 @@ static int tun_peek_len(struct socket *sock) struct tun_struct *tun; int ret = 0; - tun = __tun_get(tfile); + tun = tun_get(tfile); if (!tun) return 0; @@ -2265,7 +2260,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = 0; rtnl_lock(); - tun = __tun_get(tfile); + tun = tun_get(tfile); if (cmd == TUNSETIFF) { ret = -EEXIST; if (tun) @@ -2612,15 +2607,16 @@ static int tun_chr_close(struct inode *inode, struct file *file) } #ifdef CONFIG_PROC_FS -static void tun_chr_show_fdinfo(struct seq_file *m, struct file *f) +static void tun_chr_show_fdinfo(struct seq_file *m, struct file *file) { + struct tun_file *tfile = file->private_data; struct tun_struct *tun; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); rtnl_lock(); - tun = tun_get(f); + tun = tun_get(tfile); if (tun) tun_get_iff(current->nsproxy->net_ns, tun, &ifr); rtnl_unlock(); -- 2.7.4
[PATCH net-next] idsn: fix wrong skb_put() used
From: yuan linyu in my commit b952f4dff2751252db073c27c0f8a16a416a2ddc, - *(u8 *)skb_put(skb_out, 1) = (u8)(accm >> 24); \ + skb_put(skb_out, (u8)(accm >> 24)); \ it should skb_put_u8() Fixes: b952f4dff275 ("net: manual clean code which call skb_put_[data:zero])") Signed-off-by: yuan linyu --- drivers/isdn/i4l/isdn_bsdcomp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c index 5b64a13..99012c0 100644 --- a/drivers/isdn/i4l/isdn_bsdcomp.c +++ b/drivers/isdn/i4l/isdn_bsdcomp.c @@ -472,7 +472,7 @@ static int bsd_compress(void *state, struct sk_buff *skb_in, struct sk_buff *skb accm |= ((ent) << bitno); \ do { \ if (skb_out && skb_tailroom(skb_out) > 0) \ - skb_put(skb_out, (u8)(accm >> 24)); \ + skb_put_u8(skb_out, (u8)(accm >> 24)); \ accm <<= 8; \ bitno += 8; \ } while (bitno <= 24); \ -- 2.7.4
[PATCH] net: fib: fix fib_new_table() logical issue
From: yuan linyu when CONFIG_IP_MULTIPLE_TABLES defined, if id == RT_TABLE_LOCAL and !net->ipv4.fib_has_custom_rules, fib_new_table() call itself to get RT_TABLE_MAIN table, but if RT_TABLE_MAIN table not exist at this point, this function will become deadloop. the solution is move RT_TABLE_MAIN table create to per-net init. and call fib_get_table() to get RT_TABLE_MAIN table. Signed-off-by: yuan linyu --- net/ipv4/fib_frontend.c | 12 ++-- net/ipv4/fib_rules.c| 11 +++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 4e678fa..4606b4a 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -87,22 +87,14 @@ struct fib_table *fib_new_table(struct net *net, u32 id) return tb; if (id == RT_TABLE_LOCAL && !net->ipv4.fib_has_custom_rules) - alias = fib_new_table(net, RT_TABLE_MAIN); + alias = fib_get_table(net, RT_TABLE_MAIN); tb = fib_trie_table(id, alias); if (!tb) return NULL; - switch (id) { - case RT_TABLE_MAIN: - rcu_assign_pointer(net->ipv4.fib_main, tb); - break; - case RT_TABLE_DEFAULT: + if (id == RT_TABLE_DEFAULT) rcu_assign_pointer(net->ipv4.fib_default, tb); - break; - default: - break; - } h = id & (FIB_TABLE_HASHSZ - 1); hlist_add_head_rcu(&tb->tb_hlist, &net->ipv4.fib_table_hash[h]); diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 778ecf9..a9796ac 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -402,8 +402,14 @@ static int fib_default_rules_init(struct fib_rules_ops *ops) int __net_init fib4_rules_init(struct net *net) { int err; + unsigned int h; + struct fib_table *main_table; struct fib_rules_ops *ops; + main_table = fib_trie_table(RT_TABLE_MAIN, NULL); + if (!main_table) + return -ENOMEM; + ops = fib_rules_register(&fib4_rules_ops_template, net); if (IS_ERR(ops)) return PTR_ERR(ops); @@ -413,11 +419,16 @@ int __net_init fib4_rules_init(struct net *net) goto fail; net->ipv4.rules_ops = ops; net->ipv4.fib_has_custom_rules = false; + + rcu_assign_pointer(net->ipv4.fib_main, main_table); + h = RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1); + hlist_add_head_rcu(&main_table->tb_hlist, &net->ipv4.fib_table_hash[h]); return 0; fail: /* also cleans all rules already added */ fib_rules_unregister(ops); + fib_free_table(main_table); return err; } -- 2.7.4
RE: [PATCH] net: fib: fix fib_new_table() logical issue
Sorry, it's not dead loop, I realized it but I tried to send to mail to note it on my phone, it failed. > -Original Message- > From: Cong Wang [mailto:xiyou.wangc...@gmail.com] > Sent: Thursday, June 22, 2017 6:54 AM > To: yuan linyu > Cc: Linux Kernel Network Developers; David S . Miller; YUAN Linyu > Subject: Re: [PATCH] net: fib: fix fib_new_table() logical issue > > On Wed, Jun 21, 2017 at 7:02 AM, yuan linyu wrote: > > From: yuan linyu > > > > when CONFIG_IP_MULTIPLE_TABLES defined, > > if id == RT_TABLE_LOCAL and !net->ipv4.fib_has_custom_rules, > > fib_new_table() call itself to get RT_TABLE_MAIN table, > > but if RT_TABLE_MAIN table not exist at this point, > > this function will become deadloop. > > Why deadloop here? If fib_new_table() is called recursively, > then main table is created by fib_trie_table() and we return.
RE: [PATCH 1/2] dt-bindings: net: Add bindings for National Instruments XGE netdev
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Moritz Fischer > Sent: Friday, July 14, 2017 5:22 AM > To: netdev@vger.kernel.org > Cc: devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; > da...@davemloft.net; mark.rutl...@arm.com; robh...@kernel.org; Moritz > Fischer > Subject: [PATCH 1/2] dt-bindings: net: Add bindings for National Instruments > XGE netdev > > This adds bindings for the NI XGE 1G/10G network device. > > Signed-off-by: Moritz Fischer > --- > Documentation/devicetree/bindings/net/nixge.c | 32 > +++ > 1 file changed, 32 insertions(+) > create mode 100644 Documentation/devicetree/bindings/net/nixge.c It should be a text file, nixge.txt > > diff --git a/Documentation/devicetree/bindings/net/nixge.c > b/Documentation/devicetree/bindings/net/nixge.c > new file mode 100644 > index 000..9fff5a7
[PATCH net-next v3] net: assign err to 0 at begin in do_setlink() function
From: yuan linyu each netlink attribute have proper process when error happen, when exit one attribute process, it implies that no error, so err = 0; is useless. assign err = 0; at beginning if all attributes not set. v1 -> v2: fix review comment from David, clear err before nla_for_each_nested() v2 -> v3: maybe wrong understanding of David comment, provide a new version Signed-off-by: yuan linyu --- net/core/rtnetlink.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index dabba2a..54f792b 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2075,7 +2075,7 @@ static int do_setlink(const struct sk_buff *skb, struct nlattr **tb, char *ifname, int status) { const struct net_device_ops *ops = dev->netdev_ops; - int err; + int err = 0; if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) { struct net *net = rtnl_link_get_net(dev_net(dev), tb); @@ -2253,7 +2253,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_VF_PORTS]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2261,9 +2260,10 @@ static int do_setlink(const struct sk_buff *skb, int vf; int rem; - err = -EOPNOTSUPP; - if (!ops->ndo_set_vf_port) + if (!ops->ndo_set_vf_port) { + err = -EOPNOTSUPP; goto errout; + } nla_for_each_nested(attr, tb[IFLA_VF_PORTS], rem) { if (nla_type(attr) != IFLA_VF_PORT || @@ -2286,7 +2286,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PORT_SELF]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2326,7 +2325,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PROTO_DOWN]) { err = dev_change_proto_down(dev, -- 2.7.4
Re: [PATCH net-next v3] net: assign err to 0 at begin in do_setlink() function
On 五, 2017-11-17 at 15:08 +0900, David Miller wrote: > From: yuan linyu > Date: Thu, 16 Nov 2017 19:59:48 +0800 > > > From: yuan linyu > > > > each netlink attribute have proper process when error happen, > > when exit one attribute process, it implies that no error, > > so err = 0; is useless. > > > > assign err = 0; at beginning if all attributes not set. > > > > v1 -> v2: > > fix review comment from David, clear err before > > nla_for_each_nested() > > > > v2 -> v3: > > maybe wrong understanding of David comment, > > provide a new version > > > > Signed-off-by: yuan linyu > > I'm sorry I still find it hard to accept this change. > > What about all of the assignments of 'err' which only branch to > 'errout' if err is negative? It is not easy to see that none of those > case ever result in 'err' holding a positive non-zero value. yes, i also try to check any function return > 0, but it hard, maybe some function not follow common rule. > > The code as-is is the easiest to understand, audit and prove correct > in the error-free case. And this because of the explicit clearing or > 'err' to zero late in the function. yes, but this clearing will do three times every function call, but it is not big issue > > Thanks you.
[PATCH net-next] netlink: optimize err assignment
From: yuan linyu Signed-off-by: yuan linyu --- net/netlink/af_netlink.c | 54 +--- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index b9e0ee4..37ce0d3 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -533,14 +533,16 @@ static int netlink_insert(struct sock *sk, u32 portid) lock_sock(sk); - err = nlk_sk(sk)->portid == portid ? 0 : -EBUSY; - if (nlk_sk(sk)->bound) + if (nlk_sk(sk)->bound) { + err = nlk_sk(sk)->portid == portid ? 0 : -EBUSY; goto err; + } - err = -ENOMEM; if (BITS_PER_LONG > 32 && - unlikely(atomic_read(&table->hash.nelems) >= UINT_MAX)) + unlikely(atomic_read(&table->hash.nelems) >= UINT_MAX)) { + err = -ENOMEM; goto err; + } nlk_sk(sk)->portid = portid; sock_hold(sk); @@ -1585,8 +1587,8 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); - unsigned int val = 0; - int err; + unsigned int val; + int err = 0; if (level != SOL_NETLINK) return -ENOPROTOOPT; @@ -1601,7 +1603,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_RECV_PKTINFO; else nlk->flags &= ~NETLINK_F_RECV_PKTINFO; - err = 0; break; case NETLINK_ADD_MEMBERSHIP: case NETLINK_DROP_MEMBERSHIP: { @@ -1623,8 +1624,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, netlink_table_ungrab(); if (optname == NETLINK_DROP_MEMBERSHIP && nlk->netlink_unbind) nlk->netlink_unbind(sock_net(sk), val); - - err = 0; break; } case NETLINK_BROADCAST_ERROR: @@ -1632,7 +1631,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_BROADCAST_SEND_ERROR; else nlk->flags &= ~NETLINK_F_BROADCAST_SEND_ERROR; - err = 0; break; case NETLINK_NO_ENOBUFS: if (val) { @@ -1642,7 +1640,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, } else { nlk->flags &= ~NETLINK_F_RECV_NO_ENOBUFS; } - err = 0; break; case NETLINK_LISTEN_ALL_NSID: if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_BROADCAST)) @@ -1652,21 +1649,18 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_LISTEN_ALL_NSID; else nlk->flags &= ~NETLINK_F_LISTEN_ALL_NSID; - err = 0; break; case NETLINK_CAP_ACK: if (val) nlk->flags |= NETLINK_F_CAP_ACK; else nlk->flags &= ~NETLINK_F_CAP_ACK; - err = 0; break; case NETLINK_EXT_ACK: if (val) nlk->flags |= NETLINK_F_EXT_ACK; else nlk->flags &= ~NETLINK_F_EXT_ACK; - err = 0; break; default: err = -ENOPROTOOPT; @@ -1679,7 +1673,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); - int len, val, err; + int len, val, err = 0; if (level != SOL_NETLINK) return -ENOPROTOOPT; @@ -1698,7 +1692,6 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, optval)) return -EFAULT; - err = 0; break; case NETLINK_BROADCAST_ERROR: if (len < sizeof(int)) @@ -1708,7 +1701,6 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, optval)) return -EFAULT; - err = 0; break; case NETLINK_NO_ENOBUFS: if (len < sizeof(int)) @@ -1718,12 +1710,10 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, op
[PATCH v2 net-next] netlink: optimize err assignment
From: yuan linyu Signed-off-by: yuan linyu --- v2: fix kbuild test warning --- net/netlink/af_netlink.c | 52 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index b9e0ee4..49ba43ea 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -533,14 +533,16 @@ static int netlink_insert(struct sock *sk, u32 portid) lock_sock(sk); - err = nlk_sk(sk)->portid == portid ? 0 : -EBUSY; - if (nlk_sk(sk)->bound) + if (nlk_sk(sk)->bound) { + err = nlk_sk(sk)->portid == portid ? 0 : -EBUSY; goto err; + } - err = -ENOMEM; if (BITS_PER_LONG > 32 && - unlikely(atomic_read(&table->hash.nelems) >= UINT_MAX)) + unlikely(atomic_read(&table->hash.nelems) >= UINT_MAX)) { + err = -ENOMEM; goto err; + } nlk_sk(sk)->portid = portid; sock_hold(sk); @@ -1586,7 +1588,7 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); unsigned int val = 0; - int err; + int err = 0; if (level != SOL_NETLINK) return -ENOPROTOOPT; @@ -1601,7 +1603,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_RECV_PKTINFO; else nlk->flags &= ~NETLINK_F_RECV_PKTINFO; - err = 0; break; case NETLINK_ADD_MEMBERSHIP: case NETLINK_DROP_MEMBERSHIP: { @@ -1623,8 +1624,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, netlink_table_ungrab(); if (optname == NETLINK_DROP_MEMBERSHIP && nlk->netlink_unbind) nlk->netlink_unbind(sock_net(sk), val); - - err = 0; break; } case NETLINK_BROADCAST_ERROR: @@ -1632,7 +1631,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_BROADCAST_SEND_ERROR; else nlk->flags &= ~NETLINK_F_BROADCAST_SEND_ERROR; - err = 0; break; case NETLINK_NO_ENOBUFS: if (val) { @@ -1642,7 +1640,6 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, } else { nlk->flags &= ~NETLINK_F_RECV_NO_ENOBUFS; } - err = 0; break; case NETLINK_LISTEN_ALL_NSID: if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_BROADCAST)) @@ -1652,21 +1649,18 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, nlk->flags |= NETLINK_F_LISTEN_ALL_NSID; else nlk->flags &= ~NETLINK_F_LISTEN_ALL_NSID; - err = 0; break; case NETLINK_CAP_ACK: if (val) nlk->flags |= NETLINK_F_CAP_ACK; else nlk->flags &= ~NETLINK_F_CAP_ACK; - err = 0; break; case NETLINK_EXT_ACK: if (val) nlk->flags |= NETLINK_F_EXT_ACK; else nlk->flags &= ~NETLINK_F_EXT_ACK; - err = 0; break; default: err = -ENOPROTOOPT; @@ -1679,7 +1673,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; struct netlink_sock *nlk = nlk_sk(sk); - int len, val, err; + int len, val, err = 0; if (level != SOL_NETLINK) return -ENOPROTOOPT; @@ -1698,7 +1692,6 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, optval)) return -EFAULT; - err = 0; break; case NETLINK_BROADCAST_ERROR: if (len < sizeof(int)) @@ -1708,7 +1701,6 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, optval)) return -EFAULT; - err = 0; break; case NETLINK_NO_ENOBUFS: if (len < sizeof(int)) @@ -1718,12 +1710,10 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, if (put_user(len, optlen) || put_user(val, op
[PATCH net-next] net: dpaa: remove init which already done in per-cpu allocation
From: yuan linyu Signed-off-by: yuan linyu --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 4 1 file changed, 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index a8d0be8..1ccc316 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2814,10 +2814,6 @@ static int dpaa_eth_probe(struct platform_device *pdev) err = -ENOMEM; goto free_dpaa_fqs; } - for_each_possible_cpu(i) { - percpu_priv = per_cpu_ptr(priv->percpu_priv, i); - memset(percpu_priv, 0, sizeof(*percpu_priv)); - } priv->num_tc = 1; netif_set_real_num_tx_queues(net_dev, priv->num_tc * DPAA_TC_TXQ_NUM); -- 2.7.4
[PATCH net-next 0/2] net: dpaa: two minor cleanup
From: yuan linyu original i try to remove duplicate code which clean allocated per-cpu area, thanks to David S. Miller, there are two build warning as errors. path 1: fix old code maybe-uninitialized warning. path 2: remove duplicate code and fix unused var warning. yuan linyu (2): net: dpaa: fix maybe uninitialized var in dpaa_open() net: dpaa: remove init which already done in per-cpu allocation drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) -- 2.7.4
[PATCH net-next 1/2] net: dpaa: fix maybe uninitialized var in dpaa_open()
From: yuan linyu Signed-off-by: yuan linyu --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index a8d0be8..68f0ac1 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2468,7 +2468,8 @@ static int dpaa_open(struct net_device *net_dev) mac_dev = priv->mac_dev; dpaa_eth_napi_enable(priv); - if (dpaa_phy_init(net_dev)) + err = dpaa_phy_init(net_dev); + if (err) goto phy_init_failed; for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) { -- 2.7.4
[PATCH net-next 2/2] net: dpaa: remove init which already done in per-cpu allocation
From: yuan linyu Signed-off-by: yuan linyu --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 5 - 1 file changed, 5 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index 68f0ac1..969f6b1 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2669,7 +2669,6 @@ static inline u16 dpaa_get_headroom(struct dpaa_buffer_layout *bl) static int dpaa_eth_probe(struct platform_device *pdev) { struct dpaa_bp *dpaa_bps[DPAA_BPS_NUM] = {NULL}; - struct dpaa_percpu_priv *percpu_priv; struct net_device *net_dev = NULL; struct dpaa_fq *dpaa_fq, *tmp; struct dpaa_priv *priv = NULL; @@ -2815,10 +2814,6 @@ static int dpaa_eth_probe(struct platform_device *pdev) err = -ENOMEM; goto free_dpaa_fqs; } - for_each_possible_cpu(i) { - percpu_priv = per_cpu_ptr(priv->percpu_priv, i); - memset(percpu_priv, 0, sizeof(*percpu_priv)); - } priv->num_tc = 1; netif_set_real_num_tx_queues(net_dev, priv->num_tc * DPAA_TC_TXQ_NUM); -- 2.7.4
[PATCH net-next] net: assign err to 0 at begin in do_setlink() function
From: yuan linyu each netlink attribute have proper process when error happen, when exit on attribute process, it implies that no error, so err = 0; is useless. assign err = 0; at beginning if all attributes not set. Signed-off-by: yuan linyu --- net/core/rtnetlink.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index dabba2a..4760249 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2075,7 +2075,7 @@ static int do_setlink(const struct sk_buff *skb, struct nlattr **tb, char *ifname, int status) { const struct net_device_ops *ops = dev->netdev_ops; - int err; + int err = 0; if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) { struct net *net = rtnl_link_get_net(dev_net(dev), tb); @@ -2253,7 +2253,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_VF_PORTS]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2286,7 +2285,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PORT_SELF]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2326,7 +2324,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PROTO_DOWN]) { err = dev_change_proto_down(dev, -- 2.7.4
[PATCH net-next] net: assign err to 0 at begin in do_setlink() function
From: yuan linyu each netlink attribute have proper process when error happen, when exit one attribute process, it implies that no error, so err = 0; is useless. assign err = 0; at beginning if all attributes not set. v1 -> v2: fix review comment from David, clear err before nla_for_each_nested() Signed-off-by: yuan linyu --- net/core/rtnetlink.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index dabba2a..4c75e40 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2075,7 +2075,7 @@ static int do_setlink(const struct sk_buff *skb, struct nlattr **tb, char *ifname, int status) { const struct net_device_ops *ops = dev->netdev_ops; - int err; + int err = 0; if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) { struct net *net = rtnl_link_get_net(dev_net(dev), tb); @@ -2237,6 +2237,7 @@ static int do_setlink(const struct sk_buff *skb, struct nlattr *attr; int rem; + err = 0; nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) { if (nla_type(attr) != IFLA_VF_INFO || nla_len(attr) < NLA_HDRLEN) { @@ -2253,7 +2254,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_VF_PORTS]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2265,6 +2265,7 @@ static int do_setlink(const struct sk_buff *skb, if (!ops->ndo_set_vf_port) goto errout; + err = 0; nla_for_each_nested(attr, tb[IFLA_VF_PORTS], rem) { if (nla_type(attr) != IFLA_VF_PORT || nla_len(attr) < NLA_HDRLEN) { @@ -2286,7 +2287,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PORT_SELF]) { struct nlattr *port[IFLA_PORT_MAX+1]; @@ -2309,6 +2309,7 @@ static int do_setlink(const struct sk_buff *skb, struct nlattr *af; int rem; + err = 0; nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) { const struct rtnl_af_ops *af_ops; @@ -2326,7 +2327,6 @@ static int do_setlink(const struct sk_buff *skb, status |= DO_SETLINK_NOTIFY; } } - err = 0; if (tb[IFLA_PROTO_DOWN]) { err = dev_change_proto_down(dev, -- 2.7.4
RE: [PATCH v2] scm: fix possible control message header alignment issue
> -Original Message- > From: David Miller [mailto:da...@davemloft.net] > Sent: Saturday, December 31, 2016 4:21 AM > To: cug...@163.com > Cc: netdev@vger.kernel.org; YUAN Linyu > Subject: Re: [PATCH v2] scm: fix possible control message header alignment > issue > If you can come up with a case where this does happen in > practice, I will continue to consider this patch. > Yes, before send patch I also check two archs(arm-v7 and powerpc e6500), they are aligned. No one report issue, I think cmsghdr aligned on all archs. > Otherwise, we should make the assumptions that exist explicit > and get rid of all of the code that does that funny alignment > upon the cmsghdr structure. > Do you accept that I remove all CMSG{_COMPAT}_ALIGN of header ? > Thanks.
[PATCH] scm: remove use CMSG{_COMPAT}_ALIGN(sizeof(struct {compat_}cmsghdr))
From: yuan linyu sizeof(struct cmsghdr) and sizeof(struct compat_cmsghdr) already aligned. remove use CMSG_ALIGN(sizeof(struct cmsghdr)) and CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) keep code consistent. Signed-off-by: yuan linyu --- include/linux/socket.h | 6 +++--- net/compat.c | 14 ++ net/core/scm.c | 2 +- net/ipv4/ip_sockglue.c | 2 +- net/rxrpc/sendmsg.c| 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index b5cc5a6..c064380 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -92,9 +92,9 @@ struct cmsghdr { #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) ) -#define CMSG_DATA(cmsg)((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr -#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len)) -#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) +#define CMSG_DATA(cmsg)((void *)((char *)(cmsg) + sizeof(struct cmsghdr))) +#define CMSG_SPACE(len) (sizeof(struct cmsghdr) + CMSG_ALIGN(len)) +#define CMSG_LEN(len) (sizeof(struct cmsghdr) + (len)) #define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ? \ (struct cmsghdr *)(ctl) : \ diff --git a/net/compat.c b/net/compat.c index 96c544b..4e27dd1 100644 --- a/net/compat.c +++ b/net/compat.c @@ -90,11 +90,11 @@ int get_compat_msghdr(struct msghdr *kmsg, #define CMSG_COMPAT_ALIGN(len) ALIGN((len), sizeof(s32)) #define CMSG_COMPAT_DATA(cmsg) \ - ((void __user *)((char __user *)(cmsg) + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr + ((void __user *)((char __user *)(cmsg) + sizeof(struct compat_cmsghdr))) #define CMSG_COMPAT_SPACE(len) \ - (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + CMSG_COMPAT_ALIGN(len)) + (sizeof(struct compat_cmsghdr) + CMSG_COMPAT_ALIGN(len)) #define CMSG_COMPAT_LEN(len) \ - (CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) + (len)) + (sizeof(struct compat_cmsghdr) + (len)) #define CMSG_COMPAT_FIRSTHDR(msg) \ (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \ @@ -141,8 +141,7 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg)) return -EINVAL; - tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) + - CMSG_ALIGN(sizeof(struct cmsghdr))); + tmp = ((ucmlen - sizeof(*ucmsg)) + sizeof(struct cmsghdr)); tmp = CMSG_ALIGN(tmp); kcmlen += tmp; ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen); @@ -168,8 +167,7 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, goto Efault; if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg)) goto Einval; - tmp = ((ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg))) + - CMSG_ALIGN(sizeof(struct cmsghdr))); + tmp = ((ucmlen - sizeof(*ucmsg)) + sizeof(struct cmsghdr)); if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp)) goto Einval; kcmsg->cmsg_len = tmp; @@ -178,7 +176,7 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk, __get_user(kcmsg->cmsg_type, &ucmsg->cmsg_type) || copy_from_user(CMSG_DATA(kcmsg), CMSG_COMPAT_DATA(ucmsg), - (ucmlen - CMSG_COMPAT_ALIGN(sizeof(*ucmsg) + (ucmlen - sizeof(*ucmsg goto Efault; /* Advance. */ diff --git a/net/core/scm.c b/net/core/scm.c index d882043..b6d8368 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -71,7 +71,7 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp) struct file **fpp; int i, num; - num = (cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)))/sizeof(int); + num = (cmsg->cmsg_len - sizeof(struct cmsghdr))/sizeof(int); if (num <= 0) return 0; diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 53ae0c6..c77e65e 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -272,7 +272,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, continue; switch (cmsg->cmsg_type) { case IP_RETOPTS: - err = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)); + err = cmsg->cmsg_len - sizeof(struct cmsghdr); /*
RE: [PATCH] scm: remove use CMSG{_COMPAT}_ALIGN(sizeof(struct {compat_}cmsghdr))
Thanks > -Original Message- > From: David Miller [mailto:da...@davemloft.net] > Sent: Thursday, January 05, 2017 2:25 AM > To: cug...@163.com > Cc: netdev@vger.kernel.org; YUAN Linyu > Subject: Re: [PATCH] scm: remove use CMSG{_COMPAT}_ALIGN(sizeof(struct > {compat_}cmsghdr)) > > From: yuan linyu > Date: Tue, 3 Jan 2017 20:42:17 +0800 > > > From: yuan linyu > > > > sizeof(struct cmsghdr) and sizeof(struct compat_cmsghdr) already aligned. > > remove use CMSG_ALIGN(sizeof(struct cmsghdr)) and > > CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)) keep code > consistent. > > > > Signed-off-by: yuan linyu > > Applied, and I added the following commit which will make sure our > analysis is accurate. > > > [PATCH] net: Assert at build time the assumptions we make about the CMSG > header. > > It must always be the case that CMSG_ALIGN(sizeof(hdr)) == sizeof(hdr). > > Otherwise there are missing adjustments in the various calculations > that parse and build these things. > > Signed-off-by: David S. Miller > --- > net/compat.c | 3 +++ > net/socket.c | 2 ++ > 2 files changed, 5 insertions(+) > > diff --git a/net/compat.c b/net/compat.c > index 4e27dd1..ba3ac72 100644 > --- a/net/compat.c > +++ b/net/compat.c > @@ -130,6 +130,9 @@ int cmsghdr_from_user_compat_to_kern(struct > msghdr *kmsg, struct sock *sk, > __kernel_size_t kcmlen, tmp; > int err = -EFAULT; > > + BUILD_BUG_ON(sizeof(struct compat_cmsghdr) != > + CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr))); > + > kcmlen = 0; > kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf; > ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg); > diff --git a/net/socket.c b/net/socket.c > index 8487bf1..5f3b5a2 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -1948,6 +1948,8 @@ static int ___sys_sendmsg(struct socket *sock, > struct user_msghdr __user *msg, > ctl_buf = msg_sys->msg_control; > ctl_len = msg_sys->msg_controllen; > } else if (ctl_len) { > + BUILD_BUG_ON(sizeof(struct cmsghdr) != > + CMSG_ALIGN(sizeof(struct cmsghdr))); > if (ctl_len > sizeof(ctl)) { > ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL); > if (ctl_buf == NULL) > -- > 2.4.11
[PATCH] net: change init_inodecache() return void
From: yuan linyu sock_init() call it but not check it's return value, so change it to void return and add an internal BUG_ON() check. Signed-off-by: yuan linyu --- net/socket.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/socket.c b/net/socket.c index c65bb92..3ef02e9 100644 --- a/net/socket.c +++ b/net/socket.c @@ -287,7 +287,7 @@ static void init_once(void *foo) inode_init_once(&ei->vfs_inode); } -static int init_inodecache(void) +static void init_inodecache(void) { sock_inode_cachep = kmem_cache_create("sock_inode_cache", sizeof(struct socket_alloc), @@ -296,9 +296,7 @@ static int init_inodecache(void) SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD | SLAB_ACCOUNT), init_once); - if (sock_inode_cachep == NULL) - return -ENOMEM; - return 0; + BUG_ON(sock_inode_cachep == NULL); } static const struct super_operations sockfs_ops = { -- 2.7.4
[PATCH] net: fix accept4() flags not work
From: yuan linyu user input flags store to newsock which should be used. Signed-off-by: yuan linyu --- net/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/socket.c b/net/socket.c index a8c2307..415f988 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1508,7 +1508,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, if (err) goto out_fd; - err = sock->ops->accept(sock, newsock, sock->file->f_flags); + err = sock->ops->accept(sock, newsock, newsock->file->f_flags); if (err < 0) goto out_fd; -- 2.7.4
[PATCH] net: add regs attribute to phy device for user diagnose
From: yuan linyu if phy device have register(s) configuration problem, user can use this attribute to diagnose. this feature need phy driver maintainer implement. Signed-off-by: yuan linyu --- drivers/net/phy/phy_device.c | 26 ++ include/linux/phy.h | 4 2 files changed, 30 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 92b0838..a400748 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -617,10 +617,36 @@ phy_has_fixups_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(phy_has_fixups); +static ssize_t +phy_regs_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct phy_device *phydev = to_phy_device(dev); + + if (!phydev->drv || !phydev->drv->read_regs) + return 0; + + return phydev->drv->read_regs(phydev, buf, PAGE_SIZE); +} + +static ssize_t +phy_regs_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct phy_device *phydev = to_phy_device(dev); + + if (!phydev->drv || !phydev->drv->write_regs) + return 0; + + return phydev->drv->write_regs(phydev, buf, count); +} +static DEVICE_ATTR_RW(phy_regs); + static struct attribute *phy_dev_attrs[] = { &dev_attr_phy_id.attr, &dev_attr_phy_interface.attr, &dev_attr_phy_has_fixups.attr, + &dev_attr_phy_regs.attr, NULL, }; ATTRIBUTE_GROUPS(phy_dev); diff --git a/include/linux/phy.h b/include/linux/phy.h index f7d95f6..c9c4ab3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -622,6 +622,10 @@ struct phy_driver { int (*set_tunable)(struct phy_device *dev, struct ethtool_tunable *tuna, const void *data); + + /* Diagnose PHY register configuration issue from user space */ + ssize_t (*read_regs)(struct phy_device *dev, char *buf, size_t size); + int (*write_regs)(struct phy_device *dev, const char *buf, size_t size); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) -- 2.7.4
Re: [PATCH] net: add regs attribute to phy device for user diagnose
On 六, 2017-01-14 at 10:35 -0800, Florian Fainelli wrote: > On 01/14/2017 08:24 AM, Andrew Lunn wrote: > > > > On Sat, Jan 14, 2017 at 10:46:31AM +0800, yuan linyu wrote: > > > > > > From: yuan linyu > > > > > > if phy device have register(s) configuration problem, > > > user can use this attribute to diagnose. > > > this feature need phy driver maintainer implement. > > what is wrong with mii-tool -vv ? > Agreed, and without an actual user of this API (ethtool?), nor a PHY > driver implementing it, we cannot quite see how you want to make use of > this. I hope user/developer can read this attribute file "regs" to do a full check of all registers value, and they can write any register inside PHY through this file. I think mii-tool or ethtool can't do it currently. > > Thank you
Re: [PATCH] net: add regs attribute to phy device for user diagnose
On 六, 2017-01-14 at 17:57 -0800, Florian Fainelli wrote: > Le 01/14/17 à 17:51, yuan linyu a écrit : > > > > I think mii-tool or ethtool can't do it currently. > Maybe they cannot right now but they can certainly be patched to support > that. sysfs is not an appropriate interface for what you are proposing > here. We already have a set/get register via ethtool (-d/-D) it would > seem natural to use this. I think most ethernet driver implement ethtool -d to dump mac register. > > Besides that, are not the current ioctl() good enough for that? I think user/developer diagnose through simple attribute file will be easy.
Re: [PATCH] net: add regs attribute to phy device for user diagnose
On 日, 2017-01-15 at 18:21 +0100, Andrew Lunn wrote: > On Sun, Jan 15, 2017 at 09:51:03AM +0800, yuan linyu wrote: > > > > I hope user/developer can read this attribute file "regs" to do > > a full check of all registers value, and they can write any register > > inside PHY through this file. > Since this is intended for debug, it should not be sysfs, but debugfs. agree, > However, in general, Linux does not allow user space to peek and poke > device registers. Can you point me at examples where i can do the same > to my GPU? SATA controller? Ethernet controller, I2C temperature > sensor? Any device? we can read registers of ethernet controller(memory register accessed) through devmem or ethtool > > Andrew >
RE: [PATCH] net: add regs attribute to phy device for user diagnose
> -Original Message- > From: David Miller [mailto:da...@davemloft.net] > Sent: Tuesday, January 17, 2017 5:54 AM > To: f.faine...@gmail.com > Cc: cug...@163.com; and...@lunn.ch; netdev@vger.kernel.org; YUAN Linyu > Subject: Re: [PATCH] net: add regs attribute to phy device for user diagnose > > From: Florian Fainelli > Date: Mon, 16 Jan 2017 12:22:16 -0800 > > > > > So why not add support in ethtool for reading PHY registers if you need > > it? There are handful of PHY "things" in ethtool, such as reading > > counters, configuring downshift etc., adding support for dumping > > registers does not sound out of space. Thanks, I will try this direction. > > Agreed.
RE: [PATCH net-next 2/2] bpf: Remove the capability check for cgroup skb eBPF program
hi > -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Chenbo Feng > Sent: Thursday, June 01, 2017 2:07 AM > To: netdev@vger.kernel.org; David Miller > Cc: Lorenzo Colitti; Chenbo Feng > Subject: [PATCH net-next 2/2] bpf: Remove the capability check for cgroup skb > eBPF program > - if (type != BPF_PROG_TYPE_SOCKET_FILTER > && !capable(CAP_SYS_ADMIN)) > + if (type != BPF_PROG_TYPE_SOCKET_FILTER > + && type != BPF_PROG_TYPE_CGROUP_SKB > + && !capable(CAP_SYS_ADMIN)) checkpatch.pl prefer put && at end of line > return -EPERM; > > /* plain bpf_prog allocation */ > -- > 2.7.4
[PATCH net-next 00/11] skb_put_zero() used to optimize code
From: yuan linyu yuan linyu (11): ipv6: skb_put_zero() used to optimize code ipv4: skb_put_zero() used to optimize code ncsi: skb_put_zero() used to optimize code dsa: skb_put_zero() used to optimize code key: skb_put_zero() used to optimize code openvswitch: skb_put_zero() used to optimize code batman-adv: skb_put_zero() used to optimize code bridge: skb_put_zero() used to optimize code sctp: skb_put_zero() used to optimize code atm: skb_put_zero() used to optimize code qrtr: skb_put_zero() used to optimize code net/atm/signaling.c | 3 +-- net/batman-adv/bat_v_elp.c | 3 +-- net/bridge/netfilter/nft_reject_bridge.c | 6 ++ net/dsa/tag_trailer.c| 3 +-- net/ipv4/ipconfig.c | 3 +-- net/ipv4/netfilter/nf_reject_ipv4.c | 3 +-- net/ipv6/mcast.c | 3 +-- net/ipv6/ndisc.c | 13 ++-- net/key/af_key.c | 12 --- net/ncsi/ncsi-cmd.c | 36 +++- net/openvswitch/datapath.c | 2 +- net/qrtr/qrtr.c | 9 +++- net/sctp/output.c| 2 +- 13 files changed, 31 insertions(+), 67 deletions(-) -- 2.7.4
[PATCH net-next 02/11] ipv4: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv4/ipconfig.c | 3 +-- net/ipv4/netfilter/nf_reject_ipv4.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index c3b12b1..a6292a6 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -813,8 +813,7 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d if (!skb) return; skb_reserve(skb, hlen); - b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt)); - memset(b, 0, sizeof(struct bootp_pkt)); + b = (struct bootp_pkt *) skb_put_zero(skb, sizeof(struct bootp_pkt)); /* Construct IP header */ skb_reset_network_header(skb); diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c index 6f8d9e5..2569ba9 100644 --- a/net/ipv4/netfilter/nf_reject_ipv4.c +++ b/net/ipv4/netfilter/nf_reject_ipv4.c @@ -76,8 +76,7 @@ void nf_reject_ip_tcphdr_put(struct sk_buff *nskb, const struct sk_buff *oldskb, struct tcphdr *tcph; skb_reset_transport_header(nskb); - tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr)); - memset(tcph, 0, sizeof(*tcph)); + tcph = (struct tcphdr *)skb_put_zero(nskb, sizeof(struct tcphdr)); tcph->source= oth->dest; tcph->dest = oth->source; tcph->doff = sizeof(struct tcphdr) / 4; -- 2.7.4
[PATCH net-next 01/11] ipv6: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/mcast.c | 3 +-- net/ipv6/ndisc.c | 13 ++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 07403fa..b186c67 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c @@ -2008,8 +2008,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra)); - hdr = (struct mld_msg *) skb_put(skb, sizeof(struct mld_msg)); - memset(hdr, 0, sizeof(struct mld_msg)); + hdr = (struct mld_msg *) skb_put_zero(skb, sizeof(struct mld_msg)); hdr->mld_type = type; hdr->mld_mca = *addr; diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..e6586ed 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -144,21 +144,12 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, int data_len, int pad) { int space = __ndisc_opt_addr_space(data_len, pad); - u8 *opt = skb_put(skb, space); + u8 *opt = skb_put_zero(skb, space); opt[0] = type; opt[1] = space>>3; - memset(opt + 2, 0, pad); - opt += pad; - space -= pad; - - memcpy(opt+2, data, data_len); - data_len += 2; - opt += data_len; - space -= data_len; - if (space > 0) - memset(opt, 0, space); + memcpy(opt+2+pad, data, data_len); } EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option); -- 2.7.4
[PATCH net-next 03/11] ncsi: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/ncsi/ncsi-cmd.c | 36 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c index db7083b..010d808 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -66,8 +66,7 @@ static int ncsi_cmd_handler_default(struct sk_buff *skb, { struct ncsi_cmd_pkt *cmd; - cmd = (struct ncsi_cmd_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_pkt *)skb_put_zero(skb, sizeof(*cmd)); ncsi_cmd_build_header(&cmd->cmd.common, nca); return 0; @@ -78,8 +77,7 @@ static int ncsi_cmd_handler_sp(struct sk_buff *skb, { struct ncsi_cmd_sp_pkt *cmd; - cmd = (struct ncsi_cmd_sp_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_sp_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->hw_arbitration = nca->bytes[0]; ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -91,8 +89,7 @@ static int ncsi_cmd_handler_dc(struct sk_buff *skb, { struct ncsi_cmd_dc_pkt *cmd; - cmd = (struct ncsi_cmd_dc_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_dc_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->ald = nca->bytes[0]; ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -104,8 +101,7 @@ static int ncsi_cmd_handler_rc(struct sk_buff *skb, { struct ncsi_cmd_rc_pkt *cmd; - cmd = (struct ncsi_cmd_rc_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_rc_pkt *)skb_put_zero(skb, sizeof(*cmd)); ncsi_cmd_build_header(&cmd->cmd.common, nca); return 0; @@ -116,8 +112,7 @@ static int ncsi_cmd_handler_ae(struct sk_buff *skb, { struct ncsi_cmd_ae_pkt *cmd; - cmd = (struct ncsi_cmd_ae_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_ae_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->mc_id = nca->bytes[0]; cmd->mode = htonl(nca->dwords[1]); ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -130,8 +125,7 @@ static int ncsi_cmd_handler_sl(struct sk_buff *skb, { struct ncsi_cmd_sl_pkt *cmd; - cmd = (struct ncsi_cmd_sl_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_sl_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->mode = htonl(nca->dwords[0]); cmd->oem_mode = htonl(nca->dwords[1]); ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -144,8 +138,7 @@ static int ncsi_cmd_handler_svf(struct sk_buff *skb, { struct ncsi_cmd_svf_pkt *cmd; - cmd = (struct ncsi_cmd_svf_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_svf_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->vlan = htons(nca->words[0]); cmd->index = nca->bytes[2]; cmd->enable = nca->bytes[3]; @@ -159,8 +152,7 @@ static int ncsi_cmd_handler_ev(struct sk_buff *skb, { struct ncsi_cmd_ev_pkt *cmd; - cmd = (struct ncsi_cmd_ev_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_ev_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->mode = nca->bytes[0]; ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -173,8 +165,7 @@ static int ncsi_cmd_handler_sma(struct sk_buff *skb, struct ncsi_cmd_sma_pkt *cmd; int i; - cmd = (struct ncsi_cmd_sma_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_sma_pkt *)skb_put_zero(skb, sizeof(*cmd)); for (i = 0; i < 6; i++) cmd->mac[i] = nca->bytes[i]; cmd->index = nca->bytes[6]; @@ -189,8 +180,7 @@ static int ncsi_cmd_handler_ebf(struct sk_buff *skb, { struct ncsi_cmd_ebf_pkt *cmd; - cmd = (struct ncsi_cmd_ebf_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_ebf_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->mode = htonl(nca->dwords[0]); ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -202,8 +192,7 @@ static int ncsi_cmd_handler_egmf(struct sk_buff *skb, { struct ncsi_cmd_egmf_pkt *cmd; - cmd = (struct ncsi_cmd_egmf_pkt *)skb_put(skb, sizeof(*cmd)); - memset(cmd, 0, sizeof(*cmd)); + cmd = (struct ncsi_cmd_egmf_pkt *)skb_put_zero(skb, sizeof(*cmd)); cmd->mode = htonl(nca->dwords[0]); ncsi_cmd_build_header(&cmd->cmd.common, nca); @@ -215,8 +204,7 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb, { struct ncsi_cmd_snfc_pkt *cmd; - cmd = (struct ncsi_cmd_snfc_pkt *)skb_put(
[PATCH net-next 04/11] dsa: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/dsa/tag_trailer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c index 172f131..b09e562 100644 --- a/net/dsa/tag_trailer.c +++ b/net/dsa/tag_trailer.c @@ -43,8 +43,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) kfree_skb(skb); if (padlen) { - u8 *pad = skb_put(nskb, padlen); - memset(pad, 0, padlen); + skb_put_zero(nskb, padlen); } trailer = skb_put(nskb, 4); -- 2.7.4
[PATCH net-next 06/11] openvswitch: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/openvswitch/datapath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 9ddc9f8..d772e9a 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -413,7 +413,7 @@ static void pad_packet(struct datapath *dp, struct sk_buff *skb) size_t plen = NLA_ALIGN(skb->len) - skb->len; if (plen > 0) - memset(skb_put(skb, plen), 0, plen); + skb_put_zero(skb, plen); } } -- 2.7.4
[PATCH net-next 05/11] key: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/key/af_key.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/net/key/af_key.c b/net/key/af_key.c index 512dc43..c6c7cbf 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -2934,8 +2934,7 @@ static void dump_ah_combs(struct sk_buff *skb, const struct xfrm_tmpl *t) if (aalg_tmpl_set(t, aalg) && aalg->available) { struct sadb_comb *c; - c = (struct sadb_comb*)skb_put(skb, sizeof(struct sadb_comb)); - memset(c, 0, sizeof(*c)); + c = (struct sadb_comb*)skb_put_zero(skb, sizeof(struct sadb_comb)); p->sadb_prop_len += sizeof(struct sadb_comb)/8; c->sadb_comb_auth = aalg->desc.sadb_alg_id; c->sadb_comb_auth_minbits = aalg->desc.sadb_alg_minbits; @@ -2979,8 +2978,7 @@ static void dump_esp_combs(struct sk_buff *skb, const struct xfrm_tmpl *t) continue; if (!(aalg_tmpl_set(t, aalg) && aalg->available)) continue; - c = (struct sadb_comb*)skb_put(skb, sizeof(struct sadb_comb)); - memset(c, 0, sizeof(*c)); + c = (struct sadb_comb*)skb_put_zero(skb, sizeof(struct sadb_comb)); p->sadb_prop_len += sizeof(struct sadb_comb)/8; c->sadb_comb_auth = aalg->desc.sadb_alg_id; c->sadb_comb_auth_minbits = aalg->desc.sadb_alg_minbits; @@ -3461,8 +3459,7 @@ static int set_sadb_kmaddress(struct sk_buff *skb, const struct xfrm_kmaddress * size_req = (sizeof(struct sadb_x_kmaddress) + pfkey_sockaddr_pair_size(family)); - kma = (struct sadb_x_kmaddress *)skb_put(skb, size_req); - memset(kma, 0, size_req); + kma = (struct sadb_x_kmaddress *)skb_put_zero(skb, size_req); kma->sadb_x_kmaddress_len = size_req / 8; kma->sadb_x_kmaddress_exttype = SADB_X_EXT_KMADDRESS; kma->sadb_x_kmaddress_reserved = k->reserved; @@ -3488,8 +3485,7 @@ static int set_ipsecrequest(struct sk_buff *skb, size_req = sizeof(struct sadb_x_ipsecrequest) + pfkey_sockaddr_pair_size(family); - rq = (struct sadb_x_ipsecrequest *)skb_put(skb, size_req); - memset(rq, 0, size_req); + rq = (struct sadb_x_ipsecrequest *)skb_put_zero(skb, size_req); rq->sadb_x_ipsecrequest_len = size_req; rq->sadb_x_ipsecrequest_proto = proto; rq->sadb_x_ipsecrequest_mode = mode; -- 2.7.4
[PATCH net-next 07/11] batman-adv: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/batman-adv/bat_v_elp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c index b58007b..bd1064d 100644 --- a/net/batman-adv/bat_v_elp.c +++ b/net/batman-adv/bat_v_elp.c @@ -346,9 +346,8 @@ int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface) goto out; skb_reserve(hard_iface->bat_v.elp_skb, ETH_HLEN + NET_IP_ALIGN); - elp_buff = skb_put(hard_iface->bat_v.elp_skb, BATADV_ELP_HLEN); + elp_buff = skb_put_zero(hard_iface->bat_v.elp_skb, BATADV_ELP_HLEN); elp_packet = (struct batadv_elp_packet *)elp_buff; - memset(elp_packet, 0, BATADV_ELP_HLEN); elp_packet->packet_type = BATADV_ELP; elp_packet->version = BATADV_COMPAT_VERSION; -- 2.7.4
[PATCH net-next 08/11] bridge: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/bridge/netfilter/nft_reject_bridge.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/bridge/netfilter/nft_reject_bridge.c b/net/bridge/netfilter/nft_reject_bridge.c index c16dd3a..22a52d5 100644 --- a/net/bridge/netfilter/nft_reject_bridge.c +++ b/net/bridge/netfilter/nft_reject_bridge.c @@ -147,8 +147,7 @@ static void nft_reject_br_send_v4_unreach(struct net *net, net->ipv4.sysctl_ip_default_ttl); skb_reset_transport_header(nskb); - icmph = (struct icmphdr *)skb_put(nskb, sizeof(struct icmphdr)); - memset(icmph, 0, sizeof(*icmph)); + icmph = (struct icmphdr *)skb_put_zero(nskb, sizeof(struct icmphdr)); icmph->type = ICMP_DEST_UNREACH; icmph->code = code; @@ -275,8 +274,7 @@ static void nft_reject_br_send_v6_unreach(struct net *net, net->ipv6.devconf_all->hop_limit); skb_reset_transport_header(nskb); - icmp6h = (struct icmp6hdr *)skb_put(nskb, sizeof(struct icmp6hdr)); - memset(icmp6h, 0, sizeof(*icmp6h)); + icmp6h = (struct icmp6hdr *)skb_put_zero(nskb, sizeof(struct icmp6hdr)); icmp6h->icmp6_type = ICMPV6_DEST_UNREACH; icmp6h->icmp6_code = code; -- 2.7.4
[PATCH net-next 09/11] sctp: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/sctp/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sctp/output.c b/net/sctp/output.c index e2edf2e..c339c68 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -463,7 +463,7 @@ static int sctp_packet_pack(struct sctp_packet *packet, padding = SCTP_PAD4(chunk->skb->len) - chunk->skb->len; if (padding) - memset(skb_put(chunk->skb, padding), 0, padding); + skb_put_zero(chunk->skb, padding); if (chunk == packet->auth) auth = (struct sctp_auth_chunk *) -- 2.7.4
[PATCH net-next 10/11] atm: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/atm/signaling.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/atm/signaling.c b/net/atm/signaling.c index adb6e3d..380d496 100644 --- a/net/atm/signaling.c +++ b/net/atm/signaling.c @@ -150,8 +150,7 @@ void sigd_enq2(struct atm_vcc *vcc, enum atmsvc_msg_type type, pr_debug("%d (0x%p)\n", (int)type, vcc); while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL))) schedule(); - msg = (struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg)); - memset(msg, 0, sizeof(*msg)); + msg = (struct atmsvc_msg *)skb_put_zero(skb, sizeof(struct atmsvc_msg)); msg->type = type; *(struct atm_vcc **) &msg->vcc = vcc; *(struct atm_vcc **) &msg->listen_vcc = listen_vcc; -- 2.7.4
[PATCH net-next 11/11] qrtr: skb_put_zero() used to optimize code
From: yuan linyu Signed-off-by: yuan linyu --- net/qrtr/qrtr.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index c7a5d86..e96353d 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -285,8 +285,7 @@ static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node, if (!skb) return NULL; - buf = (__le32 *)skb_put(skb, pkt_len); - memset(buf, 0, pkt_len); + buf = (__le32 *)skb_put_zero(skb, pkt_len); buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX); buf[1] = cpu_to_le32(src_node); buf[2] = cpu_to_le32(port); @@ -306,8 +305,7 @@ static struct sk_buff *qrtr_alloc_local_bye(u32 src_node) if (!skb) return NULL; - buf = (__le32 *)skb_put(skb, pkt_len); - memset(buf, 0, pkt_len); + buf = (__le32 *)skb_put_zero(skb, pkt_len); buf[0] = cpu_to_le32(QRTR_TYPE_BYE); return skb; @@ -324,8 +322,7 @@ static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq) if (!skb) return NULL; - buf = (__le32 *)skb_put(skb, pkt_len); - memset(buf, 0, pkt_len); + buf = (__le32 *)skb_put_zero(skb, pkt_len); buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); buf[1] = cpu_to_le32(sq->sq_node); buf[2] = cpu_to_le32(sq->sq_port); -- 2.7.4
Re: [PATCH net-next 00/11] skb_put_zero() used to optimize code
On 三, 2017-06-14 at 16:42 +0200, Johannes Berg wrote: > On Wed, 2017-06-14 at 22:30 +0800, yuan linyu wrote: > > > > From: yuan linyu > > > > > > yuan linyu (11): > > ipv6: skb_put_zero() used to optimize code > > ipv4: skb_put_zero() used to optimize code > > ncsi: skb_put_zero() used to optimize code > > dsa: skb_put_zero() used to optimize code > > key: skb_put_zero() used to optimize code > > openvswitch: skb_put_zero() used to optimize code > > batman-adv: skb_put_zero() used to optimize code > > bridge: skb_put_zero() used to optimize code > > sctp: skb_put_zero() used to optimize code > > atm: skb_put_zero() used to optimize code > > qrtr: skb_put_zero() used to optimize code > Hmm. I guess my spatch missed these because of the casts present in > them. > > Surely you didn't do them by hand, so maybe you should provide a single > big patch with the spatch? sorry, I do them by hand. last time when i try to change ndisc.c, david adhern suggest to use skb_put_zero(). > > johannes
RE: [PATCH net-next 00/11] skb_put_zero() used to optimize code
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Johannes Berg > Sent: Thursday, June 15, 2017 12:32 AM > To: cug...@163.com; netdev@vger.kernel.org > Cc: David S . Miller; YUAN Linyu > Subject: Re: [PATCH net-next 00/11] skb_put_zero() used to optimize code > > On Wed, 2017-06-14 at 18:29 +0200, Johannes Berg wrote: > > On Wed, 2017-06-14 at 23:00 +0800, yuan linyu wrote: > > > > > sorry, I do them by hand. > > > > oh, ok. > > > > This seems to work: > > > > @@ > > identifier p; > > expression len; > > expression skb; > > type t; > > @@ > > -p = (t)skb_put(skb, len); > > -memset(p, 0, len); > > +p = (t)skb_put_zero(skb, len); > > Nope, still didn't find everything - not the batman and atm cases for > example. But still a few more, I think that you didn't find, e.g. in > mac80211. Yes, I thought you already done in mac80211 > > Anyway - I think none of this is really critical. > > johannes
RE: [RFC] networking: convert many more places to skb_put_zero()
Hi, Indeed, it find more. Compare with my patch, still lost pattern like below, 1. sctp and openvswitch --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -463,7 +463,7 @@ static int sctp_packet_pack(struct sctp_packet *packet, padding = SCTP_PAD4(chunk->skb->len) - chunk->skb->len; if (padding) - memset(skb_put(chunk->skb, padding), 0, padding); + skb_put_zero(chunk->skb, padding); --- a/net/dsa/tag_trailer.c +++ b/net/dsa/tag_trailer.c @@ -43,8 +43,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) kfree_skb(skb); if (padlen) { - u8 *pad = skb_put(nskb, padlen); - memset(pad, 0, padlen); + skb_put_zero(nskb, padlen); I will send a separate patch for ipv6/ndisc.c once spatch done. > -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Johannes Berg > Sent: Thursday, June 15, 2017 4:18 AM > To: netdev@vger.kernel.org > Cc: Johannes Berg > Subject: [RFC] networking: convert many more places to skb_put_zero() > > From: Johannes Berg > > There were many places that my previous spatch didn't find, > as pointed out by yuan linyu in various patches. > > The following spatch found many more and also removes the > now unnecessary casts: > > @@ > identifier p, p2; > expression len; > expression skb; > type t, t2; > @@ > ( > -p = skb_put(skb, len); > +p = skb_put_zero(skb, len); > | > -p = (t)skb_put(skb, len); > +p = skb_put_zero(skb, len); > ) > ( > p2 = (t2)p; > -memset(p2, 0, len); > | > -memset(p, 0, len); > ) > > @@ > type t, t2; > identifier p, p2; > expression skb; > @@ > t *p; > ... > ( > -p = skb_put(skb, sizeof(t)); > +p = skb_put_zero(skb, sizeof(t)); > | > -p = (t *)skb_put(skb, sizeof(t)); > +p = skb_put_zero(skb, sizeof(t)); > ) > ( > p2 = (t2)p; > -memset(p2, 0, sizeof(*p)); > | > -memset(p, 0, sizeof(*p)); > ) >
RE: [RFC] networking: convert many more places to skb_put_zero()
> -Original Message- > From: Johannes Berg [mailto:johan...@sipsolutions.net] > Sent: Thursday, June 15, 2017 2:58 PM > To: YUAN Linyu; netdev@vger.kernel.org > Subject: Re: [RFC] networking: convert many more places to skb_put_zero() > > On Thu, 2017-06-15 at 00:23 +, YUAN Linyu wrote: > > Hi, > > Indeed, it find more. > > Compare with my patch, still lost pattern like below, > > 1. sctp and openvswitch > > --- a/net/sctp/output.c > > +++ b/net/sctp/output.c > > @@ -463,7 +463,7 @@ static int sctp_packet_pack(struct sctp_packet > > *packet, > > > > padding = SCTP_PAD4(chunk->skb->len) - > > chunk->skb->len; > > if (padding) > > - memset(skb_put(chunk->skb, padding), > > 0, padding); > > + skb_put_zero(chunk->skb, padding); > > Yep, good catch, this finds 18 instances thereof: > > @@ > expression skb, len; > @@ > -memset(skb_put(skb, len), 0, len); > +skb_put_zero(skb, len); > > > > --- a/net/dsa/tag_trailer.c > > +++ b/net/dsa/tag_trailer.c > > @@ -43,8 +43,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff > > *skb, struct net_device *dev) > > kfree_skb(skb); > > > > if (padlen) { > > - u8 *pad = skb_put(nskb, padlen); > > - memset(pad, 0, padlen); > > + skb_put_zero(nskb, padlen); > > I'd have thought it finds this, but indeed it doesn't; there's only one > instances this changes though: > > @@ > type t; > expression skb, len; > identifier p; > @@ > t *p > - = skb_put(skb, len); > + = skb_put_zero(skb, len); > -memset(p, 0, len); > > and it can't figure out that it should remove the variable, without > much more work that's not really worth it for one instance :) Yes, I agree, it conflict with previous spatch which will keep "pad" variable, right? I can do it by hand if spatch not work > > johannes
RE: [RFC] networking: convert many more places to skb_put_zero()
> -Original Message- > From: Johannes Berg [mailto:johan...@sipsolutions.net] > Sent: Thursday, June 15, 2017 3:12 PM > To: YUAN Linyu; netdev@vger.kernel.org > Subject: Re: [RFC] networking: convert many more places to skb_put_zero() > > On Thu, 2017-06-15 at 07:05 +, YUAN Linyu wrote: > > > @@ > > > type t; > > > expression skb, len; > > > identifier p; > > > @@ > > > t *p > > > - = skb_put(skb, len); > > > + = skb_put_zero(skb, len); > > > -memset(p, 0, len); > > > > > > and it can't figure out that it should remove the variable, without > > > much more work that's not really worth it for one instance :) > > > > Yes, I agree, > > it conflict with previous spatch which will keep "pad" variable, > > right? > > > > I can do it by hand if spatch not work > > I could teach spatch, but it's usually faster (for me) to post-process > the spatch changes to remove the extra variable - in this case though, > it's just not worth it at all since there's just a single change and > you already have a separate patch :) In my opinion if spatch can do it even it found one place, keep it. Only leave difficult places like ndisc.c to me. > > Btw, just made a patch to add and use "skb_put_data()", just doing a > memcpy() into the skb_put() area also has lots of users. Yes, I also notice some places. > > johannes
RE: [RFC] networking: convert many more places to skb_put_zero()
Ok, understand > -Original Message- > From: Johannes Berg [mailto:johan...@sipsolutions.net] > Sent: Thursday, June 15, 2017 3:45 PM > To: YUAN Linyu; netdev@vger.kernel.org > Subject: Re: [RFC] networking: convert many more places to skb_put_zero() > > On Thu, 2017-06-15 at 07:20 +, YUAN Linyu wrote: > > > > > In my opinion if spatch can do it even it found one place, keep it. > > Only leave difficult places like ndisc.c to me. > > It's not so simple - I'd have to tailor the spatch to it pretty much I > guess, spending far more time on the spatch than the single place > warrants. > > > > Btw, just made a patch to add and use "skb_put_data()", just doing > > > a > > > memcpy() into the skb_put() area also has lots of users. > > > > Yes, I also notice some places. > > I sent a patch. > > johannes
RE: [RFC v2] networking: convert many more places to skb_put_zero()
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Johannes Berg > Sent: Thursday, June 15, 2017 5:28 PM > To: netdev@vger.kernel.org > Cc: Johannes Berg > Subject: [RFC v2] networking: convert many more places to skb_put_zero() > > From: Johannes Berg > diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c > index ea2601501654..aaac2660aaf7 100644 > --- a/net/sctp/sm_make_chunk.c > +++ b/net/sctp/sm_make_chunk.c > @@ -1478,10 +1478,9 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, > int len, const void *data) > int chunklen = ntohs(chunk->chunk_hdr->length); > int padlen = SCTP_PAD4(chunklen) - chunklen; > > - padding = skb_put(chunk->skb, padlen); > + padding = skb_put_zero(chunk->skb, padlen); "padding" will become unused. I know this place when I check. > target = skb_put(chunk->skb, len); > > - memset(padding, 0, padlen); > memcpy(target, data, len); > > /* Adjust the chunk length field. */ > -- > 2.11.0
[PATCH net-next 0/3] more skb_put_[data:zero] related work
From: yuan linyu yuan linyu (3): net: introduce __skb_put_[zero, data, u8] net: replace more place to skb_put_[data:zero] net: manual clean code which call skb_put_[data:zero] drivers/crypto/chelsio/chcr_algo.c | 15 +-- drivers/infiniband/hw/cxgb4/cm.c | 6 ++ drivers/infiniband/hw/cxgb4/cq.c | 6 ++ drivers/infiniband/hw/cxgb4/mem.c | 6 ++ drivers/infiniband/hw/cxgb4/qp.c | 3 +-- drivers/isdn/gigaset/asyncdata.c | 4 ++-- drivers/isdn/gigaset/isocdata.c| 2 +- drivers/isdn/hysdn/hycapi.c| 8 drivers/isdn/i4l/isdn_bsdcomp.c| 2 +- drivers/isdn/i4l/isdn_ppp.c| 2 +- drivers/net/bonding/bond_alb.c | 3 +-- drivers/net/caif/caif_hsi.c| 6 ++ drivers/net/caif/caif_serial.c | 3 +-- drivers/net/caif/caif_spi.c| 3 +-- drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c| 12 drivers/net/ethernet/chelsio/cxgb3/sge.c | 2 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 3 +-- drivers/net/ethernet/nxp/lpc_eth.c | 7 +++ drivers/net/ethernet/packetengines/hamachi.c | 4 ++-- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/usb/asix_common.c | 5 ++--- drivers/net/usb/cdc_ncm.c | 4 ++-- drivers/net/usb/hso.c | 13 ++--- drivers/net/usb/int51x1.c | 2 +- drivers/net/wireless/ath/ath9k/wmi.c | 3 +-- drivers/net/wireless/marvell/libertas/if_sdio.c| 3 +-- .../net/wireless/quantenna/qtnfmac/qlink_util.h| 4 +--- drivers/net/wireless/realtek/rtlwifi/pci.c | 3 +-- .../wireless/realtek/rtlwifi/rtl8192c/fw_common.c | 3 +-- .../net/wireless/realtek/rtlwifi/rtl8192de/fw.c| 3 +-- .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.c| 3 +-- .../net/wireless/realtek/rtlwifi/rtl8723ae/fw.c| 3 +-- .../net/wireless/realtek/rtlwifi/rtl8723be/fw.c| 3 +-- .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.c| 6 ++ drivers/net/wireless/rsi/rsi_91x_mgmt.c| 10 +++--- drivers/net/wireless/ti/wlcore/rx.c| 3 +-- drivers/nfc/pn533/pn533.c | 4 ++-- drivers/staging/octeon/ethernet-tx.c | 3 +-- drivers/staging/rtl8188eu/core/rtw_recv.c | 4 +--- drivers/staging/rtl8192e/rtllib_rx.c | 5 ++--- drivers/staging/rtl8192e/rtllib_softmac.c | 11 ++- drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 +--- .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 11 +-- drivers/staging/rtl8192u/r819xU_cmdpkt.c | 3 +-- drivers/staging/rtl8712/rtl8712_recv.c | 4 ++-- drivers/staging/rtl8723bs/os_dep/recv_linux.c | 4 +--- drivers/staging/wlan-ng/hfa384x_usb.c | 2 +- drivers/target/iscsi/cxgbit/cxgbit_cm.c| 12 drivers/usb/gadget/function/f_ncm.c| 11 +-- include/linux/skbuff.h | 22 ++ lib/nlattr.c | 6 +- lib/test_bpf.c | 2 +- net/802/garp.c | 2 +- net/bluetooth/bnep/core.c | 15 ++- net/bluetooth/bnep/netdev.c| 12 ++-- net/bridge/br_stp_bpdu.c | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 6 ++ net/dsa/tag_trailer.c | 3 +-- net/hsr/hsr_device.c | 6 +++--- net/irda/irlap_frame.c | 5 ++--- net/mac80211/mlme.c| 12 net/mac80211/tdls.c| 19 +-- net/sctp/sm_make_chunk.c | 3 +-- net/vmw_vsock/virtio_transport_common.c| 5 ++--- net/x25/x25_subr.c | 16 65 files changed, 166 insertions(+), 218 deletions(-) -- 2.7.4
[PATCH net-next 1/3] net: introduce __skb_put_[zero, data, u8]
From: yuan linyu follow Johannes Berg, semantic patch file as below, @@ identifier p, p2; expression len; expression skb; type t, t2; @@ ( -p = __skb_put(skb, len); +p = __skb_put_zero(skb, len); | -p = (t)__skb_put(skb, len); +p = __skb_put_zero(skb, len); ) ... when != p ( p2 = (t2)p; -memset(p2, 0, len); | -memset(p, 0, len); ) @@ identifier p; expression len; expression skb; type t; @@ ( -t p = __skb_put(skb, len); +t p = __skb_put_zero(skb, len); ) ... when != p ( -memset(p, 0, len); ) @@ type t, t2; identifier p, p2; expression skb; @@ t *p; ... ( -p = __skb_put(skb, sizeof(t)); +p = __skb_put_zero(skb, sizeof(t)); | -p = (t *)__skb_put(skb, sizeof(t)); +p = __skb_put_zero(skb, sizeof(t)); ) ... when != p ( p2 = (t2)p; -memset(p2, 0, sizeof(*p)); | -memset(p, 0, sizeof(*p)); ) @@ expression skb, len; @@ -memset(__skb_put(skb, len), 0, len); +__skb_put_zero(skb, len); @@ expression skb, len, data; @@ -memcpy(__skb_put(skb, len), data, len); +__skb_put_data(skb, data, len); @@ expression SKB, C, S; typedef u8; identifier fn = {__skb_put}; fresh identifier fn2 = fn ## "_u8"; @@ - *(u8 *)fn(SKB, S) = C; + fn2(SKB, C); Signed-off-by: yuan linyu --- drivers/crypto/chelsio/chcr_algo.c| 15 +-- drivers/infiniband/hw/cxgb4/cm.c | 6 ++ drivers/infiniband/hw/cxgb4/cq.c | 6 ++ drivers/infiniband/hw/cxgb4/mem.c | 6 ++ drivers/infiniband/hw/cxgb4/qp.c | 3 +-- drivers/isdn/gigaset/asyncdata.c | 4 ++-- drivers/isdn/gigaset/isocdata.c | 2 +- drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 12 drivers/net/ethernet/chelsio/cxgb3/sge.c | 2 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 3 +-- drivers/net/usb/int51x1.c | 2 +- drivers/staging/octeon/ethernet-tx.c | 3 +-- drivers/target/iscsi/cxgbit/cxgbit_cm.c | 12 include/linux/skbuff.h| 22 ++ lib/test_bpf.c| 2 +- net/802/garp.c| 2 +- net/bluetooth/bnep/core.c | 15 ++- net/bluetooth/bnep/netdev.c | 12 ++-- net/bridge/br_stp_bpdu.c | 2 +- 19 files changed, 64 insertions(+), 67 deletions(-) diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c index 92185ab..b75b8be 100644 --- a/drivers/crypto/chelsio/chcr_algo.c +++ b/drivers/crypto/chelsio/chcr_algo.c @@ -604,8 +604,7 @@ static struct sk_buff if (!skb) return ERR_PTR(-ENOMEM); skb_reserve(skb, sizeof(struct sge_opaque_hdr)); - chcr_req = __skb_put(skb, transhdr_len); - memset(chcr_req, 0, transhdr_len); + chcr_req = __skb_put_zero(skb, transhdr_len); chcr_req->sec_cpl.op_ivinsrtofst = FILL_SEC_CPL_OP_IVINSR(ctx->dev->rx_channel_id, 2, 1); @@ -881,8 +880,7 @@ static struct sk_buff *create_hash_wr(struct ahash_request *req, return skb; skb_reserve(skb, sizeof(struct sge_opaque_hdr)); - chcr_req = __skb_put(skb, transhdr_len); - memset(chcr_req, 0, transhdr_len); + chcr_req = __skb_put_zero(skb, transhdr_len); chcr_req->sec_cpl.op_ivinsrtofst = FILL_SEC_CPL_OP_IVINSR(ctx->dev->rx_channel_id, 2, 0); @@ -1447,8 +1445,7 @@ static struct sk_buff *create_authenc_wr(struct aead_request *req, skb_reserve(skb, sizeof(struct sge_opaque_hdr)); /* Write WR */ - chcr_req = __skb_put(skb, transhdr_len); - memset(chcr_req, 0, transhdr_len); + chcr_req = __skb_put_zero(skb, transhdr_len); stop_offset = (op_type == CHCR_ENCRYPT_OP) ? 0 : authsize; @@ -1779,8 +1776,7 @@ static struct sk_buff *create_aead_ccm_wr(struct aead_request *req, skb_reserve(skb, sizeof(struct sge_opaque_hdr)); - chcr_req = __skb_put(skb, transhdr_len); - memset(chcr_req, 0, transhdr_len); + chcr_req = __skb_put_zero(skb, transhdr_len); fill_sec_cpl_for_aead(&chcr_req->sec_cpl, dst_size, req, op_type, ctx); @@ -1892,8 +1888,7 @@ static struct sk_buff *create_gcm_wr(struct aead_request *req, /* NIC driver is going to write the sge hdr. */ skb_reserve(skb, sizeof(struct sge_opaque_hdr)); - chcr_req = __skb_put(skb, transhdr_len); - memset(chcr_req, 0, transhdr_len); + chcr_req = __skb_put_zero(skb, transhdr_len); if (get_aead_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106) req->assoclen -= 8; diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c index 76fb394..e49b34c 100644 --- a/drivers/infiniband/hw/cxgb4/cm.c +++ b/drivers/infiniband/hw/cxgb4/cm.c @@ -1900,8 +1900,7 @@ static int send_fw_act_
[PATCH net-next 2/3] net: replace more place to skb_put_[data:zero]
From: yuan linyu spatch file, @@ expression skb, len, data; type t; @@ -memcpy((t *)skb_put(skb, len), data, len); +skb_put_data(skb, data, len); @@ identifier p; expression skb, len, data; type t; @@ -p = (t *)memset(skb_put(skb, len), data, len); +p = skb_put_zero(skb, len); @@ expression skb, len, data; type t; @@ -memcpy((t *)__skb_put(skb, len), data, len); +__skb_put_data(skb, data, len); @@ identifier p; expression skb, len, data; type t; @@ -p = (t *)memset(__skb_put(skb, len), data, len); +p = __skb_put_zero(skb, len); Signed-off-by: yuan linyu --- drivers/net/usb/cdc_ncm.c | 4 ++-- drivers/net/wireless/realtek/rtlwifi/rtl8192c/fw_common.c | 3 +-- drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c | 3 +-- drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c | 3 +-- drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.c | 3 +-- drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c | 3 +-- drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c | 6 ++ 7 files changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index bcb9747..2067743 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -1069,7 +1069,7 @@ static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp(struct cdc_ncm_ctx *ctx, struct sk_ /* push a new empty NDP */ if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)) - ndp16 = (struct usb_cdc_ncm_ndp16 *)memset(skb_put(skb, ctx->max_ndp_size), 0, ctx->max_ndp_size); + ndp16 = skb_put_zero(skb, ctx->max_ndp_size); else ndp16 = ctx->delayed_ndp16; @@ -1120,7 +1120,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign) goto exit_no_skb; } /* fill out the initial 16-bit NTB header */ - nth16 = (struct usb_cdc_ncm_nth16 *)memset(skb_put(skb_out, sizeof(struct usb_cdc_ncm_nth16)), 0, sizeof(struct usb_cdc_ncm_nth16)); + nth16 = skb_put_zero(skb_out, sizeof(struct usb_cdc_ncm_nth16)); nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN); nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16)); nth16->wSequence = cpu_to_le16(ctx->tx_seq++); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192c/fw_common.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192c/fw_common.c index c7a7746..015476e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192c/fw_common.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192c/fw_common.c @@ -647,8 +647,7 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, skb = dev_alloc_skb(totalpacketlen); - memcpy((u8 *)skb_put(skb, totalpacketlen), - &reserved_page_packet, totalpacketlen); + skb_put_data(skb, &reserved_page_packet, totalpacketlen); if (cmd_send_packet) rtstatus = cmd_send_packet(hw, skb); diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c index 88faeab..f4129cf 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c @@ -668,8 +668,7 @@ void rtl92d_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished) if (!skb) { dlok = false; } else { - memcpy((u8 *) skb_put(skb, totalpacketlen), - &reserved_page_packet, totalpacketlen); + skb_put_data(skb, &reserved_page_packet, totalpacketlen); rtstatus = _rtl92d_cmd_send_packet(hw, skb); if (rtstatus) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c index 1f42ce5..6f8f75a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c @@ -708,8 +708,7 @@ void rtl92ee_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished) u1rsvdpageloc, 3); skb = dev_alloc_skb(totalpacketlen); - memcpy((u8 *)skb_put(skb, totalpacketlen), - &reserved_page_packet, totalpacketlen); + skb_put_data(skb, &reserved_page_packet, totalpacketlen); b_dlok = true; diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.c index a954a87b..bf9859f 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/fw.c @@ -470,8 +470,7 @@ void rtl8723e_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished) u1rsvdpageloc, 3); skb = dev_alloc_skb(totalpacketlen); - memcpy((u8 *)skb_put(skb, totalpacketlen), - &rese
[PATCH net-next 3/3] net: manual clean code which call skb_put_[data:zero]
From: yuan linyu Signed-off-by: yuan linyu --- drivers/isdn/hysdn/hycapi.c | 8 drivers/isdn/i4l/isdn_bsdcomp.c | 2 +- drivers/isdn/i4l/isdn_ppp.c | 2 +- drivers/net/bonding/bond_alb.c| 3 +-- drivers/net/caif/caif_hsi.c | 6 ++ drivers/net/caif/caif_serial.c| 3 +-- drivers/net/caif/caif_spi.c | 3 +-- drivers/net/ethernet/nxp/lpc_eth.c| 7 +++ drivers/net/ethernet/packetengines/hamachi.c | 4 ++-- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/usb/asix_common.c | 5 ++--- drivers/net/usb/hso.c | 13 ++--- drivers/net/wireless/ath/ath9k/wmi.c | 3 +-- drivers/net/wireless/marvell/libertas/if_sdio.c | 3 +-- drivers/net/wireless/quantenna/qtnfmac/qlink_util.h | 4 +--- drivers/net/wireless/realtek/rtlwifi/pci.c| 3 +-- drivers/net/wireless/rsi/rsi_91x_mgmt.c | 10 +++--- drivers/net/wireless/ti/wlcore/rx.c | 3 +-- drivers/nfc/pn533/pn533.c | 4 ++-- drivers/staging/rtl8188eu/core/rtw_recv.c | 4 +--- drivers/staging/rtl8192e/rtllib_rx.c | 5 ++--- drivers/staging/rtl8192e/rtllib_softmac.c | 11 ++- drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 +--- .../staging/rtl8192u/ieee80211/ieee80211_softmac.c| 11 +-- drivers/staging/rtl8192u/r819xU_cmdpkt.c | 3 +-- drivers/staging/rtl8712/rtl8712_recv.c| 4 ++-- drivers/staging/rtl8723bs/os_dep/recv_linux.c | 4 +--- drivers/staging/wlan-ng/hfa384x_usb.c | 2 +- drivers/usb/gadget/function/f_ncm.c | 11 +-- lib/nlattr.c | 6 +- net/bridge/netfilter/nft_reject_bridge.c | 6 ++ net/dsa/tag_trailer.c | 3 +-- net/hsr/hsr_device.c | 6 +++--- net/irda/irlap_frame.c| 5 ++--- net/mac80211/mlme.c | 12 net/mac80211/tdls.c | 19 +-- net/sctp/sm_make_chunk.c | 3 +-- net/vmw_vsock/virtio_transport_common.c | 5 ++--- net/x25/x25_subr.c| 16 39 files changed, 93 insertions(+), 135 deletions(-) diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c index 87119b5..eac0f51 100644 --- a/drivers/isdn/hysdn/hycapi.c +++ b/drivers/isdn/hysdn/hycapi.c @@ -173,8 +173,8 @@ hycapi_register_internal(struct capi_ctr *ctrl, __u16 appl, } skb_put_data(skb, &len, sizeof(__u16)); skb_put_data(skb, &appl, sizeof(__u16)); - memcpy(skb_put(skb, sizeof(__u8)), &_command, sizeof(_command)); - memcpy(skb_put(skb, sizeof(__u8)), &_subcommand, sizeof(_subcommand)); + skb_put_data(skb, &_command, sizeof(__u8)); + skb_put_data(skb, &_subcommand, sizeof(__u8)); skb_put_data(skb, &MessageNumber, sizeof(__u16)); skb_put_data(skb, &MessageBufferSize, sizeof(__u16)); skb_put_data(skb, &(rp->level3cnt), sizeof(__u16)); @@ -281,8 +281,8 @@ static void hycapi_release_internal(struct capi_ctr *ctrl, __u16 appl) } skb_put_data(skb, &len, sizeof(__u16)); skb_put_data(skb, &appl, sizeof(__u16)); - memcpy(skb_put(skb, sizeof(__u8)), &_command, sizeof(_command)); - memcpy(skb_put(skb, sizeof(__u8)), &_subcommand, sizeof(_subcommand)); + skb_put_data(skb, &_command, sizeof(__u8)); + skb_put_data(skb, &_subcommand, sizeof(__u8)); skb_put_data(skb, &MessageNumber, sizeof(__u16)); hycapi_send_message(ctrl, skb); hycapi_applications[appl - 1].ctrl_mask &= ~(1 << (ctrl->cnr - 1)); diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c index 3035210..5b64a13 100644 --- a/drivers/isdn/i4l/isdn_bsdcomp.c +++ b/drivers/isdn/i4l/isdn_bsdcomp.c @@ -472,7 +472,7 @@ static int bsd_compress(void *state, struct sk_buff *skb_in, struct sk_buff *skb accm |= ((ent) << bitno); \ do { \ if (skb_out && skb_tailroom(skb_out) > 0) \ - *(u8 *)skb_put(skb_out, 1) = (u8)(accm >> 24); \ + skb_put(skb_out, (u8)(accm >> 24)); \ accm <<= 8;
[PATCH net-next] net: raw: assign delivered after receive success
From: yuan linyu it's not reasonable to assign delivered if packet match no RAW sock Signed-off-by: yuan linyu --- net/ipv4/raw.c | 5 ++--- net/ipv6/raw.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index bdffad8..fa39894 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -187,15 +187,14 @@ static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash) skb->dev->ifindex); while (sk) { - delivered = 1; if ((iph->protocol != IPPROTO_ICMP || !icmp_filter(sk, skb)) && ip_mc_sf_allow(sk, iph->daddr, iph->saddr, skb->dev->ifindex)) { struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC); /* Not releasing hash table! */ - if (clone) - raw_rcv(sk, clone); + if (clone && raw_rcv(sk, clone) == NET_RX_SUCCESS) + delivered = 1; } sk = __raw_v4_lookup(net, sk_next(sk), iph->protocol, iph->saddr, iph->daddr, diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 60be012..de9483e 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -183,7 +183,6 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) while (sk) { int filtered; - delivered = true; switch (nexthdr) { case IPPROTO_ICMPV6: filtered = icmpv6_filter(sk, skb); @@ -218,7 +217,8 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) /* Not releasing hash table! */ if (clone) { nf_reset(clone); - rawv6_rcv(sk, clone); + if (rawv6_rcv(sk, clone) == NET_RX_SUCCESS) + delivered = true; } } sk = __raw_v6_lookup(net, sk_next(sk), nexthdr, daddr, saddr, -- 2.7.4
RE: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with udp_l3mdev_accept=0
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Subash Abhinov Kasiviswanathan > Sent: Tuesday, April 18, 2017 7:25 AM > To: d...@cumulusnetworks.com; da...@davemloft.net; > netdev@vger.kernel.org; rshea...@brocade.com; eric.duma...@gmail.com > Cc: Subash Abhinov Kasiviswanathan; Eric Dumazet > Subject: [PATCH net-next v2] net: ipv6: Fix UDP early demux lookup with > udp_l3mdev_accept=0 > > - return sk; > + udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) { > + if (INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif)) > + return sk; > + break; I think break here should remove ? > + } > + return NULL; > } > -- > 1.9.1
create drivers/net/mdio and move mdio drivers into it
Hi, I have an idea to create drivers/net/mdio and move mdio drivers(drivers/net/phy/mdio-* | drivers/net/ethernet/xxx/mdio-yyy | ) into it. Do you think it is acceptable ? Thanks
RE: create drivers/net/mdio and move mdio drivers into it
1. the main issue is mdio driver mixed with phy driver/ethernet driver. 2. move them together, it's easy to maintain, add, delete or optimization(we can do it step by step). 3. another idea is bind mdio device to network device 4. support mdio auto probe phy device. For 3, 4 can take device tree as example, Current, ethernet@e4000 { phy-handle = <&rgmii_phy1>; phy-connection-type = "rgmii"; }; ethernet@e6000 { phy-handle = <&rgmii_phy2>; phy-connection-type = "rgmii"; }; mdio@fc000 { rgmii_phy1: ethernet-phy@1 { reg = <0x1>; }; rgmii_phy2: ethernet-phy@2 { reg = <0x2>; }; }; After change, ethernet@e4000 { mdio-handle = <&mdio>; phy-reg = <0x1>; phy-connection-type = "rgmii"; }; ethernet@e6000 { mdio-handle = <&mdio>; phy-handle = <&rgmii_phy2>; phy-connection-type = "rgmii"; }; mdio: mdio@fc000 { reg = ; }; > -Original Message----- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Monday, February 20, 2017 1:03 PM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > > > On 02/19/2017 04:20 PM, YUAN Linyu wrote: > > Hi, > > > > I have an idea to create drivers/net/mdio and move mdio > drivers(drivers/net/phy/mdio-* | drivers/net/ethernet/xxx/mdio-yyy | ) into > it. > > > > Do you think it is acceptable ? > > What problem are you trying to fix by doing such a move? Moving files > around mean that making stable backports are going to be much more painful. > > So without further explanation, does not sound like such a great idea. > -- > Florian
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Monday, February 20, 2017 1:42 PM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > 3. another idea is bind mdio device to network device > > You would have to be more specific about what you want to do here. If > the MDIO device is e.g: a switch, what we recommend doing is provide a > fixed-link node that describes how the Ethernet MAC and the switch's > CPU/management ports are connected (that way the MAC always "sees" the > link as UP, running with a specific speed and duplex). > Yes, some system will configured the phy to fixed speed/duplex at boot time, no phy driver used in kernel at all. If network device know mdio device it used, we can do phy dump through this mdio device driver. > If this is a different kind of MDIO device, e.g: an USB/PCIe/SATA PHY, > there is no network device associated with those. > mdio under drivers/net/, it will not cover these devices.
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Monday, February 20, 2017 2:16 PM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > > > On 02/19/2017 10:10 PM, YUAN Linyu wrote: > > > > > >> -Original Message- > >> From: Florian Fainelli [mailto:f.faine...@gmail.com] > >> Sent: Monday, February 20, 2017 1:42 PM > >> To: YUAN Linyu; David S . Miller; Andrew Lunn > >> Cc: netdev@vger.kernel.org; cug...@163.com > >> Subject: Re: create drivers/net/mdio and move mdio drivers into it > >>> 3. another idea is bind mdio device to network device > >> > >> You would have to be more specific about what you want to do here. If > >> the MDIO device is e.g: a switch, what we recommend doing is provide a > >> fixed-link node that describes how the Ethernet MAC and the switch's > >> CPU/management ports are connected (that way the MAC always "sees" > the > >> link as UP, running with a specific speed and duplex). > >> > > Yes, some system will configured the phy to fixed speed/duplex at boot time, > > no phy driver used in kernel at all. > > There is always a PHY driver used, either is a dedicated one, or its the > generic PHY driver in drivers/net/phy/phy_device.c, even when fixed > PHYs/link are used. > > > If network device know mdio device it used, we can do phy dump through this > > mdio device driver. > > We are not going to accept MDIO device drivers whose only purpose is to > allow PHY devices register dumps. Implement a proper PHY driver for > these devices, if nothing needs to be done, you just need to call into > genphy_* functions, and just override how to do register dumps. > No, we discuss mdio driver here, not phy driver. I mean if a network device know mdio device it used, we use mdio driver to dump any register of phy device even it's driver is not build. > > > >> If this is a different kind of MDIO device, e.g: an USB/PCIe/SATA PHY, > >> there is no network device associated with those. > >> > > mdio under drivers/net/, it will not cover these devices. > > > > -- > Florian
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Monday, February 20, 2017 1:42 PM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > 4. support mdio auto probe phy device. > > That's already the case, even in a Device Tree enabled system if you > omit to provide a "reg" property for child nodes, the bus is > automatically scanned. > I check of_mdiobus_registe() which not do auto scan. Which function should I refer?
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Tuesday, February 21, 2017 6:31 AM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > > > On 02/19/2017 10:29 PM, YUAN Linyu wrote: > > > > > >> -Original Message- > >> From: Florian Fainelli [mailto:f.faine...@gmail.com] > >> Sent: Monday, February 20, 2017 1:42 PM > >> To: YUAN Linyu; David S . Miller; Andrew Lunn > >> Cc: netdev@vger.kernel.org; cug...@163.com > >> Subject: Re: create drivers/net/mdio and move mdio drivers into it > >>> 4. support mdio auto probe phy device. > >> > >> That's already the case, even in a Device Tree enabled system if you > >> omit to provide a "reg" property for child nodes, the bus is > >> automatically scanned. > >> > > I check of_mdiobus_registe() which not do auto scan. > > Which function should I refer? > > of_mdiobus_register() does this: > > /* Loop over the child nodes and register a phy_device for each > phy */ > for_each_available_child_of_node(np, child) { > addr = of_mdio_parse_addr(&mdio->dev, child); > if (addr < 0) { > scanphys = true; > continue; > } > > if (of_mdiobus_child_is_phy(child)) > of_mdiobus_register_phy(mdio, child, addr); > else > of_mdiobus_register_device(mdio, child, addr); > } > > if (!scanphys) > return 0; > > It does continue with scanning the PHY child nodes which don't have a > correct "reg" property set here. >From this code, it parse sub-node of mdio node. mdio@fc000 { rgmii_phy1: ethernet-phy@1 { }; }; But I think we can auto detect the phy even if there is no sub-node of mdio node. mdio@fc000 { }; > -- > Florian
RE: create drivers/net/mdio and move mdio drivers into it
Hi Florian, 1. Let's go back to original topic, Can we move all mdio dirvers into drivers/net/mdio ? Last time you said half convinced. If you insist not do it, l will follow your decision. 2. Per may understanding, I don't know why create a struct mii_bus instance to represent a mdio device in current mdio driver. Why not create a struct mdio_device instance, it's easy to understand. (We can move part of member of mii_bus to mdio_device). Then in mdio layer, there will mdio_device and mdio_driver. Other module(dsa) base on mdio should not register mdio_driver directly. thanks > -Original Message- > From: Florian Fainelli [mailto:f.faine...@gmail.com] > Sent: Tuesday, February 21, 2017 6:31 AM > To: YUAN Linyu; David S . Miller; Andrew Lunn > Cc: netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > > > On 02/19/2017 10:29 PM, YUAN Linyu wrote: > > > > > >> -Original Message- > >> From: Florian Fainelli [mailto:f.faine...@gmail.com] > >> Sent: Monday, February 20, 2017 1:42 PM > >> To: YUAN Linyu; David S . Miller; Andrew Lunn > >> Cc: netdev@vger.kernel.org; cug...@163.com > >> Subject: Re: create drivers/net/mdio and move mdio drivers into it > >>> 4. support mdio auto probe phy device. > >> > >> That's already the case, even in a Device Tree enabled system if you > >> omit to provide a "reg" property for child nodes, the bus is > >> automatically scanned. > >> > > I check of_mdiobus_registe() which not do auto scan. > > Which function should I refer? > > of_mdiobus_register() does this: > > /* Loop over the child nodes and register a phy_device for each > phy */ > for_each_available_child_of_node(np, child) { > addr = of_mdio_parse_addr(&mdio->dev, child); > if (addr < 0) { > scanphys = true; > continue; > } > > if (of_mdiobus_child_is_phy(child)) > of_mdiobus_register_phy(mdio, child, addr); > else > of_mdiobus_register_device(mdio, child, addr); > } > > if (!scanphys) > return 0; > > It does continue with scanning the PHY child nodes which don't have a > correct "reg" property set here. > -- > Florian
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: Andrew Lunn [mailto:and...@lunn.ch] > Sent: Wednesday, February 22, 2017 6:21 PM > To: YUAN Linyu > Cc: Florian Fainelli; David S . Miller; netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > On Wed, Feb 22, 2017 at 05:38:49AM +, YUAN Linyu wrote: > > Hi Florian, > > > > 1. > > Let's go back to original topic, > > Can we move all mdio dirvers into drivers/net/mdio ? > > Hi Yuan > > Please could you explain what benefit this brings. Please also list > all the downsides for such a move. As Florian said, we need to ensure > such a move adds more value than it removes. At beginning I think mdio and phy are two different things, mdio should have it's home. > > > Per may understanding, > > I don't know why create a struct mii_bus instance to represent a mdio device > in current mdio driver. > > Why not create a struct mdio_device instance, it's easy to understand. > > (We can move part of member of mii_bus to mdio_device). > > Please take a step back. What are you trying to achieve. What is the > big picture. What cannot you do with the current design? Big picture is we can remove struct mii_bus, and use struct mdio_device/driver for mdio controller. > > Andrew
RE: create drivers/net/mdio and move mdio drivers into it
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Andrew Lunn > Sent: Thursday, February 23, 2017 5:30 PM > To: YUAN Linyu > Cc: Florian Fainelli; David S . Miller; netdev@vger.kernel.org; cug...@163.com > Subject: Re: create drivers/net/mdio and move mdio drivers into it > > > Big picture is we can remove struct mii_bus, > > So if you remove this, how do you represent MII as a bus? It is a bus, > clause 22 allows up to 32 devices on it, and i have boards with more > than 8 devices on the bus. Clause 44 allows many more devices on the > bus. > add a phy device list to mdio_device. > Andrew
RE: [PATCH] net: add regs attribute to phy device for user diagnose
> -Original Message- > From: Zefir Kurtisi [mailto:zefir.kurt...@neratec.com] > > ... on the other hand, having direct RW access to MDIO regs can ease your life > greatly during bring-up / debugging of PHYs. > > Attached is a patch we are using to track down PHY problems at register level, > not > for integrating into the kernel but as a handy tool for developers. > We should follow previous discussion and move this debug feature to ethtool. Sysfs is not suggested by experts. I think it's reasonable and it's netdev development way. One thing that your patch only care a few registers. It's better to find a way to check all register of PHY. I will add two ethtool command in kernel to read and write register in PHY. ethtool can use these command to dump what user want, there is no more work to PHY driver. ( additional, mii-tool have two ioctl command[SIOCSMIIREG, SIOCGMIIREG], but is not export to use in mii-tool. It's better to add command to eth-tool which maintained closely with kernel. ) > > Cheers, > Zefir >
RE: [PATCH v3 net-next] net: mvneta: implement .set_wol and .get_wol
> -Original Message- > From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org] > On Behalf Of Jingju Hou > Sent: Monday, January 23, 2017 12:11 PM > To: da...@davemloft.net > Cc: jszh...@marvell.com; thomas.petazz...@free-electrons.com; > netdev@vger.kernel.org; Jingju Hou > Subject: [PATCH v3 net-next] net: mvneta: implement .set_wol and .get_wol > > The mvneta itself does not support WOL, but the PHY might. > So pass the calls to the PHY > > Signed-off-by: Jingju Hou > --- > Since v2: > - it should be phydev member not phy_dev > > drivers/net/ethernet/marvell/mvneta.c | 21 + > 1 file changed, 21 insertions(+) > > diff --git a/drivers/net/ethernet/marvell/mvneta.c > b/drivers/net/ethernet/marvell/mvneta.c > index e05e227..fea4968 100644 > --- a/drivers/net/ethernet/marvell/mvneta.c > +++ b/drivers/net/ethernet/marvell/mvneta.c > @@ -3908,6 +3908,25 @@ static int mvneta_ethtool_get_rxfh(struct > net_device *dev, u32 *indir, u8 *key, > return 0; > } > > +static void > +mvneta_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo > *wol) > +{ > + wol->supported = 0; > + wol->wolopts = 0; > + > + if (dev->phy_dev) Not changed, > + return phy_ethtool_get_wol(dev->phydev, wol); > +} > + > +static int > +mvneta_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) > +{ > + if (!dev->phydev) > + return -EOPNOTSUPP; > + > + return phy_ethtool_set_wol(dev->phydev, wol); > +} > + > static const struct net_device_ops mvneta_netdev_ops = { > .ndo_open= mvneta_open, > .ndo_stop= mvneta_stop, > @@ -3937,6 +3956,8 @@ static int mvneta_ethtool_get_rxfh(struct > net_device *dev, u32 *indir, u8 *key, > .set_rxfh = mvneta_ethtool_set_rxfh, > .get_link_ksettings = phy_ethtool_get_link_ksettings, > .set_link_ksettings = mvneta_ethtool_set_link_ksettings, > + .get_wol= mvneta_ethtool_get_wol, > + .set_wol= mvneta_ethtool_set_wol, > }; > > /* Initialize hw */ > -- > 1.9.1
[net-next] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 300 --- 1 file changed, 155 insertions(+), 145 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..5a3dfaa 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -240,13 +240,15 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; } break; case ND_OPT_PREFIX_INFO: ndopts->nd_opts_pi_end = nd_opt; if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; break; #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: @@ -261,8 +263,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +281,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +329,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +345,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->
[PATCH v2 net-next] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 300 --- 1 file changed, 155 insertions(+), 145 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..5a3dfaa 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -240,13 +240,15 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; } break; case ND_OPT_PREFIX_INFO: ndopts->nd_opts_pi_end = nd_opt; if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; break; #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: @@ -261,8 +263,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +281,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +329,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +345,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->
[PATCH net-next v3] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 310 +-- 1 file changed, 163 insertions(+), 147 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..7528c4c 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -240,13 +240,15 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; } break; case ND_OPT_PREFIX_INFO: ndopts->nd_opts_pi_end = nd_opt; if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; break; #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: @@ -261,8 +263,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +281,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +329,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +345,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->
[PATCH net-next v4] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 310 +-- 1 file changed, 163 insertions(+), 147 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..df31f29 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -240,13 +240,15 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; } break; case ND_OPT_PREFIX_INFO: ndopts->nd_opts_pi_end = nd_opt; if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + ndopts->nd_opt_array[nd_opt->nd_opt_type] = + nd_opt; break; #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: @@ -261,8 +263,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +281,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +329,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +345,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->
[PATCH net-next v5] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..5cf25bc 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -234,20 +234,28 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, case ND_OPT_TARGET_LL_ADDR: case ND_OPT_MTU: case ND_OPT_NONCE: - case ND_OPT_REDIRECT_HDR: - if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) { + case ND_OPT_REDIRECT_HDR: { + struct nd_opt_hdr **hdr; + + hdr = &ndopts->nd_opt_array[nd_opt->nd_opt_type]; + if (*hdr) { ND_PRINTK(2, warn, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + *hdr = nd_opt; } break; - case ND_OPT_PREFIX_INFO: + } + case ND_OPT_PREFIX_INFO: { + struct nd_opt_hdr **hdr; + + hdr = &ndopts->nd_opt_array[nd_opt->nd_opt_type]; ndopts->nd_opts_pi_end = nd_opt; - if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + if (!*hdr) + *hdr = nd_opt; break; + } #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: ndopts->nd_opts_ri_end = nd_opt; @@ -261,8 +269,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +287,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +335,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +351,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_s
[PATCH net-next v6] net: ipv6: fix code style error and warning of ndisc.c
From: yuan linyu CC: Joe Perches Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 324 +-- 1 file changed, 173 insertions(+), 151 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..5cf25bc 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -12,8 +12,7 @@ * 2 of the License, or (at your option) any later version. */ -/* - * Changes: +/* Changes: * * Alexey I. Froloff : RFC6106 (DNSSL) support * Pierre Ynard: export userland ND options @@ -99,7 +98,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +145,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +180,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +221,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -234,20 +234,28 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, case ND_OPT_TARGET_LL_ADDR: case ND_OPT_MTU: case ND_OPT_NONCE: - case ND_OPT_REDIRECT_HDR: - if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) { + case ND_OPT_REDIRECT_HDR: { + struct nd_opt_hdr **hdr; + + hdr = &ndopts->nd_opt_array[nd_opt->nd_opt_type]; + if (*hdr) { ND_PRINTK(2, warn, "%s: duplicated ND6 option found: type=%d\n", __func__, nd_opt->nd_opt_type); } else { - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + *hdr = nd_opt; } break; - case ND_OPT_PREFIX_INFO: + } + case ND_OPT_PREFIX_INFO: { + struct nd_opt_hdr **hdr; + + hdr = &ndopts->nd_opt_array[nd_opt->nd_opt_type]; ndopts->nd_opts_pi_end = nd_opt; - if (!ndopts->nd_opt_array[nd_opt->nd_opt_type]) - ndopts->nd_opt_array[nd_opt->nd_opt_type] = nd_opt; + if (!*hdr) + *hdr = nd_opt; break; + } #ifdef CONFIG_IPV6_ROUTE_INFO case ND_OPT_ROUTE_INFO: ndopts->nd_opts_ri_end = nd_opt; @@ -261,8 +269,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, if (!ndopts->nd_useropts) ndopts->nd_useropts = nd_opt; } else { - /* -* Unknown options must be silently ignored, + /* Unknown options must be silently ignored, * to accommodate future extension to the * protocol. */ @@ -280,7 +287,8 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, return ndopts; } -int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) +int ndisc_mc_map(const struct in6_addr *addr, char *buf, +struct net_device *dev, int dir) { switch (dev->type) { case ARPHRD_ETHER: @@ -327,9 +335,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __
[PATCH net-next 0/2] ndisc.c minor clean and improvement
From: yuan linyu 1. fix part of checkpatch issue which I like to fix 2. __ndisc_fill_addr_option() clean yuan linyu (2): net: ndisc.c: fix coding style issue net: ndisc.c: minor code improvement net/ipv6/ndisc.c | 139 --- 1 file changed, 70 insertions(+), 69 deletions(-) -- 2.7.4
[PATCH net-next 1/2] net: ndisc.c: fix coding style issue
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 109 --- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..292c827 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -99,7 +99,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +146,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +181,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +222,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -327,9 +328,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +344,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->flags & IFF_LOOPBACK) neigh->type = RTN_LOCAL; - } else if (dev->flags&IFF_POINTOPOINT) { + } else if (dev->flags & IFF_POINTOPOINT) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->broadcast, dev->addr_len); } @@ -357,7 +357,7 @@ static int ndisc_constructor(struct neighbour *neigh) neigh->ops = &ndisc_hh_ops; else neigh->ops = &ndisc_generic_ops; - if (neigh->nud_state&NUD_VALID) + if (neigh->nud_state & NUD_VALID) neigh->output = neigh->ops->connected_output; else neigh->output = neigh->ops->output; @@ -580,7 +580,7 @@ void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit, if (!saddr) { if (ipv6_get_lladdr(dev, &addr_buf, - (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))) + (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC))) return; saddr = &addr_buf; } @@ -641,9 +641,8 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, struct inet6_ifaddr *ifp = ipv6_get_ifaddr(dev_net(dev), saddr, dev, 1); if (ifp) { - if (ifp->flags & IFA_F_OPTIMISTIC) { + if (ifp->flags & IFA_F_OPTIMISTIC) send_sllao = 0; - } in6_ifa_put(ifp); } else { send_sllao = 0; @@ -672,7 +671,6 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, ndisc_send_skb(skb, daddr, saddr); } - static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb) { /* @@ -695,7 +693,7 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb) if (skb && ipv6_chk_addr_and_flags(dev_net(dev), &ipv6_hdr(skb)->saddr, dev, 1, -
[PATCH net-next 2/2] net: ndisc.c: minor code improvement
From: yuan linyu on x86_64, text size decrease 80 bytes Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 292c827..ee9b12c 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -147,17 +147,16 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, opt[0] = type; opt[1] = space >> 3; + opt += 2; - memset(opt + 2, 0, pad); + memset(opt, 0, pad); opt += pad; space -= pad; - memcpy(opt + 2, data, data_len); - data_len += 2; + memcpy(opt, data, data_len); opt += data_len; space -= data_len; - if (space > 0) - memset(opt, 0, space); + memset(opt, 0, space); } EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option); @@ -997,6 +996,7 @@ static void ndisc_recv_na(struct sk_buff *skb) if (neigh) { u8 old_flags = neigh->flags; struct net *net = dev_net(dev); + u32 flags; if (neigh->nud_state & NUD_FAILED) goto out; @@ -1013,13 +1013,14 @@ static void ndisc_recv_na(struct sk_buff *skb) goto out; } + flags = NEIGH_UPDATE_F_WEAK_OVERRIDE | NEIGH_UPDATE_F_OVERRIDE_ISROUTER; + if (msg->icmph.icmp6_override) + flags |= NEIGH_UPDATE_F_OVERRIDE; + if (msg->icmph.icmp6_router) + flags |= NEIGH_UPDATE_F_ISROUTER; ndisc_update(dev, neigh, lladdr, msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE, -NEIGH_UPDATE_F_WEAK_OVERRIDE| -(msg->icmph.icmp6_override ? NEIGH_UPDATE_F_OVERRIDE : 0)| -NEIGH_UPDATE_F_OVERRIDE_ISROUTER| -(msg->icmph.icmp6_router ? NEIGH_UPDATE_F_ISROUTER : 0), -NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts); +flags, NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts); if ((old_flags & ~neigh->flags) & NTF_ROUTER) { /* @@ -1217,12 +1218,11 @@ static void ndisc_router_discovery(struct sk_buff *skb) * received RA message (RFC 2462) -- yoshfuji */ old_if_flags = in6_dev->if_flags; - in6_dev->if_flags = (in6_dev->if_flags & ~(IF_RA_MANAGED | - IF_RA_OTHERCONF)) | - (ra_msg->icmph.icmp6_addrconf_managed ? - IF_RA_MANAGED : 0) | - (ra_msg->icmph.icmp6_addrconf_other ? - IF_RA_OTHERCONF : 0); + in6_dev->if_flags &= ~(IF_RA_MANAGED | IF_RA_OTHERCONF); + if (ra_msg->icmph.icmp6_addrconf_managed) + in6_dev->if_flags |= IF_RA_MANAGED; + if (ra_msg->icmph.icmp6_addrconf_other) + in6_dev->if_flags |= IF_RA_OTHERCONF; if (old_if_flags != in6_dev->if_flags) send_ifinfo_notify = true; -- 2.7.4
[PATCH net-next v1 0/2] ndisc.c minor clean and improvement
From: yuan linyu 1. fix part of checkpatch issue which I like to fix 2. __ndisc_fill_addr_option() clean v1: correct space value yuan linyu (2): net: ndisc.c: fix coding style issue net: ndisc.c: minor code improvement net/ipv6/ndisc.c | 141 --- 1 file changed, 72 insertions(+), 69 deletions(-) -- 2.7.4
[PATCH net-next v1 1/2] net: ndisc.c: fix coding style issue
From: yuan linyu Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 109 --- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index d310dc4..292c827 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -99,7 +99,6 @@ static const struct neigh_ops ndisc_hh_ops = { .connected_output = neigh_resolve_output, }; - static const struct neigh_ops ndisc_direct_ops = { .family = AF_INET6, .output = neigh_direct_output, @@ -147,13 +146,13 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, u8 *opt = skb_put(skb, space); opt[0] = type; - opt[1] = space>>3; + opt[1] = space >> 3; memset(opt + 2, 0, pad); opt += pad; space -= pad; - memcpy(opt+2, data, data_len); + memcpy(opt + 2, data, data_len); data_len += 2; opt += data_len; space -= data_len; @@ -182,6 +181,7 @@ static struct nd_opt_hdr *ndisc_next_option(struct nd_opt_hdr *cur, struct nd_opt_hdr *end) { int type; + if (!cur || !end || cur >= end) return NULL; type = cur->nd_opt_type; @@ -222,6 +222,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev, memset(ndopts, 0, sizeof(*ndopts)); while (opt_len) { int l; + if (opt_len < sizeof(struct nd_opt_hdr)) return NULL; l = nd_opt->nd_opt_len << 3; @@ -327,9 +328,8 @@ static int ndisc_constructor(struct neighbour *neigh) bool is_multicast = ipv6_addr_is_multicast(addr); in6_dev = in6_dev_get(dev); - if (!in6_dev) { + if (!in6_dev) return -EINVAL; - } parms = in6_dev->nd_parms; __neigh_parms_put(neigh->parms); @@ -344,12 +344,12 @@ static int ndisc_constructor(struct neighbour *neigh) if (is_multicast) { neigh->nud_state = NUD_NOARP; ndisc_mc_map(addr, neigh->ha, dev, 1); - } else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) { + } else if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->dev_addr, dev->addr_len); - if (dev->flags&IFF_LOOPBACK) + if (dev->flags & IFF_LOOPBACK) neigh->type = RTN_LOCAL; - } else if (dev->flags&IFF_POINTOPOINT) { + } else if (dev->flags & IFF_POINTOPOINT) { neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->broadcast, dev->addr_len); } @@ -357,7 +357,7 @@ static int ndisc_constructor(struct neighbour *neigh) neigh->ops = &ndisc_hh_ops; else neigh->ops = &ndisc_generic_ops; - if (neigh->nud_state&NUD_VALID) + if (neigh->nud_state & NUD_VALID) neigh->output = neigh->ops->connected_output; else neigh->output = neigh->ops->output; @@ -580,7 +580,7 @@ void ndisc_send_ns(struct net_device *dev, const struct in6_addr *solicit, if (!saddr) { if (ipv6_get_lladdr(dev, &addr_buf, - (IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))) + (IFA_F_TENTATIVE | IFA_F_OPTIMISTIC))) return; saddr = &addr_buf; } @@ -641,9 +641,8 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, struct inet6_ifaddr *ifp = ipv6_get_ifaddr(dev_net(dev), saddr, dev, 1); if (ifp) { - if (ifp->flags & IFA_F_OPTIMISTIC) { + if (ifp->flags & IFA_F_OPTIMISTIC) send_sllao = 0; - } in6_ifa_put(ifp); } else { send_sllao = 0; @@ -672,7 +671,6 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, ndisc_send_skb(skb, daddr, saddr); } - static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb) { /* @@ -695,7 +693,7 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb) if (skb && ipv6_chk_addr_and_flags(dev_net(dev), &ipv6_hdr(skb)->saddr, dev, 1, -
[PATCH net-next v1 2/2] net: ndisc.c: minor code improvement
From: yuan linyu on x86_64, text size decrease 64 bytes Signed-off-by: yuan linyu --- net/ipv6/ndisc.c | 34 ++ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 292c827..8051b46 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -147,17 +147,18 @@ void __ndisc_fill_addr_option(struct sk_buff *skb, int type, void *data, opt[0] = type; opt[1] = space >> 3; + opt += 2; + space -= 2; - memset(opt + 2, 0, pad); + memset(opt, 0, pad); opt += pad; space -= pad; - memcpy(opt + 2, data, data_len); - data_len += 2; + memcpy(opt, data, data_len); opt += data_len; space -= data_len; - if (space > 0) - memset(opt, 0, space); + + memset(opt, 0, space); } EXPORT_SYMBOL_GPL(__ndisc_fill_addr_option); @@ -997,6 +998,7 @@ static void ndisc_recv_na(struct sk_buff *skb) if (neigh) { u8 old_flags = neigh->flags; struct net *net = dev_net(dev); + u32 flags; if (neigh->nud_state & NUD_FAILED) goto out; @@ -1013,13 +1015,14 @@ static void ndisc_recv_na(struct sk_buff *skb) goto out; } + flags = NEIGH_UPDATE_F_WEAK_OVERRIDE | NEIGH_UPDATE_F_OVERRIDE_ISROUTER; + if (msg->icmph.icmp6_override) + flags |= NEIGH_UPDATE_F_OVERRIDE; + if (msg->icmph.icmp6_router) + flags |= NEIGH_UPDATE_F_ISROUTER; ndisc_update(dev, neigh, lladdr, msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE, -NEIGH_UPDATE_F_WEAK_OVERRIDE| -(msg->icmph.icmp6_override ? NEIGH_UPDATE_F_OVERRIDE : 0)| -NEIGH_UPDATE_F_OVERRIDE_ISROUTER| -(msg->icmph.icmp6_router ? NEIGH_UPDATE_F_ISROUTER : 0), -NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts); +flags, NDISC_NEIGHBOUR_ADVERTISEMENT, &ndopts); if ((old_flags & ~neigh->flags) & NTF_ROUTER) { /* @@ -1217,12 +1220,11 @@ static void ndisc_router_discovery(struct sk_buff *skb) * received RA message (RFC 2462) -- yoshfuji */ old_if_flags = in6_dev->if_flags; - in6_dev->if_flags = (in6_dev->if_flags & ~(IF_RA_MANAGED | - IF_RA_OTHERCONF)) | - (ra_msg->icmph.icmp6_addrconf_managed ? - IF_RA_MANAGED : 0) | - (ra_msg->icmph.icmp6_addrconf_other ? - IF_RA_OTHERCONF : 0); + in6_dev->if_flags &= ~(IF_RA_MANAGED | IF_RA_OTHERCONF); + if (ra_msg->icmph.icmp6_addrconf_managed) + in6_dev->if_flags |= IF_RA_MANAGED; + if (ra_msg->icmph.icmp6_addrconf_other) + in6_dev->if_flags |= IF_RA_OTHERCONF; if (old_if_flags != in6_dev->if_flags) send_ifinfo_notify = true; -- 2.7.4
Re: [PATCH net-next 1/2] net: ndisc.c: fix coding style issue
On 五, 2017-05-26 at 22:45 +0900, 吉藤英明 wrote: > Hi, > > 2017-05-26 22:23 GMT+09:00 yuan linyu : > > > > From: yuan linyu > > > > Signed-off-by: yuan linyu > > --- > > net/ipv6/ndisc.c | 109 > > --- > > 1 file changed, 55 insertions(+), 54 deletions(-) > Sorry, I don't think this kind of change for style is good > bacause this makes effort of backport more difficult. hi, i can't understand. if any change of this code you decide to backport, it need effort, not only important fix. do I miss your point ? > > --yoshfuji >
Re: [PATCH net-next 1/2] net: ndisc.c: fix coding style issue
On 六, 2017-05-27 at 02:25 +0900, 吉藤英明 wrote: > Hi, > > 2017-05-26 22:55 GMT+09:00 yuan linyu : > > > > On 五, 2017-05-26 at 22:45 +0900, 吉藤英明 wrote: > > > > > > Hi, > > > > > > 2017-05-26 22:23 GMT+09:00 yuan linyu : > > > > > > > > > > > > From: yuan linyu > > > > > > > > Signed-off-by: yuan linyu > > > > --- > > > > net/ipv6/ndisc.c | 109 > > > > --- > > > > 1 file changed, 55 insertions(+), 54 deletions(-) > > > Sorry, I don't think this kind of change for style is good > > > bacause this makes effort of backport more difficult. > > hi, i can't understand. > > if any change of this code you decide to backport, it need effort, > > not only important fix. > > > > do I miss your point ? > Please let us minimize our effort when doing so. > > If the style is not changed, we have more chance to apply the patch > itself on top of old tree. > > Thank you. I don't know you hate this kind of changes, from a code reader view, I like to see code with good style. I am not happy when reading code with this kind of bad style. And it only spend a command time to backport, right? it will never spend your effort only if this code will not change in future. > > > > > > > > > > > > --yoshfuji > > > > >