Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp810691ybl; Thu, 12 Dec 2019 05:21:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzb9R91ff6KtEdNnDfHhYfBvPuDWzONV13NvGG4mm8qTmdZYDBKXxrkcUkPR/3fWRiwgQvd X-Received: by 2002:a9d:d0b:: with SMTP id 11mr8388796oti.287.1576156902794; Thu, 12 Dec 2019 05:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576156902; cv=none; d=google.com; s=arc-20160816; b=aI1EORvL32L2MBbX+VQXTWbVnjOuzJScZeT9QrLc0kLpTssW5Q5vkvDzpUYQJtAZ1E zv8Ubxrn9KZmHojgjsugQtQl/wbUbO+QCW0M9OpGS77wk+6mytN6+wrR2KV1QWBERdl5 5vuwFikrP+TULf2ReeHze6nM44JrbLvVBjd+kSJvw8xCDxR11gi/GJaEldwOS/OemgXC Q1ISBpFsb7/rsYFBNy4AEBSsqlUwdpw+WycQ1ovFucLtCygnzUHTeMRXgzZnybJeQFaT AnaYkr82SX68CA5aHXWKCsmLozHmhL7+UpcEKC1gCkcmyqqfnd+PvFxZJiSlfgp7e1a4 3mCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Hg7Wl/6CET3pvbTGNm/tGvdeGMQk6gSudBEEyfBygCo=; b=eq9Hsp8GwCtJR7eitdW0vdD7z7HAdMjo6uIFc2tEFbFdFZjGQ2vlEFTpXKdHnp5rjW VNSBAYXUc/xjIQZGwy3Ma2KAZn1AjPycz9YMWL3Afb7sMGbbsGgZcA6HGoLY3QqWI7Tu xkNa+WeQwm/rfP2DAyWolp22uyRizbBqNt5b6LuXdqTFAbQC015EZauMyO10z563tz8c FJTANhErCinJBNbHQP7JogL+fzpgb765KLjc/A1r7i21R9e73QgrvsPNey/SfQwwI8Tr VUuSkohp3gURitYlwVE8jQ4BDzPBSs2Sy8F9D4pOkwkQvPqXiGQOwOEH8t+CYEk7MeJb Jd3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SSsBUJhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si3148055otr.297.2019.12.12.05.21.29; Thu, 12 Dec 2019 05:21:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SSsBUJhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729398AbfLLNU7 (ORCPT + 99 others); Thu, 12 Dec 2019 08:20:59 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41297 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729378AbfLLNU6 (ORCPT ); Thu, 12 Dec 2019 08:20:58 -0500 Received: by mail-lj1-f195.google.com with SMTP id h23so2254699ljc.8 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=TLnWKAxtR2Sig7qwL/uTSl9LcTgYXQWvi5MfbIqroWfRV/zqpK5FElC3Kf/8gJcsSY aksTkKd7fYDCuDKZ+CvaIAW63u4fct2ftzuedlWfIk+bCiCQ9d7PF6SSClWkWsaVxwfU ajKn9U5vqJmhv6NuH7L9nnQg4oeAcaoLrnsGlOVQJLTqtMbLJ1lmZgISll+8pzUwYw+O YsXLEfD08GNUauAj7PF2vZ4oipBXHu1LYgLzCRktIj05OTAKvt4pztepjYy3u8RWaVDj //O+1qnvdXDEz9XqnKJcT171CfdrJXdQ2vzFrX+Tk9S8I2U41U6PB+bLj5768FRPvM6l E0NQ== X-Gm-Message-State: APjAAAXTg91AFeXsSCOG/rVE0+1umUPRBSeQ1NNV+0GACj0uZr0VuH86 Ii2ZS+xnpxSoHWV2mGO525cVkVnQNy8klPIQM1yapw== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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