From patchwork Sat Nov 14 08:38:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bamvor Zhang Jian X-Patchwork-Id: 56557 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp241918lbb; Sat, 14 Nov 2015 00:39:13 -0800 (PST) X-Received: by 10.66.97.8 with SMTP id dw8mr37616393pab.113.1447490353415; Sat, 14 Nov 2015 00:39:13 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fi15si22366894pac.191.2015.11.14.00.39.13; Sat, 14 Nov 2015 00:39:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751095AbbKNIjM (ORCPT + 4 others); Sat, 14 Nov 2015 03:39:12 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:33464 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750814AbbKNIjM (ORCPT ); Sat, 14 Nov 2015 03:39:12 -0500 Received: by pabfh17 with SMTP id fh17so124060157pab.0 for ; Sat, 14 Nov 2015 00:39:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WgHCxiozNf2j6a+l4kJIrntId7eDZzDfdMCNsv4gA6U=; b=HcFOz2+q6iFM/dmmlclzRpCIw/HLXbPP4qnrabl5VfXY5rz9nFIRXz5+FhK54TdY9d 2uPc5ryX+2bzdpd/t2iNF5iLQ2IxavTDZFH8KKKuhf6DM2s4iJplPN+4BPPjMiXuoLoQ qXFSgmFNEZm/PMqwpVB0SZfl/S6UGhA6z8lH8bxWA/FdzNHvPLzjjy78uUupB8HEymJl G0C2eb6UyNYJMsIHXDEIOQ3nCjuYBhXkFlTEDoUiWcCeLSA6PuRDm53MYqZHdXN4PS5k RZgLO+PEIm8ihtPYnNqKCJ4VUIfBnaDQeTspFs0MVomJ1GUc4TzQrW45txqJbGjCxZgn cfuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WgHCxiozNf2j6a+l4kJIrntId7eDZzDfdMCNsv4gA6U=; b=AApbIbGkJxhPN/836dSpFfc3ze05I1Ferzvf+BgfAlLWDiAHt0gVWouEBuNAkiB2xz 4jIQ0eUPOT5OhJx5J/bFOjYBA+cB2MqJhyvzsRjN7IxqMr1XPtSZUY7HmiWHb1qzKMds ixr42OW8k9uwxwOuyzrRkDBAtwFoJN9CFG44ARl1fhOPpi+m143kdwbhAuLsoyI3sExY wWPiQzHgRlkgFDuPUw8lo6c+RmSZ4gogyAlQy7vCi1ons71v+v9wW8p90NwSGqBdiSc+ q8EQvvJD0K4AYMKoVjZmZqAQ9mZC6rB+D8xz+38mpTj9T3arGgTrhvrwRvv9iy1xTIWX tLNg== X-Gm-Message-State: ALoCoQlOGhndpd/I05nH7FiMHbXlP1wwXk67cArt5230cwc1Vs40F4Q/WFtP8C79ha5NcTDCslZM X-Received: by 10.66.181.234 with SMTP id dz10mr38114694pac.51.1447490351696; Sat, 14 Nov 2015 00:39:11 -0800 (PST) Received: from linux-j170.site ([116.251.213.227]) by smtp.gmail.com with ESMTPSA id ur1sm8863768pbc.44.2015.11.14.00.39.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 14 Nov 2015 00:39:11 -0800 (PST) From: Bamvor Jian Zhang To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, broonie@kernel.org, Bamvor Jian Zhang Subject: [PATCH 1/2] gpiolib: improve overlap check of range of gpio Date: Sat, 14 Nov 2015 16:38:55 +0800 Message-Id: <1447490336-10209-2-git-send-email-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447490336-10209-1-git-send-email-bamvor.zhangjian@linaro.org> References: <1447490336-10209-1-git-send-email-bamvor.zhangjian@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org There are limitations for the current checker: 1. Could not check the overlap if the new gpiochip is the secondly gpiochip. 2. Could not check the overlap if the new gpiochip is overlap with the left of gpiochip. E.g. if we insert [c, d] between [a,b] and [e, f], and e >= c + d, it will successful even if c < a + b. 3. Allow overlap of base of different gpiochip. This patch fix these issues by checking the overlap of both right and left gpiochip in the same loop statement. Signed-off-by: Bamvor Jian Zhang --- drivers/gpio/gpiolib.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6798355..cc135d9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -191,29 +191,48 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) { struct list_head *pos; struct gpio_chip *_chip; + struct gpio_chip *_chip_prev = NULL; int err = 0; - /* find where to insert our chip */ - list_for_each(pos, &gpio_chips) { - _chip = list_entry(pos, struct gpio_chip, list); - /* shall we insert before _chip? */ - if (_chip->base >= chip->base + chip->ngpio) - break; + if (list_empty(&gpio_chips)) { + pos = gpio_chips.next; + goto found; } - /* are we stepping on the chip right before? */ - if (pos != &gpio_chips && pos->prev != &gpio_chips) { - _chip = list_entry(pos->prev, struct gpio_chip, list); - if (_chip->base + _chip->ngpio > chip->base) { + list_for_each(pos, &gpio_chips) { + _chip = list_entry(pos, struct gpio_chip, list); + if (_chip->base == chip->base) { dev_err(chip->dev, - "GPIO integer space overlap, cannot add chip\n"); + "GPIO base overlap<%d>, cannot add chip\n", + chip->base); err = -EBUSY; + goto err; } + if (_chip->base >= chip->base + chip->ngpio) { + /* we are the before the first existence gpio*/ + if (pos->prev == &gpio_chips) { + goto found; + } else { + if (_chip_prev->base + _chip_prev->ngpio + <= chip->base) + goto found; + } + } + _chip_prev = _chip; } + if (_chip->base + _chip->ngpio <= chip->base) + goto found; + dev_err(chip->dev, + "GPIO integer space overlap, cannot add chip\n"); + err = -EBUSY; + goto err; + +found: if (!err) list_add_tail(&chip->list, pos); +err: return err; }