From patchwork Thu Jan 25 14:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 13530984 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 8E9D5C47DDF for ; Thu, 25 Jan 2024 14:50:52 +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:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oSBWUGoShsurpX4UkqPcjqp2QW3rqDgE9oiujgavUQk=; b=Fg0hj+Dfva7RBy raKfnnn5Etnw0fO/rzArbDKr6U2+WabT8fDQEFQY7R07zYhDxHhbOTsbTUuJ+ZEpJTJhrAVw2aBeL wLwitg/7snMd63x9qLdvxXxQIm/vYNt/XtxiLEIuZepK1lXfTg6/4yeB8FqrBUjXq4NSqo8nJ+oI5 NM9PZKbsuvsqNfpYLINsDQLYuuO/MND7nSHe/xtSGqfytA6k2PeCmfNCinRhrpTNR4k2WGEEY5Z0u RGf9gEIfuu0bxqv5UYni5uEKUnNQWjplwMdhh1sHMQRXLRx3ljZDFu+BWF3cwE5geFwcxmF4d2W0o n2q6F35AuJyjeg8b9kHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT13x-00000000SCp-1bGd; Thu, 25 Jan 2024 14:50:41 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT13X-00000000Rt7-1UeU for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 14:50:17 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40e8d3b29f2so80029195e9.1 for ; Thu, 25 Jan 2024 06:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706194213; x=1706799013; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yRFUn44quLj+PIfBqhHItZqwl4f97FWUBTKk7RiZwVk=; b=KuNoaHrvPj28iwo0LuHiPvouGkWYvbaA0wfBppY5SI2IpHhQwePkdxbyRIQQHonLOw JMKD3Z2zCd8z1pcijGxqXwBF0nxKrwcbL2SSzWenItQQaBnZYQrDQJShZ8YQuT0l3DE4 3oWCmw2/4SZzGzyv+Eq8n757dQXqWzu4I+3DBqhhlg1fmiOxIYcmID7soHGacZTn2Vmz rN8Q/jVfZ18C5cC8H+9lbQByslPxfoWsy2g0RCWm7n9STE02+NZv72l6zT/ZMsuSM7AX I1ThWbRAcA7vUi1bLaKaVu6q1Q/AqAI/xqZ0Oo/86MhvikcfYO6JKWFAlTBAddP2WIHp BA7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706194213; x=1706799013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yRFUn44quLj+PIfBqhHItZqwl4f97FWUBTKk7RiZwVk=; b=W80/TJWZOo8buaomruXY4pCZyIVi3EQ7O0BJG8u6AJOD3FBwJgpAKxEv43b5VOtFuy SphOuxnvtqyxgomojxU4WAMrhUT5Enva07JWpxqEZnHkLXp7Lfibr5wNCVFz5KWqcNwG WstJ93h3/XZ1Fj15rceHIZ5Fz9kEdnvfaj79vFvpK04PuWJUvxSMBWSxIb0OJQdBcpBh mT+NT2LhVBBlS7/l3DpBhnAtc7iCPPboAztQdriqqs6xAUVQoT1FvSKqOykJ9392lLXC iAQS0tRWAVgLDGMP+MSgMhCL5pusKUd/gdq960mdmjIcc6RubDiL0zKQAiRQisnvOLB9 ZMFg== X-Gm-Message-State: AOJu0Yzus0+6YX6vwY16o3I3mEZeEITXFi6qk2y/FdiaoIBxhlN3VZi2 H9n88+ziljZu+q8g07Kw8EDQbR5DV3fD+bH+T9nC0KjYEnvJ45cpnCkVS0JxJP8= X-Google-Smtp-Source: AGHT+IFOgajdcjx12foem5jJQ5uVJoa8Xt7GnwMZgRpKmkxOeOk40qisvSZ27ix7km3lnNNA6G3wyw== X-Received: by 2002:a05:600c:cc7:b0:40e:d2bf:5b03 with SMTP id fk7-20020a05600c0cc700b0040ed2bf5b03mr271370wmb.82.1706194213512; Thu, 25 Jan 2024 06:50:13 -0800 (PST) Received: from ta2.c.googlers.com.com (88.140.78.34.bc.googleusercontent.com. [34.78.140.88]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b0040d91fa270fsm2875875wmo.36.2024.01.25.06.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 06:50:12 -0800 (PST) From: Tudor Ambarus To: broonie@kernel.org, andi.shyti@kernel.org, arnd@arndb.de Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, alim.akhtar@samsung.com, linux-spi@vger.kernel.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, andre.draszik@linaro.org, peter.griffin@linaro.org, semen.protsenko@linaro.org, kernel-team@android.com, willmcvicker@google.com, Tudor Ambarus Subject: [PATCH v2 03/28] spi: s3c64xx: avoid possible negative array index Date: Thu, 25 Jan 2024 14:49:41 +0000 Message-ID: <20240125145007.748295-4-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240125145007.748295-1-tudor.ambarus@linaro.org> References: <20240125145007.748295-1-tudor.ambarus@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_065015_578507_43A9B95A X-CRM114-Status: GOOD ( 11.67 ) 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 The platform id is used as an index into the fifo_lvl_mask array. Platforms can come with a negative device ID, PLATFORM_DEVID_NONE (-1), thus we risked a negative array index. Catch such cases and fail to probe. Fixes: 2b90807549e5 ("spi: s3c64xx: add device tree support") Signed-off-by: Tudor Ambarus Reviewed-by: Sam Protsenko --- drivers/spi/spi-s3c64xx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 2b5bb7604526..c3176a510643 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1189,6 +1189,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) "Failed to get alias id\n"); sdd->port_id = ret; } else { + if (pdev->id < 0) + return dev_err_probe(&pdev->dev, -EINVAL, + "Negative platform ID is not allowed\n"); sdd->port_id = pdev->id; }