From patchwork Mon Mar 11 11:00:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13588589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BA31C5475B for ; Mon, 11 Mar 2024 11:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NxeU1athU4msXaB95IHUEvsC+yvOOsbLvD4WyqReWq4=; b=pRVMO5waGsLayu dBYtMSlweF/6hfF4Y2ENFjuzBzLsYMy98YJAwQACOyEN1HDRvlLBoAfEbU5qYPYjaZBA3ZghPgmi9 Eu39SqO/qB9+pABpxe9H2IDVhNHMrgv3G4JGwTH3nc6TYVMS+AWM4E0bhFm1g288SFCPHNcALHqDv OsTSBvGi9Ff+2gxfiNvtwTsf3tTiAFjz+3Pp8Njf9AbKIjHcSDH1qk74juKQkS0CY+JoHvxqE0QQS wu5bpzVtIqax6fYwDZ9C0kgHEtZnYBlOctqnRaf2v6j1vJJ2f47Y3H1OR1ja+1elazRVgdwyk2szL 3oaU1vAwX8U92ctvy3MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjdP9-00000001BYn-269h; Mon, 11 Mar 2024 11:01:15 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjdP2-00000001BVJ-3ajv for linux-arm-kernel@lists.infradead.org; Mon, 11 Mar 2024 11:01:13 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-512e39226efso4068704e87.0 for ; Mon, 11 Mar 2024 04:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710154858; x=1710759658; darn=lists.infradead.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=S1M9CrsxURK9osAlAJKJLTrbinlvddAx/ivsJ1lbXFE=; b=Y7dxvhb+zRjAw0leK3lmyssqMjJVDxjSN/3+2dtI1xOnR69Dk5fEAkfYl62zCazQO1 X/h5NZwF4IPZeKMex8NDT8RMktNgadsDU+8u2U7A9moC0RLbpZLuh05ud1CH2j7E8ksi EP0Vonz8QVAigJhmrpUBEFvfdfcDI1bQy/GFUVnQXpRpr+1s5bdRKgMGT95bakL3KD/L oiTEB8+cw2Fia8VUcb80uzlDFFajWdOubGHCD6I1/MRhg27RqzcF/962zEyz9W1diaDS XNRgpIIYq0Yr1VW0QmUu9R27594sC5TEyrKW+2ILgsxUg3vqI6wQmESeUbJ/GnwLDMWZ sCoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710154859; x=1710759659; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S1M9CrsxURK9osAlAJKJLTrbinlvddAx/ivsJ1lbXFE=; b=KJLy5voRhHARoh8HK587PKUpMAo4P7CGGn3+HG+aBdFu37fvn6aSr+7qRPCIAMQu3I H6yh+FGafXht/AFK3Lgx+WDU/I7M+xFSnyY4hLwXB3zyCzdWohMxn83fUlEMfqadTDZo uUqR7wfCMh7zddfSed69II9SRZAsZMNC2nLV/lUU4aFv31TSjzltLCZYPwZ0P+14p3ij oZQQbBlpkD9rikmQMPKc+VM2YRLoi2+dWFa2CS5qrkng5GDUJDS6w1LIbDDdpOTeFQJ+ 6n09M6KO/Rs3V/t4OhDmDdbcwBJDo8sdWh7GMLE/pEQE8bRFAjO7RozgB9bm99h+qB8R sHng== X-Forwarded-Encrypted: i=1; AJvYcCXV8vhHfN9ad80WgEs1p8a8qMim+3vneKbcpQhyx9yFJLrpsg4fPXtajaUpO2HT9+Hf+1pIYeu2aDBorCWH+2edKNA6QCLU+1ggpKz4zb+e6xq9VEo= X-Gm-Message-State: AOJu0Yxxf5mYNrNhJbAMP6mylx7LnemFhcWCcn39LIF/VJjRosSLI8/P ixs0fScvIITX/pO6TRjhjHpG6kFf17oOyN57ZEVGhRTzeb0GW4Vs6QuqMDNVRKbk8VJSAiI5Rvn K X-Google-Smtp-Source: AGHT+IFwCGdoVdTpdQaznB2idQvFXubh9UWyyPMuumHmhiYMoRkMnvTiGe/Fhx2f7ORUyE/itJx+5g== X-Received: by 2002:a05:6512:ea2:b0:513:b0d4:da40 with SMTP id bi34-20020a0565120ea200b00513b0d4da40mr706289lfb.20.1710154857841; Mon, 11 Mar 2024 04:00:57 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id eo5-20020a056512480500b00513179f6c22sm1045933lfb.96.2024.03.11.04.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 04:00:57 -0700 (PDT) Date: Mon, 11 Mar 2024 14:00:53 +0300 From: Dan Carpenter To: Linus Walleij Cc: Bartosz Golaszewski , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240311_040109_132791_786ABE3D X-CRM114-Status: GOOD ( 11.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using BUG_ON() is discouraged and also the check wasn't done early enough to prevent an out of bounds access. Check earlier and return an error instead of calling BUG(). Signed-off-by: Dan Carpenter --- drivers/gpio/gpio-nomadik.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c index 463a765620dc..5e2f9b51ece3 100644 --- a/drivers/gpio/gpio-nomadik.c +++ b/drivers/gpio/gpio-nomadik.c @@ -533,6 +533,11 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode, } #ifdef CONFIG_PINCTRL_NOMADIK + if (id >= ARRAY_SIZE(nmk_gpio_chips)) { + dev_err(dev, "populate: invalid id: %u\n", id); + platform_device_put(gpio_pdev); + return ERR_PTR(-EINVAL); + } /* Already populated? */ nmk_chip = nmk_gpio_chips[id]; if (nmk_chip) { @@ -606,7 +611,6 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode, } #ifdef CONFIG_PINCTRL_NOMADIK - BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips)); nmk_gpio_chips[id] = nmk_chip; #endif return nmk_chip;