From patchwork Fri Jan 26 17:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 13532900 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 D1197C47422 for ; Fri, 26 Jan 2024 17:16:16 +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=7k5Il+/vPJ0WOWYTTBzBzvOzOUswFN8aMXrNhkpvqEM=; b=Rb4CmOLAN7vEhJ IUtZIvsKNWVADCcjsXYY3xGVZH4b2jvZcQvhjlwsTvhCLft2e0sRfO4V2avwEq9/q+Z3C7OSYE09R vo4BHF9/Y0aiJyMQPJio8XbS+k05dmpVnRbqABNh23H9ahey0eRzjza45WfEE+gmhtO9rk+UlUW/C Iop/TqI3S7LRLsUcWYGzL1ThpcUpyolBf+dWr8vKN7UU9AhGjFf58HHVtYBYRmyrJhPqr1ARig9X4 4z4/n97bCvK1azYKcW/hGYbxDyCyLy4Nq5b2D6IXyOkWAk+OrS62fDvXldO5CcnDqkDyLY+WABWKw St687OHSSylM5Q3djSOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTPoC-00000004pWN-1Jpw; Fri, 26 Jan 2024 17:16:04 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTPo1-00000004pPD-0V7S for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 17:15:54 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40ee82d040dso5840475e9.3 for ; Fri, 26 Jan 2024 09:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706289352; x=1706894152; 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=qV8ITwl1O57QlGGOA7a30fekUIiUXq0J9XlHzcfvV8M=; b=PSy72d8VBdsUyFWBasmJU/8ff2L/wPNaivt87K16CJBYpSFidsMuyKsuf4SYxiQbEl OZWP6VL9i2SyVMYKQI+CVKu2dtZ8Ykkx0doYFKNnxscoFW6u9JUOISKKh7ZmrFErPne7 ESIcd2eTass6n2/mV0F9O3YcBbfkcM1LfWyZPIkSfEf5t3EGDHI8qgvS5Ns9JOkFuH5b znKfz6kPRksqBhKAIkjbSB+/VjrM7Ec5D8D9pGSABpqnzFH3yc0k1Ts8O8lUOAsgrh5F 99rQnwSRP74oGBZE/Ei2DRLwRaHxJpJCuLsAbsSoR/+0YXxFUN9nYQvkEUNTRLc7ffiI u/+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706289352; x=1706894152; 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=qV8ITwl1O57QlGGOA7a30fekUIiUXq0J9XlHzcfvV8M=; b=QtD4X9vG89DkIpYJs/8MvRB+ULDbcxcuSJ1xSG5PgWmRVqx5ALiPI1D5049bq1CtJw Zj3YoTsbM07o2PLVMfh6VkfkqxatbFzJrvSxHjxaY9Bv0T4qaJsH+7C+k9n7gtDQHrOw lOWL9pPw8+xzDR3KGBKWpLL5ES+KcwABiK7LCXKzbtzI2x1nmw41loiAD7UUH8pfra+c +WzSXjjTrA4gbDYbxGQfbV+QdpZWj3Sp5PhlBXEWF8u20hm463IID41VzjtJTT3/5LbL os4H4k4L6yNY4J7GNQOYP0N7fBj3fibzk85jBrbbQE+d/KsaPFklhW+R5wIrZcOPtQui Rd2g== X-Gm-Message-State: AOJu0Yxqf8nZeqyzycWd8K+LobOb9C35FBRTXXRpKN/D5xq6vb/t1Ga8 ahIvyay/P1BTOKYKpYyzVwJNXsMNwggPWM+yj7qcfFEhMeBmLVlpGzx6o9n4Obc= X-Google-Smtp-Source: AGHT+IEvNW5DbdU8iWYCHzL7THeKzP8fEDzX/ESRePAImO9XzqkTKIuqDrCsNewY4d6xeB03PZgS4Q== X-Received: by 2002:a05:600c:378b:b0:40e:8bb2:6bcf with SMTP id o11-20020a05600c378b00b0040e8bb26bcfmr75031wmr.151.1706289351730; Fri, 26 Jan 2024 09:15:51 -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 k10-20020a05600c1c8a00b0040e451fd602sm6287286wms.33.2024.01.26.09.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 09:15:50 -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, jassi.brar@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 v3 03/17] spi: s3c64xx: avoid possible negative array index Date: Fri, 26 Jan 2024 17:15:31 +0000 Message-ID: <20240126171546.1233172-4-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240126171546.1233172-1-tudor.ambarus@linaro.org> References: <20240126171546.1233172-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-20240126_091553_203666_6F55424B X-CRM114-Status: GOOD ( 11.30 ) 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") Reviewed-by: Sam Protsenko 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 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; }