From patchwork Sat Feb 2 16:29:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 2084421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 497E5DFE76 for ; Sat, 2 Feb 2013 16:31:39 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U1fwm-0001rC-Qf; Sat, 02 Feb 2013 16:28:08 +0000 Received: from mail-pa0-f50.google.com ([209.85.220.50]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U1fwE-0001kC-Bn for linux-arm-kernel@lists.infradead.org; Sat, 02 Feb 2013 16:27:35 +0000 Received: by mail-pa0-f50.google.com with SMTP id fa11so139784pad.23 for ; Sat, 02 Feb 2013 08:27:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=e/oyn5PJsHTa3KZG39AnvBswcivGOS9xSeuI97V0yAo=; b=XeRM8r1gg4bS2MORzPPW4Tr6q76ePnCjT/DWDaqQ0zsakAXYqzLpyhTBfc85AlfxVy vpLJVSI/ZUB7PeGXTRBC6ypL4AF3nPRp0DnWzQxh6Say7h/es63Kwul+42bR9aXGKlVr UPkeCNV0iJjFcaFkQgPqWdU4QbEnD5IpNGj5RzjoV0KGgfW3l7Py8ahrf05AFjGqtXvQ pbiO+6cDaff969FmM8gl5RAAbKroKNbrPnI6nTU8wgBhlZE+9RcnQtq2lTMt1RIMQ7xq nqLgxwMGsZXdLVRdliyYqCKSH3O0KWyuyJGF1MrQheox0Y1NjRL2EMIOzAt8NJOdo/Fk QGaA== X-Received: by 10.68.213.233 with SMTP id nv9mr41604341pbc.155.1359822452772; Sat, 02 Feb 2013 08:27:32 -0800 (PST) Received: from localhost.localdomain (softbank126010191003.bbtec.net. [126.10.191.3]) by mx.google.com with ESMTPS id vn2sm12100769pbc.31.2013.02.02.08.27.30 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 08:27:32 -0800 (PST) From: Alexandre Courbot To: Grant Likely , Linus Walleij , Arnd Bergmann Subject: [PATCH 4/9] gpiolib: use gpio_chips list in sysfs ops Date: Sun, 3 Feb 2013 01:29:27 +0900 Message-Id: <1359822572-26009-6-git-send-email-acourbot@nvidia.com> X-Mailer: git-send-email 1.8.1.1 In-Reply-To: <1359822572-26009-1-git-send-email-acourbot@nvidia.com> References: <1359822572-26009-1-git-send-email-acourbot@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130202_112734_530961_5B010447 X-CRM114-Status: GOOD ( 13.54 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.50 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (gnurou[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: linux-arch@vger.kernel.org, gnurou@gmail.com, Alexandre Courbot , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This makes the code both simpler and faster compared to parsing the GPIO number space. Signed-off-by: Alexandre Courbot Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 92f9ee4..e473ded 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1889,45 +1889,28 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip) static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) { struct gpio_chip *chip = NULL; - unsigned int gpio; - void *ret = NULL; - loff_t index = 0; + loff_t index = *pos; /* REVISIT this isn't locked against gpio_chip removal ... */ - for (gpio = 0; gpio_is_valid(gpio); gpio++) { - if (gpio_desc[gpio].chip == chip) - continue; - - chip = gpio_desc[gpio].chip; - if (!chip) - continue; - - if (index++ >= *pos) { - ret = chip; - break; - } - } - s->private = ""; - return ret; + list_for_each_entry(chip, &gpio_chips, list) + if (index-- == 0) + return chip; + + return NULL; } static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) { struct gpio_chip *chip = v; - unsigned int gpio; void *ret = NULL; - /* skip GPIOs provided by the current chip */ - for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { - chip = gpio_desc[gpio].chip; - if (chip) { - ret = chip; - break; - } - } + if (list_is_last(&chip->list, &gpio_chips)) + ret = NULL; + else + ret = list_entry(chip->list.next, struct gpio_chip, list); s->private = "\n"; ++*pos;