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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no 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 6076AC00454 for ; Thu, 12 Dec 2019 13:33:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 412E322527 for ; Thu, 12 Dec 2019 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729400AbfLLNdh (ORCPT ); Thu, 12 Dec 2019 08:33:37 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:40342 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729302AbfLLNdh (ORCPT ); Thu, 12 Dec 2019 08:33:37 -0500 Received: by mail-oi1-f195.google.com with SMTP id 6so410540oix.7; Thu, 12 Dec 2019 05:33:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B1c5GbpC2qZV4XZL32ReXMmOl4Gf9Xdye7e43MFMR8g=; b=ir+J4KCiAPAkjvp0ky7CL/fRvOfMW0Zm7o6v1rXeaVUwDUxF+C9TNjXpn/BysOxlk7 jJoVe5vx7/SBDPPYb7u1VhtIifglsrR+YblRpsrivUjYZYP9lccjXlwbyfruFgZBi8qa FG80TRt7j8ounLnQC3UpkFKEVH/R6a6/IJHuA+ChO6JBMQ5umQTxLXd46SyztwKTsBUj +kXOZseOs9sI5AUoKcO2Vr3PN/+LrB6oxo5jqQKIwFy3+s96Uop2ypSNkqKzDZ5/i3KZ 6oaJR4CsJthXtHp5SJYfNYltMOJyuTE6WmZQV9n85PdWWAtrg0fWq9yUp/ixquWJprKb WHPA== X-Gm-Message-State: APjAAAVhFittvr2zZoo96SeXv2x9q8StI17TKbAhNdj1Uu3I2nzUKQ7u HaYg40oYzoh4JCwP1mVESs5PZCWVAVuwNI6D3Tk= X-Google-Smtp-Source: APXvYqyZrB81syD0Ce6WwALcSofZswA84PMJGyV785ydrh5qmd3i1ZIC8I8AuxCcmSbHRH3rYOaGved6PnxX/cMztls= X-Received: by 2002:aca:4e87:: with SMTP id c129mr4645921oib.153.1576157615510; Thu, 12 Dec 2019 05:33:35 -0800 (PST) MIME-Version: 1.0 References: <20191127084253.16356-1-geert+renesas@glider.be> <20191127084253.16356-3-geert+renesas@glider.be> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 12 Dec 2019 14:33:24 +0100 Message-ID: Subject: Re: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup To: Linus Walleij Cc: Geert Uytterhoeven , Bartosz Golaszewski , Jonathan Corbet , Rob Herring , Mark Rutland , Harish Jenny K N , Eugeniu Rosca , Alexander Graf , Peter Maydell , Paolo Bonzini , Phil Reid , Marc Zyngier , Christoffer Dall , Magnus Damm , "open list:GPIO SUBSYSTEM" , Linux Doc Mailing List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux-Renesas , "linux-kernel@vger.kernel.org" , QEMU Developers Content-Type: text/plain; charset="UTF-8" Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Hi Linus, On Thu, Dec 12, 2019 at 2:20 PM Linus Walleij wrote: > On Wed, Nov 27, 2019 at 9:43 AM Geert Uytterhoeven > wrote: > > Currently GPIO controllers can only be referred to by label in GPIO > > lookup tables. > > > > Add support for looking them up by "gpiochipN" name, with "N" either the > > corresponding GPIO device's ID number, or the GPIO controller's first > > GPIO number. > > > > Signed-off-by: Geert Uytterhoeven > > What the commit message is missing is a rationale, why is this needed? Right. To be added: so they can be looked up in the GPIO lookup table using either the chip's label, or the "gpiochipN" name. > > If this is rejected, the GPIO Aggregator documentation must be updated. > > > > The second variant is currently used by the legacy sysfs interface only, > > so perhaps the chip->base check should be dropped? > > Anything improving the sysfs is actively discouraged by me. > If it is just about staying compatible it is another thing. OK, so N must be the corresponding GPIO device's ID number. > > +static int gpiochip_match_id(struct gpio_chip *chip, void *data) > > +{ > > + int id = (uintptr_t)data; > > + > > + return id == chip->base || id == chip->gpiodev->id; > > +} > > static struct gpio_chip *find_chip_by_name(const char *name) > > { > > - return gpiochip_find((void *)name, gpiochip_match_name); > > + struct gpio_chip *chip; > > + int id; > > + > > + chip = gpiochip_find((void *)name, gpiochip_match_name); > > + if (chip) > > + return chip; > > + > > + if (!str_has_prefix(name, GPIOCHIP_NAME)) > > + return NULL; > > + > > + if (kstrtoint(name + strlen(GPIOCHIP_NAME), 10, &id)) > > + return NULL; > > + > > + return gpiochip_find((void *)(uintptr_t)id, gpiochip_match_id); > > Isn't it easier to just augment the existing match function to > check like this: > > static int gpiochip_match_name(struct gpio_chip *chip, void *data) > { > const char *name = data; > > if (!strcmp(chip->label, name)) > return 0; return true; > return !strcmp(dev_name(&chip->gpiodev->dev), name); > } Oh, didn't think of using dev_name() on the gpiodev. Yes, with the chip->base check removed, the code can be simplified. Or just return !strcmp(chip->label, name) || !strcmp(dev_name(&chip->gpiodev->dev), name); > We should I guess also add some kerneldoc to say we first > match on the label and second on dev_name(). OK. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds