From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1E37C10F14 for ; Wed, 17 Apr 2019 03:01:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9687921773 for ; Wed, 17 Apr 2019 03:01:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ncnC7sNy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730363AbfDQDB6 (ORCPT ); Tue, 16 Apr 2019 23:01:58 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33912 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727816AbfDQDB6 (ORCPT ); Tue, 16 Apr 2019 23:01:58 -0400 Received: by mail-pl1-f194.google.com with SMTP id y6so11329228plt.1; Tue, 16 Apr 2019 20:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=H6ra+ahyLgjUN3c6dmjsWNelOx/B2qkGdT4LUD01MCA=; b=ncnC7sNyWTwqzBc7xavqWM4Mk4QXG7HVlKW/HY4Es+d8avRNe0uTqhjNRGiixb2GDC Lkd4VmrGRGIEY0TPr9KfCTV7C+GZsJzNnnmBSBOlS6yhbNabETXSnoFTvnYGkpKbvmEf MAObp1Se9Qxu7Cv3n6tingnRojG2t0tYECDd3l4zsrovu0QHd0yTFGwuvXhNEjezT4c7 16AH4riZfArAQuvusVJT7F6qdl6kN8CfRoTMkPIjsyKO1en1cgg4Db1ocq+BIvxpSu7a NQ+bK6ZJ/cbuneB/quE9geOcSlaOnAbpr7HbvulBWXPKuNrJsEpHuKMyAIR0xojKXhDf qOJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=H6ra+ahyLgjUN3c6dmjsWNelOx/B2qkGdT4LUD01MCA=; b=e+b6KzqRsc8lLnIISbkKTB0Vtq3Ju+O07Bekm4AtZmfx/Ew08oFMP3Pz1lH+oEOALH g/5xabzRjQVHLMi3186fa9YdVOBhhWnGljBcTGzsCtsiDfwMmLPaGgT2FE/GLp5oh5BV j0hsTxvFqJVmpwNrr3HIj+RVLnW1ccSiALgYpv5Ffq7ojOaipIIUMVLTYPBooponVlyn BY2Ez6O69+79U/vpI83jfzhi496DHk/nw0t8MRSXA5Ei9DnISQdkRyc0CHvlGmy1sjG6 8TIlkxM4WUdNdJ3V8KlWCYRsEV/AaY0wabgjdEbiJ6p2sYHiBaBDclybbx0PYQf8qs9w Yfog== X-Gm-Message-State: APjAAAXg3rbHSWPFOgbJrxvJO21/L4cAxLXj4KPYqEiJSRxqeak/AjBE G+gp1ErxDTB9cQrB53NWjGo= X-Google-Smtp-Source: APXvYqxvHFW4m9nNF4xIZ4eTWF2ivcZytUz7KaliNCUN22pcyjKc54PuiFdVGWaXjT7wVAAhobJNwQ== X-Received: by 2002:a17:902:e508:: with SMTP id ck8mr84420751plb.96.1555470117843; Tue, 16 Apr 2019 20:01:57 -0700 (PDT) Received: from [192.168.1.70] (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id m16sm128892675pfi.29.2019.04.16.20.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 20:01:57 -0700 (PDT) Subject: Re: [PATCH] of_net: add mtd-mac-address support to of_get_mac_address() To: Florian Fainelli , =?UTF-8?Q?Petr_=c5=a0tetiar?= , netdev@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring Cc: "David S. Miller" , Mark Rutland , Andrew Lunn , Heiner Kallweit , John Crispin , Felix Fietkau References: <1555445100-30936-1-git-send-email-ynezz@true.cz> From: Frank Rowand Message-ID: <93770c6a-5f99-38f6-276b-316c00176cac@gmail.com> Date: Tue, 16 Apr 2019 20:01:56 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi Rob, On 4/16/19 5:29 PM, Florian Fainelli wrote: > > > On 16/04/2019 13:05, Petr Štetiar wrote: >> From: John Crispin >> >> Many embedded devices have information such as MAC addresses stored >> inside MTD devices. This patch allows us to add a property inside a node >> describing a network interface. The new property points at a MTD >> partition with an offset where the MAC address can be found. >> >> This patch has originated in OpenWrt some time ago, so in order to >> consider usefulness of this patch, here are some real-world numbers >> which hopefully speak for themselves: >> >>   * mtd-mac-address                used 497 times in 357 device tree files >>   * mtd-mac-address-increment      used  74 times in  58 device tree files >>   * mtd-mac-address-increment-byte used   1 time  in   1 device tree file >> >> Signed-off-by: John Crispin >> Signed-off-by: Felix Fietkau >> [cleanup of the patch for upstream submission] >> Signed-off-by: Petr Štetiar >> --- > > [snip] > >> +static const void *of_get_mac_address_mtd(struct device_node *np) >> +{ >> +#ifdef CONFIG_MTD >> +    void *addr; >> +    size_t retlen; >> +    int size, ret; >> +    u8 mac[ETH_ALEN]; >> +    phandle phandle; >> +    const char *part; >> +    const __be32 *list; >> +    struct mtd_info *mtd; >> +    struct property *prop; >> +    u32 mac_inc = 0; >> +    u32 inc_idx = ETH_ALEN-1; >> +    struct device_node *mtd_np = NULL; > > Reverse christmas tree would look a bit nicer here. Do we a variable declaration format preference for drivers/of/*? -Frank > >> + >> +    list = of_get_property(np, "mtd-mac-address", &size); >> +    if (!list || (size != (2 * sizeof(*list)))) >> +        return NULL; >> + >> +    phandle = be32_to_cpup(list++); >> +    if (phandle) >> +        mtd_np = of_find_node_by_phandle(phandle); >> + >> +    if (!mtd_np) >> +        return NULL; >> + >> +    part = of_get_property(mtd_np, "label", NULL); >> +    if (!part) >> +        part = mtd_np->name; >> + >> +    mtd = get_mtd_device_nm(part); >> +    if (IS_ERR(mtd)) >> +        return NULL; >> + >> +    ret = mtd_read(mtd, be32_to_cpup(list), ETH_ALEN, &retlen, mac); >> +    put_mtd_device(mtd); >> + >> +    of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx); > > of_property_read_u8() would probably be good here since this can't be bigger than 5 anyway. > >> +    if (inc_idx > ETH_ALEN-1) >> +        return NULL; > >> +    if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc)) >> +        mac[inc_idx] += mac_inc; > > If I use a number greater than and included 128; this will cause a roll over, should this be range checked? Similarly, using of_property_read_u8() might be a better fit? > > Other than those, LGTM