From patchwork Fri Jan 22 15:13:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 43483 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C828DB7CC2 for ; Sat, 23 Jan 2010 02:13:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755092Ab0AVPNP (ORCPT ); Fri, 22 Jan 2010 10:13:15 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754636Ab0AVPNP (ORCPT ); Fri, 22 Jan 2010 10:13:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14116 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753833Ab0AVPNF (ORCPT ); Fri, 22 Jan 2010 10:13:05 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0MFD4am017175 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Jan 2010 10:13:04 -0500 Received: from localhost (vpn2-8-128.ams2.redhat.com [10.36.8.128]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0MFD219008930; Fri, 22 Jan 2010 10:13:03 -0500 Date: Fri, 22 Jan 2010 16:13:02 +0100 From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, linux-kernel@vger.kernel.org Subject: [RFC, PATCH net-next-2.6] net: introduce a macro to traverse through uc_list easily Message-ID: <20100122151301.GC2609@psychotron.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org I'm thinking how to convert mc_list into list_head in the smoothest way. It's almost impossible to convert it at once in all drivers (It's used in almost all of them). From the mc_list of structures (either old or new list), only one member is needed in drivers' code - addr. Therefore that would be good to introduce a macro that can be used to traverse through addresses in the list without caller knowing anything about the type of the list. I think this kind of an abstraction is appropriate on this place. Also during the phase of changing, the macro can use the original list and once all drivers are using this macro, the list itself (so as the macro) can be converted into list_head. This patch shows the macro on uc_list (previously converted into list_head). What do you think about this? Please comment. Signed-off-by: Jiri Pirko --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/niu.c b/drivers/net/niu.c index 0e260cf..85d490b 100644 --- a/drivers/net/niu.c +++ b/drivers/net/niu.c @@ -22,7 +22,6 @@ #include #include #include -#include #include @@ -6359,7 +6358,7 @@ static void niu_set_rx_mode(struct net_device *dev) struct niu *np = netdev_priv(dev); int i, alt_cnt, err; struct dev_addr_list *addr; - struct netdev_hw_addr *ha; + unsigned char *ha; unsigned long flags; u16 hash[16] = { 0, }; @@ -6381,8 +6380,8 @@ static void niu_set_rx_mode(struct net_device *dev) if (alt_cnt) { int index = 0; - list_for_each_entry(ha, &dev->uc.list, list) { - err = niu_set_alt_mac(np, index, ha->addr); + netdev_for_each_uc_addr(ha, dev) { + err = niu_set_alt_mac(np, index, ha); if (err) printk(KERN_WARNING PFX "%s: Error %d " "adding alt mac %d\n", diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 727d265..c11d117 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -263,6 +263,19 @@ struct netdev_hw_addr_list { int count; }; +#define netdev_hw_addr_get_by_addr(a) \ + container_of((void *) a, struct netdev_hw_addr, addr) + +#define netdev_for_each_addr(a, head) \ + for (a = list_entry((head)->next, struct netdev_hw_addr, list)->addr; \ + prefetch(netdev_hw_addr_get_by_addr(a)->list.next), \ + &netdev_hw_addr_get_by_addr(a)->list != (head); \ + a = list_entry(netdev_hw_addr_get_by_addr(a)->list.next, \ + struct netdev_hw_addr, list)->addr) + +#define netdev_for_each_uc_addr(a, dev) \ + netdev_for_each_addr(a, &dev->uc.list) + struct hh_cache { struct hh_cache *hh_next; /* Next entry */ atomic_t hh_refcnt; /* number of users */