From patchwork Sun Mar 25 11:07:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 132389 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2668896ljb; Sun, 25 Mar 2018 04:08:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELvygi/9DChNL1B5XgC+mAp3OcmH72MIUF/UIoo6WFz8WbcnfbePm5Di4Om8nOkfJfmcZWCW X-Received: by 2002:a17:902:a607:: with SMTP id u7-v6mr36156661plq.367.1521976091241; Sun, 25 Mar 2018 04:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521976091; cv=none; d=google.com; s=arc-20160816; b=08065x47+LdrioxfFqbV6uE/aPjfTVop/2nuW9za14edX/tOydETBi/Av4F8U4cq2o gdp0csIX8TYrJDTM8S0k3EvzwseifD8EeGSe0cKlNM3WJWdWF+VRo5Xpqs7NYmp9FEsn qjqcqO5GvRaT1crdbxcMbQBad/AJO21YjRCeAj+JdmoACJgCB6bFRzSVj9ALQDBx7Z/G Mjn3qU9JcQh3W3TKJHprBgUPHes3MAqdRPcSrgsb+KxJMLV6DcDjSqZPnZjlGFZud9cN fGBERXpF+OU/bv4TRncApQtKOw/a30byWy+bw9OKUDFgEMVNTEDJvFsMkQya22EGXoli zATQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=kGj4/oEIkuazlnX5YejmpjLpijkWPrArUlhRaD8hL8M=; b=jwzBlW1YP7FOh2R6etYfZNPBZY2T6Q5ubslshasyX4PsxS/Bct2LGUYGCf26CD3NB+ x93ihHoVoHxSLtSWWcdSYv6FsN0qLysIUdwYqIS77b+k50EB4wwItiv3eE9VxNUZ6Xo8 niFVRz8A+xBLdXKf/7VYoxkeRgcT0gR7DvkNs8z85+PDaGELXKLIVoLXwFTrVRX5cMRv LprhrbmKw8PiTA6pRdDbh7DDBGCF+niz5l7zTDJEXFnAkxj98WTaUEhX+iNr9bW249LG 0pVdvfGHtQwy2rpHuSiE39zWiO/ak0SBrFBWvxQKahojujYJhxwSfBfl1bxKbx9jAF80 gDtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aVS1m1Hv; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8-v6si13805808pli.445.2018.03.25.04.08.11; Sun, 25 Mar 2018 04:08:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aVS1m1Hv; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751985AbeCYLIK (ORCPT + 3 others); Sun, 25 Mar 2018 07:08:10 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43080 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752004AbeCYLIJ (ORCPT ); Sun, 25 Mar 2018 07:08:09 -0400 Received: by mail-wr0-f193.google.com with SMTP id p53so8594720wrc.10 for ; Sun, 25 Mar 2018 04:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kGj4/oEIkuazlnX5YejmpjLpijkWPrArUlhRaD8hL8M=; b=aVS1m1HvdwAyXXpBXPHaDt7Zy/ahJNgOD7qVmasaxKFGzGN+Jaw5Bl+/ZSPeTd5RRE 10E3rW0yTnzuArUbLHD2QJuUgc5NDyE0qphVvrwdh/7J9zLNAs3uD1fFBB8UNarT5fXn xTj6biBHJZdpYYdrwqwhWJt3aCmRkWeS1OB3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kGj4/oEIkuazlnX5YejmpjLpijkWPrArUlhRaD8hL8M=; b=Bv1EZV4WMlQ0U+KsjlxhgsAxOSMSBnR2O7DejAfu01gEhpstvNf7l5LDPNssoovodQ v61actv8J80Gk/Zn3V4TBSXrMzeoQSn9F0yiqIcx5kE/hxjcYv78dKJV/XtaFk5DmeGX 21p8pWMnA6k8eTWGHgtjrS8656fRM33rcTEK5p2A9hEGwOGHxBviiJ31oiZnV+iksGuE 4Ug6FELWYOugdPhjXyGSblCmO24P0AMBMbO/H31TuFVHMhxUXqYqewjNisfbFWWmcE8q POwV64BAR+ntCtsYSR3fJJs1mZlqnA3VTo7YT753qMJeAzQCiLsQKb+k+V8uIFX0LRzv +2bA== X-Gm-Message-State: AElRT7GFKyhZXVrppKKTLu6G6/ltupAV0JBnylZo4DJ6Q9oGe4S9RT5p etq0ud6q1mevutBVJmwD/YhsdGE5HhI= X-Received: by 10.223.158.6 with SMTP id u6mr17730554wre.142.1521976088440; Sun, 25 Mar 2018 04:08:08 -0700 (PDT) Received: from localhost.localdomain ([160.105.205.136]) by smtp.gmail.com with ESMTPSA id w134sm14354298wmd.45.2018.03.25.04.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Mar 2018 04:08:07 -0700 (PDT) From: Ard Biesheuvel To: wsa@the-dreams.de Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jassisinghbrar@gmail.com, andy.shevchenko@gmail.com, Ard Biesheuvel Subject: [PATCH v6 3/3] i2c: add param sanity check to i2c_transfer() Date: Sun, 25 Mar 2018 12:07:47 +0100 Message-Id: <20180325110747.8852-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180325110747.8852-1-ard.biesheuvel@linaro.org> References: <20180325110747.8852-1-ard.biesheuvel@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The API docs describe i2c_transfer() as taking a pointer to an array of i2c_msg containing at least 1 entry, but leaves it to the individual drivers to sanity check the msgs and num parameters. Let's do this in core code instead. Signed-off-by: Ard Biesheuvel --- drivers/i2c/i2c-core-base.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.15.1 diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index c8bfe008f208..dfc549cf0ac2 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1845,6 +1845,9 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) unsigned long orig_jiffies; int ret, try; + if (!msgs || num < 1) + return -EINVAL; + if (adap->quirks && i2c_check_for_quirks(adap, msgs, num)) return -EOPNOTSUPP;