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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 E2EC9C433EF for ; Sat, 11 Sep 2021 22:06:22 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23D2F61059 for ; Sat, 11 Sep 2021 22:06:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 23D2F61059 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D999D838A8; Sun, 12 Sep 2021 00:06:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="ohryqLYV"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="w0x/QGqU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E8CF48389C; Sun, 12 Sep 2021 00:06:05 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ECCC683840 for ; Sun, 12 Sep 2021 00:06:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 2AF455C00BC; Sat, 11 Sep 2021 18:06:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 11 Sep 2021 18:06:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=FouRhLJDEShxf NkUCBmMsO2jn2DpIgaTyI87IjpUumQ=; b=ohryqLYVYKuby+YNTHILgAUF+asxT 1+RxVKp6LIgSEi/MyRKk5/2BXfxRmGz9xg1vEh/0B/MY+xrSxMb1J9fyaCsLNKkJ X9c7aVHsfy5yBUNh+Bz5ktuLjOuj7EcZagf/ELAV+IHUOCfrhJ6TYk6iOEELYd8S T3dexcDDxKyA/cu9t69YV5wtCmFmbF4hMvjJ9rX2hgn4Gt9iU4/7/NHSd1e0jTH8 GG9wyWG0jLZlt7vdVyUW+itDHABUVHuNZDo+c5q8Ow1OpheZgninaa+ABbjs9eAo xQK0CPZh5DrRzIWnW83uD/4+X1sOqLFZkK6MRAUuvjR8DfY4FBWDUbbzw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=FouRhLJDEShxfNkUCBmMsO2jn2DpIgaTyI87IjpUumQ=; b=w0x/QGqU D+Zh9u1yGR35HTkdSrai/CmWts0K6318sGRz75KUb3QBnNB8P2Lqv1aRsozHrun6 gLH3elMGXlt+pFuRa6+5qpBtuJ9OotL6Fi3bBFsP2AxekDkezoQTxeafwMQrjOgs fr4LuoT8Hn6Jtij4qPTWXIp3Xs+Cb7RliS4w3xnc1Qyt3LVGmo8gquJfKob4A+tH BYZT+fAWqsmGBct7p7yluYfTcK2D3AdZjakFVLhMWxx3InYIAQnPqscxBWQp2vr3 NUZ4ciV+h7hQKpNWbL1sLoDq2sHcrY9pEiM7jyUnfTDDF95GGNP6KrY/3ctmOTQU XWVvD1Dd6tLXDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeggedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 Sep 2021 18:05:59 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de Cc: Samuel Holland , Dario Binacchi , Jean-Jacques Hiblot , Patrick Delaunay , Pratyush Yadav , Simon Glass Subject: [PATCH 2/3] gpio: Verify validity of pin offsets from device trees Date: Sat, 11 Sep 2021 17:05:52 -0500 Message-Id: <20210911220553.9427-3-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911220553.9427-1-samuel@sholland.org> References: <20210911220553.9427-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Translation of an OF GPIO specifier should fail if the pin offset is larger than the number of pins in the GPIO bank. Signed-off-by: Samuel Holland --- drivers/gpio/gpio-uclass.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 57e87960ee4..6f2b1adfdec 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -188,10 +188,14 @@ int gpio_lookup_name(const char *name, struct udevice **devp, int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + if (args->args_count < 1) return -EINVAL; desc->offset = args->args[0]; + if (desc->offset >= uc_priv->gpio_count) + return -EINVAL; if (args->args_count < 2) return 0; -- 2.31.1