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 283E2C43603 for ; Thu, 12 Dec 2019 14:14:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EFA65214AF for ; Thu, 12 Dec 2019 14:14:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFA65214AF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifPES-00028C-RU for qemu-devel@archiver.kernel.org; Thu, 12 Dec 2019 09:14:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49267) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifOb4-0003eW-92 for qemu-devel@nongnu.org; Thu, 12 Dec 2019 08:33:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifOb2-0002f9-Os for qemu-devel@nongnu.org; Thu, 12 Dec 2019 08:33:38 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:41332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ifOb2-0002dV-ID for qemu-devel@nongnu.org; Thu, 12 Dec 2019 08:33:36 -0500 Received: by mail-oi1-f195.google.com with SMTP id i1so409193oie.8 for ; 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=ubcrILAsj0IiGasCgkyC49mc/Gmrg0xueyh88hZjFcZ5PUazTVkzBOVcWYi7ejGI8t P+MSGfJzGWxyBw1+3TQQXuSPECEXCHoeVp8+y7MeaULOa7r1+3wBxvpq1WBBzSRl6Lqx UDtn4nVxRgdrDMZVWcgpMkdfOiNEU6rzx3rUkCbLjm+9qD9K55zAAP4DdcZ0yQHeAutF LjMB0d+esnZ5IagBZUrgUnwzGD5wLFro3qllbbLZYig/2ZDchk4Q5tRm5RQXxv/v+m2W 2H7vMIv30lAUgU+WW7F5UPNx9XgLcJnhwpoPnoePt0Npu81bHi1sMy8pIXq+gqT7IFPS /LYQ== X-Gm-Message-State: APjAAAVHXRzsXHAXRy+U9BqulFC+ltx4pKFcnPyuPx85Oa0Snd1jv6Qo tIRLX3KrEfEBAT4Vw8gKLPJI6/8thJBgAsP/TYQ= 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 Content-Type: text/plain; charset="UTF-8" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.167.195 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , QEMU Developers , Phil Reid , Geert Uytterhoeven , Jonathan Corbet , Marc Zyngier , "open list:GPIO SUBSYSTEM" , Linux Doc Mailing List , Magnus Damm , Christoffer Dall , "linux-kernel@vger.kernel.org" , Linux-Renesas , Bartosz Golaszewski , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Rob Herring , Harish Jenny K N , Paolo Bonzini , Alexander Graf , Eugeniu Rosca Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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