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.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 32237C2D0C9 for ; Thu, 12 Dec 2019 13:21:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 034E621655 for ; Thu, 12 Dec 2019 13:21:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SSsBUJhx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729387AbfLLNU6 (ORCPT ); Thu, 12 Dec 2019 08:20:58 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:32974 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfLLNU6 (ORCPT ); Thu, 12 Dec 2019 08:20:58 -0500 Received: by mail-lj1-f195.google.com with SMTP id 21so2282998ljr.0 for ; Thu, 12 Dec 2019 05:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hg7Wl/6CET3pvbTGNm/tGvdeGMQk6gSudBEEyfBygCo=; b=SSsBUJhxA1aRWawSyAxOR8XEmSe8IeDhUogI22JjnRdTk3guoUUCNE18wU5spaIBSN Tge40xKNTf2c46f/Ct3PtBV62vLDyTgN2F3kU/LEPoq1BJ2nnzBXF8JYtD2eEX1mqIJz rW7wDkFNi5MxHljIDydZyIjHe6qK9dZp/ZzKZFTU8OzgxhvVNWUmlr/+DUAbJCPCYqdT SZmfh20Q3fi5Bhn0MuHL9ePyN6uLVtDrP1daGTkTkZZvu5ew56B9/mLwobAy+2/ftSrB 0Q9aN+TRxhkjgCuoZ7lNHssuUGfAJkwH65uRfr9oM3Du3HhN0ra9yv9gV/v3pVzTcRo0 0k3g== 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=Hg7Wl/6CET3pvbTGNm/tGvdeGMQk6gSudBEEyfBygCo=; b=pMOyE6cWdjO5uOoOov+x2hPYchEi1438IBf1cTzCc69geLHG9jbUx36Ij+JvqVGdhi MKV0yEX3BjvxW15kZAQOvDK8KhnnoE8geKlRoNQtitgifLbZtSGH0f9G2Xuu9zB0Z+KJ YGBN+OgqRHVf/r7xegSHzRfspo83Gqc1TA4RjSLsJhw3CrAlg4nYaWgABPCwbniGMLrB +9Ut6vbkmjdrwiOh7f06jGzX1PMkWdw3EGR7saw9mmEgMqDCUowNS+dGQ3NHF5fmUj7p iwNq1xBFAyjOQWPU7P+ZyKwSKLdK21daTEmGwgvzWWfGCuYhbJOUMk+3Kn2CkYj3h1q3 lzzg== X-Gm-Message-State: APjAAAWzwAu7/P69xxa3rJFgZ5UzjaeC8utBx4fsYk44/QdvkGzDafJz afJMWyeaw6IldDpCwnBtNeeijUJawzSigVSZqyvkhQ== X-Google-Smtp-Source: APXvYqw5fhzsAgc+HL+XC84iHcSjemi0g8V+vxBZMQOSmUPecN5cY5o5jyiYAB8ZURwvkZwuG5+myIg9qUaLJdi8vHI= X-Received: by 2002:a2e:844e:: with SMTP id u14mr5871004ljh.183.1576156856527; Thu, 12 Dec 2019 05:20:56 -0800 (PST) MIME-Version: 1.0 References: <20191127084253.16356-1-geert+renesas@glider.be> <20191127084253.16356-3-geert+renesas@glider.be> In-Reply-To: <20191127084253.16356-3-geert+renesas@glider.be> From: Linus Walleij Date: Thu, 12 Dec 2019 14:20:45 +0100 Message-ID: Subject: Re: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup To: Geert Uytterhoeven Cc: 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: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Hi Geert! 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? > 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. > +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 !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(). Yours, Linus Walleij