Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp611957ybh; Thu, 12 Mar 2020 07:58:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsQTJw2H+Y8K76VT6ZijjXQXW3bwQLiFpvPOJ7Yj6gXAzzdwAyFjKdPLh4LNRPVe5wLFlOP X-Received: by 2002:a54:4396:: with SMTP id u22mr2962820oiv.128.1584025105014; Thu, 12 Mar 2020 07:58:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584025105; cv=none; d=google.com; s=arc-20160816; b=bq7GvKoA4iDwZ1sirc3PtY9cla3UAIlU4BFxAdSo83dnCh3SzDrsv47WRJ8V+45OJ4 xHdcp2Su1SUY3tGqQ5iPQ2w0Tq7mHmPqWOaP0DytONOUNRg4WdkXkEFwr0HXjuRXDzXc kjACODYdNWPPe1PGNPFQdsHfps5kas5dK/9lu5+4VWaLcydjt/e3IBObdqtR9xGq5POG lb/RGNB2nP971u1gWZmxh8E0HIHDehC/uCzKkkatQNnXKVVWHraMWlqwxpNGJw6pDQ1b 8cqQrXG3xhVTL7aQE+MHJ5tybmmoscPbzYK2GrcEohCBZavAsZUepGx+Q2q1zstgny1n az4w== 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=bxw33SxWFZjkWPj88ZuXOvwLRBj2S+g2ZJwa2FkjrJE=; b=U4ZBUHy4SJyqKIt7EZFGSTQgbL8Lpl146Ofg5AWGgpJL2Y3ssK7tkHxwOyqv5HEpYV OH6gh+Men/Uzmc82fVjyXzN4X3ZHyBkTSMwHvKO/5zdLujZOESNMHsBLswfNtK0Z6OAj S7GPoZKyQH5oB9q0JfBH3sJUlfEhZey855/6cZS839cl2gYi2YQ7aVp+2/sC+1cVn6Jn Um6neVPeJr8SCnmwcTTcmO9WyfCSZfIrSTJFjgKra3pKoHWXpAtQk6B7dFChg9Fqj3dN SyDNoQLTwXBdLvWaN5bLxjh8E8JVsia1KjKdpFQh5ojkCnwlhAeCm1SBv8ODj9fuRplr AeJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m2lcmjUG; 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 g22si1416330otn.104.2020.03.12.07.58.11; Thu, 12 Mar 2020 07:58:24 -0700 (PDT) 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=m2lcmjUG; 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 S1727524AbgCLO5k (ORCPT + 99 others); Thu, 12 Mar 2020 10:57:40 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:34526 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727241AbgCLO5k (ORCPT ); Thu, 12 Mar 2020 10:57:40 -0400 Received: by mail-ua1-f67.google.com with SMTP id g21so2225663uaj.1 for ; Thu, 12 Mar 2020 07:57:38 -0700 (PDT) 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=bxw33SxWFZjkWPj88ZuXOvwLRBj2S+g2ZJwa2FkjrJE=; b=m2lcmjUGkYWP7vkV0Vjot/cSZwZUNCcrXd/WLLuloMRr0AWoQY+jqcc/1wuUSM7DDw PqWzpdtoqX/gAP4yv2cKjurTp3cckazG7srtdvXHK8g76Tki8cdQXX8xelU3OB3zySg9 0KsHSFbk9uRX8+aRa4wmtwMYAvXbuXLOv70swGxt1sVRBXSVStkyGrRkeW0hlNtS8bAC H/DBHSdfGZmPGLqt093ppxRWjhZFdTFTZEnGt5kqd8UjsiZIQAZuxC20LSQMDmhmwdCA N6uxbr+q2W5htsfi5uFGNaAIdqYa9P6ZEEPBx1gbDz0x5QKr21FtszKn/uXbNtDP0Kgm zboA== 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=bxw33SxWFZjkWPj88ZuXOvwLRBj2S+g2ZJwa2FkjrJE=; b=X/ynw6NeE/aNRNI4LfpxDh0bjpqQ/c3GUD3WD64fHjEAkbuosm4AzMZW23aDnBo4d9 wlmG4o+TBT6IstPPQwMZ0Q6+FtvtwjcWbkwsNbKpPF44nP8HUJCeRxFHeixCqV/B2ko8 uiW3UQy/tlojdRp6+TBPISQqScREBv2hmdmoFML+hPJdReeBkcnX0J37kohB/E6IjkZJ g2EElwPKd81DesQRALkAqljxDczUpPQp+371w/drU7clDA0o8sJF5xwUBbeKj2Vw4wdi 28rFnuI7r0R5g3U6ql0Bb3XZKufPEm0Q6k/1wlAnbUSSrouIqL/Dy2iUbPHoYPQCrzSv NrFA== X-Gm-Message-State: ANhLgQ0D4ejmfw34zVmdy91ioUe2YjB/GxaInmDy0ucPK/Uei4W9PVIS CO4c0y6LN/eXbsFKLkRAqUJ2+1PPQvvu0z28Pbw6Zg== X-Received: by 2002:ab0:2a55:: with SMTP id p21mr3753572uar.54.1584025057464; Thu, 12 Mar 2020 07:57:37 -0700 (PDT) MIME-Version: 1.0 References: <20200218151812.7816-1-geert+renesas@glider.be> <20200218151812.7816-4-geert+renesas@glider.be> In-Reply-To: <20200218151812.7816-4-geert+renesas@glider.be> From: Linus Walleij Date: Thu, 12 Mar 2020 15:57:26 +0100 Message-ID: Subject: Re: [PATCH v5 3/5] gpio: Add GPIO Aggregator To: Geert Uytterhoeven Cc: Bartosz Golaszewski , Jonathan Corbet , Harish Jenny K N , Eugeniu Rosca , Alexander Graf , Peter Maydell , Paolo Bonzini , Phil Reid , Marc Zyngier , Christoffer Dall , Magnus Damm , Rob Herring , Mark Rutland , "open list:GPIO SUBSYSTEM" , Linux Doc Mailing List , 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, thanks for your patience and again sorry for procrastination on my part :( Overall I start to like this driver a lot. It has come a long way. Some comments below are nitpicky, bear with me if they seem stupid. On Tue, Feb 18, 2020 at 4:18 PM Geert Uytterhoeven wrote: > +#define DRV_NAME "gpio-aggregator" > +#define pr_fmt(fmt) DRV_NAME ": " fmt I would just use dev_[info|err] for all messages to get rid of this. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "gpiolib.h" When this file is includes I prefer if there is a comment next to this include saying why we have to touch internals and which ones. > +struct gpio_aggregator { > + struct gpiod_lookup_table *lookups; > + struct platform_device *pdev; What about just storing struct device *dev? Then callbacks can just dev_err(aggregator->dev, "myerror\n"); > +static char *get_arg(char **args) > +{ > + char *start = *args, *end; > + > + start = skip_spaces(start); > + if (!*start) > + return NULL; > + > + if (*start == '"') { > + /* Quoted arg */ > + end = strchr(++start, '"'); > + if (!end) > + return ERR_PTR(-EINVAL); > + } else { > + /* Unquoted arg */ > + for (end = start; *end && !isspace(*end); end++) ; > + } > + > + if (*end) > + *end++ = '\0'; > + > + *args = end; > + return start; > +} Isn't this function reimplementing strsep()? while ((s = strsep(&p, " \""))) { or something. I'm not the best with strings, just asking so I know you tried it already. > +static int aggr_parse(struct gpio_aggregator *aggr) > +{ > + unsigned int first_index, last_index, i, n = 0; > + char *name, *offsets, *first, *last, *next; > + char *args = aggr->args; > + int error; > + > + for (name = get_arg(&args), offsets = get_arg(&args); name; > + offsets = get_arg(&args)) { > + if (IS_ERR(name)) { > + pr_err("Cannot get GPIO specifier: %pe\n", name); If gpio_aggregrator contained struct device *dev this would be dev_err(aggr->dev, "...\n"); > +static void gpio_aggregator_free(struct gpio_aggregator *aggr) > +{ > + platform_device_unregister(aggr->pdev); Aha maybe store both the pdev and the dev in the struct then? Or print using &aggr->pdev.dev. > + /* > + * If any of the GPIO lines are sleeping, then the entire forwarder > + * will be sleeping. > + * If any of the chips support .set_config(), then the forwarder will > + * support setting configs. > + */ > + for (i = 0; i < ngpios; i++) { > + dev_dbg(dev, "gpio %u => gpio-%d (%s)\n", i, > + desc_to_gpio(descs[i]), descs[i]->label ? : "?"); If this desc->label business is why you need to include "gpiolib.h" then I'd prefer if you just add a const char *gpiod_get_producer_name(struct gpio_desc *desc); to gpiolib (add in so that gpiolib can try to give you something reasonable to print for the label here. I ran into that problem before (wanting to print something like this) and usually just printed the offset. But if it is a serious debug issue, let's fix a helper for this. gpiod_get_producer_name() could return the thing in desc->label if that is set or else something along "chipname-offset" or "unknown", I'm not very picky with that. > error = aggr_add_gpio(aggr, name, U16_MAX, &n); Is the reason why you use e.g. "gpiochip0" as name here that this is a simple ABI for userspace? Such like obtained from /sys/bus/gpio/devices/? I would actually prefer to just add a sysfs attribute such as "name" and set it to the value of gpiochip->label. These labels are compulsory and supposed to be unique. Then whatever creates an aggregator can just use cat /sys/bus/gpio/devices/gpiochipN/name to send in through the sysfs interface to this kernel driver. This will protect you in the following way: When a system is booted and populated the N in gpiochipN is not stable and this aggregator will be used by scripts that assume it is. We already had this dilemma with things like network interfaces like eth0/1. This can be because of things like probe order which can be random, or because someone compiled a kernel with a new driver for a gpiochip that wasn't detected before. This recently happened to Raspberry Pi, that added gpio driver for "firmware GPIOs" (IIRC). The label on the chip is going to be more stable I think, so it is better to use that. This should also rid the need to include "gpiolib.h" which makes me nervous. Yours, Linus Walleij