From patchwork Tue Jun 14 10:07:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 69983 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1963315qgf; Tue, 14 Jun 2016 03:07:32 -0700 (PDT) X-Received: by 10.98.71.135 with SMTP id p7mr2804995pfi.165.1465898851974; Tue, 14 Jun 2016 03:07:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ol5si23544425pab.73.2016.06.14.03.07.31; Tue, 14 Jun 2016 03:07:31 -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=@nifty.com; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752308AbcFNKHD (ORCPT + 30 others); Tue, 14 Jun 2016 06:07:03 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:55847 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751484AbcFNKGg (ORCPT ); Tue, 14 Jun 2016 06:06:36 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id u5EA5ngG003372; Tue, 14 Jun 2016 19:05:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u5EA5ngG003372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1465898752; bh=58SrlTeddgWYAJAcwQgkZ0mSrhKLRTonV3/wUxVFRfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=blvNYGYp3I/gb2iWiu5m0oJEF6U6KOwQY+VT60MM6B21Yy6LVfHh/LSbKFWu8ux0c FKbbihnkTFk+OwBW+e43MrFA3Ct3psXvBwwh2ANkHzAtthYizLA/Qge5xXnKsVzqym 5f8B9W/1b3WGl77GMLfQoSfyCV9nGT+c0nPx6UL1tB8ij19xCN7l3E0/6wiwjKGKci U+AZ7shtL3zkMXxkA2vbvFi1oC7npEMJGPKyZG65dff2aWwqYgAQixCvH9yjbNiohx lElio+/o55g145PlM7EKS4Td9V+zneYVsRzOVxvSfMfJ9VJ2z+aRZzuYQRxU6rpNHY gKEE23/ME8bXg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-gpio@vger.kernel.org Cc: Masahiro Yamada , Linus Walleij , Alexandre Courbot , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] gpio: of: move chip->of_gpio_n_cells checking to of_gpiochip_add() Date: Tue, 14 Jun 2016 19:07:05 +0900 Message-Id: <1465898827-2229-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465898827-2229-1-git-send-email-yamada.masahiro@socionext.com> References: <1465898827-2229-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do this sanity check only once when the gpio_chip is added rather than every time gpio-hog is handled. Signed-off-by: Masahiro Yamada --- drivers/gpio/gpiolib-of.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 27b1729..a5a5bc7 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -156,7 +156,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, if (ret) return ERR_PTR(ret); - if (tmp > MAX_PHANDLE_ARGS || tmp != chip->of_gpio_n_cells) + if (tmp != chip->of_gpio_n_cells) return ERR_PTR(-EINVAL); gpiospec.np = chip_np; @@ -487,6 +487,9 @@ int of_gpiochip_add(struct gpio_chip *chip) chip->of_xlate = of_gpio_simple_xlate; } + if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) + return -EINVAL; + status = of_gpiochip_add_pin_range(chip); if (status) return status;