From patchwork Wed Feb 7 12:04:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 13548385 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 4141BC4828F for ; Wed, 7 Feb 2024 12:05:14 +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=px0ypbO1skfuA6/20m5t7LaxR4ipzw/MSgbD3hzcjKc=; b=VM994YPiL6Lapt 4JQEuS1ALS9Kv3rXdj/w3kHfNn9LQmpUQUSNIbnk4Rzn1APXX99jKpoCg8DAF9o8ZLZNkoUhLMVc0 KJa9xQJ/YKvwYWE0yZLGySuMmzhtsDSC7ptRV3yzCm738bh52y6/62w+r3x0ilSQmidFK1EUawhjR 9aykqtnjcB8jNffeJCuFIgiVMNqN7IXZcB+XRp5WkN+jJvzy4HBk62c+Sa5LjzHVRSygpfMky2/zf Svxx4fuPkjWGJhx2Ze5BQCpXanudjpmAf52sXFruZvh6aUvPH2kfI0xw5VtaFVeL5mWuLLBlQiri7 6YP+GrDit/PrDaTp9bUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXgfo-0000000AZQ0-0d7m; Wed, 07 Feb 2024 12:05:04 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXgfU-0000000AZAA-2WPJ for linux-arm-kernel@lists.infradead.org; Wed, 07 Feb 2024 12:04:45 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5101cd91017so678456e87.2 for ; Wed, 07 Feb 2024 04:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707307482; x=1707912282; 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=9Bzl1XVd4VG7OC9yiL2j94dw6vCN8qDUED8GxJICOsA=; b=LfdL9sL4SDKQ//sDo4Q30tWz5poTcBrNyBL6Y0ITHbX8D7lD8ErW+NV5+by7nDdVuH nsw/l4tCD+klZimP7zva2MbiM3b1qrvXuabwcRYA0PZpCeuenDN2/236K1L5UjnTP/Sr 4Gr46g9v25dHkfg0uRbFAgBccpYujNi2OnAPXJ3rsFWUcGMiZlOAss3n6M/Vk/VWfWof 3CYRgTqyN3Tx+ZbC2S05XHu3piF//z9Y+jlF9iy7QQEZnZ4YTYSU6fvD1QXKYhzCO77y zge7IWaEfk3FSDGAqtG+S3Z1LcOvDn09I6Hi/EEs2dO9A+x0+2KbRisC9NrmOAkBHRA+ aGww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707307482; x=1707912282; 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=9Bzl1XVd4VG7OC9yiL2j94dw6vCN8qDUED8GxJICOsA=; b=ixp8q+FtHrDtH5/87yombEVlSoF77ZfYvx5z+52Ss2FGNzZH2D/jHdLOcP6c0I116p 0TwxZ7mnKxBOrwCzCQLyUiIvr5L+YqDgvil1GVZPktIYfMdnW9Nvw0C8um4Or1Ro60Bl E7xCedR/qG668hJ3QG8G2RvltT8sRDaSyWsENWiJgxa/sSQmRi3LsA3BF7U1yEg96FJJ yd3uchn9Lejzr+02ZIzOPfpnDE2naosAXLXCTfQx6mhL6dA2ETXVhsBFvh8I2VirCKyl ftTWye5m985Qz6ZuIbqNPL7UsBrW0zdKA1sFG1VaTlq2iNq0HekxWgR0ngnZ8fJBp/pH eVIQ== X-Forwarded-Encrypted: i=1; AJvYcCW5BVrYiHUjmWzlsntvcY+CbuBRmVaprOQ5/uycVC4oh/Ej0EyJeENvufI7jrfschS6sNW5P1U50vdTF/eztQgItTbBhP8CGeXpoypL8FdYGnKyJjQ= X-Gm-Message-State: AOJu0Yw12PZGXFDL8W2yLeCihcJtIL/VJmfXfUpwpl5UeryNNaYxYnWS OK27ttxcKt/jottOxlbyUh6Ta37sfL61gtf+7c7knPp9PXxv88emYpebMEPRFAk= X-Google-Smtp-Source: AGHT+IGcck/xmUicyK/uSuRdySCd6lMKVJAEjrg4NVjjnDTt9057DOq1RhPNTzrfhuYWeIgmMq9WnA== X-Received: by 2002:a05:6512:31c7:b0:511:4e64:fe09 with SMTP id j7-20020a05651231c700b005114e64fe09mr4393588lfe.43.1707307481710; Wed, 07 Feb 2024 04:04:41 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUQv6Y3rp8ha8/1pYWIrhm+SSEwXtyTCHxObJ+7Ec7urGBGiCErba4U9qGVl0fQMRgdootm7T/BpCm8MPhq9X3a1QZ2sw4/eiosfzFJsXtPDeLqGwIPX2yskvLe2RtPMU7yi/h+PWaU7yVpqnIIyBwGnOgrEYlXe9De1jQ/vWs6raG/hjYtUeofYZ4BQ2pY9Ks3MwWtmU976uew+KP7gBsqzCk1DuXFUlo60/csbqywTZcB7vBeJ2s8YXn0g8nIfphWKpuqkkbiI4UlK7D/A2TJX1KgsnaFpnGue9dXTTrLTRGX0Rt5LeQ5p1MMX7mbttA81TfmAsq8neWBmTI09soUUih5hy/fZWx8xN3N6y2vbCXQZ9ZGCbi8sofdpmry0WflT+B6QLaw250aN0bLXZTGjzdu6uYboFTjuTH5GJFrZ0ZsBA/ScVlfzAJnNpF4r/OF6RoRgbpbchVl/u4syxaWTf2Z3MWkjAadY3Z+xUVwoFpcRsjgm+z9t5T+VQ== Received: from ta2.c.googlers.com.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id d15-20020a5d644f000000b0033b44a349e1sm1349967wrw.38.2024.02.07.04.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 04:04:40 -0800 (PST) From: Tudor Ambarus To: broonie@kernel.org, andi.shyti@kernel.org, semen.protsenko@linaro.org Cc: krzysztof.kozlowski@linaro.org, alim.akhtar@samsung.com, linux-spi@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, andre.draszik@linaro.org, peter.griffin@linaro.org, kernel-team@android.com, willmcvicker@google.com, Tudor Ambarus Subject: [PATCH v5 05/17] spi: s3c64xx: avoid possible negative array index Date: Wed, 7 Feb 2024 12:04:19 +0000 Message-ID: <20240207120431.2766269-6-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240207120431.2766269-1-tudor.ambarus@linaro.org> References: <20240207120431.2766269-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-20240207_040444_670599_9799DA0B X-CRM114-Status: GOOD ( 11.22 ) 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. Reviewed-by: Sam Protsenko Reviewed-by: Peter Griffin Signed-off-by: Tudor Ambarus --- 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 0a30d034e288..dfe78ddfa233 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1228,6 +1228,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; }