Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754525AbbKCOFf (ORCPT ); Tue, 3 Nov 2015 09:05:35 -0500 Received: from mail-wi0-f175.google.com ([209.85.212.175]:32857 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751880AbbKCOFc (ORCPT ); Tue, 3 Nov 2015 09:05:32 -0500 Subject: Re: [PATCH v2 net-next] net/core: generic support for disabling netdev features down stack To: Jarod Wilson , Geert Uytterhoeven References: <1446486818-26166-1-git-send-email-jarod@redhat.com> <1446519359-21400-1-git-send-email-jarod@redhat.com> <5638865D.2000804@cumulusnetworks.com> <5638BD2E.8010508@redhat.com> Cc: "linux-kernel@vger.kernel.org" , "David S. Miller" , Eric Dumazet , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Jiri Pirko , Nikolay Aleksandrov , Michal Kubecek , Alexander Duyck , "netdev@vger.kernel.org" From: Nikolay Aleksandrov X-Enigmail-Draft-Status: N1110 Message-ID: <5638BF29.7030601@cumulusnetworks.com> Date: Tue, 3 Nov 2015 15:05:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5638BD2E.8010508@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1963 Lines: 55 On 11/03/2015 02:57 PM, Jarod Wilson wrote: > Geert Uytterhoeven wrote: >> On Tue, Nov 3, 2015 at 11:03 AM, Nikolay Aleksandrov >> wrote: >>> On 11/03/2015 03:55 AM, Jarod Wilson wrote: >>> [snip] >>>> +#define for_each_netdev_feature(mask_addr, feature) \ >>>> + int bit; \ >>>> + for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT) \ >>>> + feature = __NETIF_F_BIT(bit); >>>> + >>> ^ >>> This is broken, it will not work for more than a single feature. >> >> Indeed it is. >> >> This is used as: >> >> for_each_netdev_feature(&upper_disables, feature) { >> ... >> } >> >> which expands to: >> >> int bit; >> for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT) >> feature = __NETIF_F_BIT(bit); >> { >> ... >> } >> >> Note the assignment to "feature" happens outside the {}-delimited block. >> And the block is always executed once. > > Bah, crap, I was still staring at the code not seeing it, thank you for the detailed cluebat. I'll fix that up right now. > Yeah, sorry for not elaborating, I wrote it in a hurry. :-) Thanks Geert! By the way since you'll be changing this code, I don't know if it's okay to declare caller-visible hidden local variables in a macro like this, at the very least please consider renaming it to something that's much less common, I can see "bit" being used here and there. IMO either try to find a way to avoid it altogether or add another argument to the macro so it's explicitly passed. Cheers, Nik -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/