Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 10/21] media: dvb_core: slight optimization of addr compare

1 view
Skip to first unread message

Ding Tianhong

unread,
Dec 23, 2013, 12:20:01 AM12/23/13
to
Use the recently added and possibly more efficient
ether_addr_equal_unaligned to instead of memcmp.

Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>
Cc: linux...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Signed-off-by: Yang Yingliang <yangyi...@huawei.com>
Signed-off-by: Ding Tianhong <dingti...@huawei.com>
---
drivers/media/dvb-core/dvb_net.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index f91c80c..ff00f97 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -179,7 +179,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
eth = eth_hdr(skb);

if (*eth->h_dest & 1) {
- if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
+ if(ether_addr_equal_unaligned(eth->h_dest, dev->broadcast))
skb->pkt_type=PACKET_BROADCAST;
else
skb->pkt_type=PACKET_MULTICAST;
@@ -674,11 +674,11 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
if (priv->rx_mode != RX_MODE_PROMISC) {
if (priv->ule_skb->data[0] & 0x01) {
/* multicast or broadcast */
- if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
+ if (!ether_addr_equal_unaligned(priv->ule_skb->data, bc_addr)) {
/* multicast */
if (priv->rx_mode == RX_MODE_MULTI) {
int i;
- for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
+ for(i = 0; i < priv->multi_num && !ether_addr_equal_unaligned(priv->ule_skb->data, priv->multi_macs[i]); i++)
;
if (i == priv->multi_num)
drop = 1;
@@ -688,7 +688,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
}
/* else: broadcast */
}
- else if (memcmp(priv->ule_skb->data, dev->dev_addr, ETH_ALEN))
+ else if (!ether_addr_equal_unaligned(priv->ule_skb->data, dev->dev_addr))
drop = 1;
/* else: destination address matches the MAC address of our receiver device */
}
@@ -837,7 +837,7 @@ static void dvb_net_sec(struct net_device *dev,
}
if (pkt[5] & 0x02) {
/* handle LLC/SNAP, see rfc-1042 */
- if (pkt_len < 24 || memcmp(&pkt[12], "\xaa\xaa\x03\0\0\0", 6)) {
+ if (pkt_len < 24 || !ether_addr_equal_unaligned(&pkt[12], "\xaa\xaa\x03\0\0\0")) {
stats->rx_dropped++;
return;
}
--
1.8.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Ding Tianhong

unread,
Dec 24, 2013, 6:30:01 AM12/24/13
to
Use possibly more efficient ether_addr_equal
instead of memcmp.

Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>
Cc: linux...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Signed-off-by: Yang Yingliang <yangyi...@huawei.com>
Signed-off-by: Ding Tianhong <dingti...@huawei.com>
---
drivers/media/dvb-core/dvb_net.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index f91c80c..3dfc33b 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -179,7 +179,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
eth = eth_hdr(skb);

if (*eth->h_dest & 1) {
- if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
+ if(ether_addr_equal(eth->h_dest,dev->broadcast))
skb->pkt_type=PACKET_BROADCAST;
else
skb->pkt_type=PACKET_MULTICAST;
@@ -674,11 +674,11 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
if (priv->rx_mode != RX_MODE_PROMISC) {
if (priv->ule_skb->data[0] & 0x01) {
/* multicast or broadcast */
- if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
+ if (!ether_addr_equal(priv->ule_skb->data, bc_addr)) {
/* multicast */
if (priv->rx_mode == RX_MODE_MULTI) {
int i;
- for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
+ for(i = 0; i < priv->multi_num && !ether_addr_equal(priv->ule_skb->data, priv->multi_macs[i]); i++)
;
if (i == priv->multi_num)
drop = 1;
@@ -688,7 +688,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
}
/* else: broadcast */
}
- else if (memcmp(priv->ule_skb->data, dev->dev_addr, ETH_ALEN))
+ else if (!ether_addr_equal(priv->ule_skb->data, dev->dev_addr))
drop = 1;
/* else: destination address matches the MAC address of our receiver device */
}

Ding Tianhong

unread,
Dec 24, 2013, 10:30:02 PM12/24/13
to

Sergei Shtylyov

unread,
Dec 25, 2013, 6:00:02 AM12/25/13
to
Hello.

On 25-12-2013 7:29, Ding Tianhong wrote:

> Use possibly more efficient ether_addr_equal
> instead of memcmp.

> Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>
> Cc: linux...@vger.kernel.org
> Cc: linux-...@vger.kernel.org
> Signed-off-by: Yang Yingliang <yangyi...@huawei.com>
> Signed-off-by: Ding Tianhong <dingti...@huawei.com>
> ---
> drivers/media/dvb-core/dvb_net.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)

> diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
> index f91c80c..3dfc33b 100644
> --- a/drivers/media/dvb-core/dvb_net.c
> +++ b/drivers/media/dvb-core/dvb_net.c
> @@ -179,7 +179,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
> eth = eth_hdr(skb);
>
> if (*eth->h_dest & 1) {
> - if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
> + if(ether_addr_equal(eth->h_dest,dev->broadcast))

There should be space after comma.

> @@ -674,11 +674,11 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
> if (priv->rx_mode != RX_MODE_PROMISC) {
> if (priv->ule_skb->data[0] & 0x01) {
> /* multicast or broadcast */
> - if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
> + if (!ether_addr_equal(priv->ule_skb->data, bc_addr)) {
> /* multicast */
> if (priv->rx_mode == RX_MODE_MULTI) {
> int i;
> - for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
> + for(i = 0; i < priv->multi_num && !ether_addr_equal(priv->ule_skb->data, priv->multi_macs[i]); i++)

Shouldn't this line be broken?

> ;
> if (i == priv->multi_num)
> drop = 1;

WBR, Sergei

Ding Tianhong

unread,
Dec 26, 2013, 6:20:01 AM12/26/13
to
ok, thanks.

Regards

Ding Tianhong

unread,
Dec 26, 2013, 6:50:01 AM12/26/13
to
Use possibly more efficient ether_addr_equal
instead of memcmp.

Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>
Cc: linux...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Signed-off-by: Yang Yingliang <yangyi...@huawei.com>
Signed-off-by: Ding Tianhong <dingti...@huawei.com>
---
drivers/media/dvb-core/dvb_net.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index f91c80c..8a86b30 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -179,7 +179,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
eth = eth_hdr(skb);

if (*eth->h_dest & 1) {
- if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
+ if(ether_addr_equal(eth->h_dest,dev->broadcast))
skb->pkt_type=PACKET_BROADCAST;
else
skb->pkt_type=PACKET_MULTICAST;
@@ -674,11 +674,13 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
if (priv->rx_mode != RX_MODE_PROMISC) {
if (priv->ule_skb->data[0] & 0x01) {
/* multicast or broadcast */
- if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
+ if (!ether_addr_equal(priv->ule_skb->data, bc_addr)) {
/* multicast */
if (priv->rx_mode == RX_MODE_MULTI) {
int i;
- for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
+ for(i = 0; i < priv->multi_num &&
+ !ether_addr_equal(priv->ule_skb->data,
+ priv->multi_macs[i]); i++)
;
if (i == priv->multi_num)
drop = 1;
@@ -688,7 +690,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
}
/* else: broadcast */
}
- else if (memcmp(priv->ule_skb->data, dev->dev_addr, ETH_ALEN))
+ else if (!ether_addr_equal(priv->ule_skb->data, dev->dev_addr))
drop = 1;
/* else: destination address matches the MAC address of our receiver device */
}
--
1.8.0


Mauro Carvalho Chehab

unread,
Jan 7, 2014, 8:50:03 AM1/7/14
to
Em Mon, 23 Dec 2013 13:10:35 +0800
Ding Tianhong <dingti...@huawei.com> escreveu:

> Use the recently added and possibly more efficient
> ether_addr_equal_unaligned to instead of memcmp.

I'm ok with this change, but I prefer if you could merge it together with the
other patches, as I don't have the patch that added
ether_addr_equal_unaligned() on my tree yet.
>
> Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>

Acked-by: Mauro Carvalho Chehab <m.ch...@samsung.com>
Cheers,
Mauro

Mauro Carvalho Chehab

unread,
Jan 7, 2014, 9:00:02 AM1/7/14
to
Em Thu, 26 Dec 2013 19:09:10 +0800
Ding Tianhong <dingti...@huawei.com> escreveu:
Also, since you're touching on those lines, could you please add an space
after 'if' (on the first hunk) and after 'for' (on the second one)?

>
> Regards
> >> ;
> >> if (i == priv->multi_num)
> >> drop = 1;
> >
> > WBR, Sergei
> >
> >
> >
> >
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majo...@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html

Thanks,
Mauro

Ding Tianhong

unread,
Jan 7, 2014, 8:10:01 PM1/7/14
to
Ok, thanks

Regards
Ding

>>
>> Regards
>>>> ;
>>>> if (i == priv->multi_num)
>>>> drop = 1;
>>>
>>> WBR, Sergei
>>>
>>>
>>>
>>>
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-media" in
>> the body of a message to majo...@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> Thanks,
> Mauro
>
> .

Ding Tianhong

unread,
Jan 7, 2014, 10:00:03 PM1/7/14
to
Use possibly more efficient ether_addr_equal
instead of memcmp.

Cc: Mauro Carvalho Chehab <m.ch...@samsung.com>
Cc: linux...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Signed-off-by: Yang Yingliang <yangyi...@huawei.com>
Signed-off-by: Ding Tianhong <dingti...@huawei.com>
Acked-by: Mauro Carvalho Chehab <m.ch...@samsung.com>
---
drivers/media/dvb-core/dvb_net.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index f91c80c..8a86b30 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -179,7 +179,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
eth = eth_hdr(skb);

if (*eth->h_dest & 1) {
- if(memcmp(eth->h_dest,dev->broadcast, ETH_ALEN)==0)
+ if (ether_addr_equal(eth->h_dest,dev->broadcast))
skb->pkt_type=PACKET_BROADCAST;
else
skb->pkt_type=PACKET_MULTICAST;
@@ -674,11 +674,13 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
if (priv->rx_mode != RX_MODE_PROMISC) {
if (priv->ule_skb->data[0] & 0x01) {
/* multicast or broadcast */
- if (memcmp(priv->ule_skb->data, bc_addr, ETH_ALEN)) {
+ if (!ether_addr_equal(priv->ule_skb->data, bc_addr)) {
/* multicast */
if (priv->rx_mode == RX_MODE_MULTI) {
int i;
- for(i = 0; i < priv->multi_num && memcmp(priv->ule_skb->data, priv->multi_macs[i], ETH_ALEN); i++)
+ for (i = 0; i < priv->multi_num &&
+ !ether_addr_equal(priv->ule_skb->data,
+ priv->multi_macs[i]); i++)
;
if (i == priv->multi_num)
drop = 1;
@@ -688,7 +690,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
}
/* else: broadcast */
}
- else if (memcmp(priv->ule_skb->data, dev->dev_addr, ETH_ALEN))
+ else if (!ether_addr_equal(priv->ule_skb->data, dev->dev_addr))
drop = 1;
/* else: destination address matches the MAC address of our receiver device */
}
--
1.8.0
0 new messages