Message ID | 20180325110747.8852-4-ard.biesheuvel@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org> Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD185605BD for <patchwork-linux-arm@patchwork.kernel.org>; Sun, 25 Mar 2018 22:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B48992934E for <patchwork-linux-arm@patchwork.kernel.org>; Sun, 25 Mar 2018 22:26:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8F5E29352; Sun, 25 Mar 2018 22:26:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A4012934E for <patchwork-linux-arm@patchwork.kernel.org>; Sun, 25 Mar 2018 22:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5VknqQq3BulvLrt6YkDJ8ehgJ3yYghMNp8hMEvdiP3g=; b=ICcU8YPjp2rJgrUGSPiA9ObqxG aq4B/ReiEDyxdKejmJMw0rbK/wwJufDjEEnNUSGc2J0w93lu9F9OujBeDM3rQC/Kv7VgOFAkByqJV GuMlIx/D9gMO2TW9wIY3xl56HgDxg4GoHa/M5zIxDX/zZ1yA7eEkX0/KD8bj2/X0eWNVUv4m1trSi rJFI3bGFiKDUFxAS/7vX93BK9WYcZKw6knnnngP3Iz8+2XEdGmd6FjmUKauKKgrHZtt3BRE1L603w aPRDkVUu559IGop9mqa05J2NW6Z8hR07ob9dhggv4f//KANmqH//GGCUIERWyPIb3O6sGv/MHM2+l +n4PJrsQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0E5K-0001Sr-NH; Sun, 25 Mar 2018 22:25:54 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f0Dqe-0002Hq-75 for linux-arm-kernel@bombadil.infradead.org; Sun, 25 Mar 2018 22:10:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kGj4/oEIkuazlnX5YejmpjLpijkWPrArUlhRaD8hL8M=; b=RprFAnzz7nStd0a4AqtvlE5a/ DqoZAJ0EGVbIUxTLb1qaPZANHZs6CMGz8zIRwLpHhQzNFcR/gjTrS8P0IAzWv3kP+DCzrh6Gwd1rJ YZVF7pE81K9cnPmjrYdMbQHLeDpb8qdqmBM6mRbEuaJxtYIWE4AIgQ4ohe1VWOORTBAJB0+0tbwgj MPN1Y9T6qOojx+nxlIl0RWpRfLN4tNL051woiqmjcA0hpBZ3QvlFw0fSMMN2cg4yW2aQL2ZS79s4A lz8tnLKapjoMHWoL6hctVkTmegtmD2BOWPhLuXlQef8X0rBi2pstxpcl5y7CdJBR/KEw5/OWzGDIx EnH1tj4fQ==; Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f03XW-0000xA-UV for linux-arm-kernel@lists.infradead.org; Sun, 25 Mar 2018 11:10:20 +0000 Received: by mail-wr0-x241.google.com with SMTP id u46so16103782wrc.11 for <linux-arm-kernel@lists.infradead.org>; Sun, 25 Mar 2018 04:10:08 -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=XwtL6rxV725ewxACNZQIpGufOZE0SbxHm1QzQeuQRxdGCUoZjuY0F6+rjhYCKGuTqy 70LHUeinB61CYEB4rM05y+M38aZvBoXW60eNlw1lm4uL0gzcf6lXgB+tbIlgTSwUEy6I 0KPbqclcBuINujTBDOflDkwxWSLCfqG410Cv2tSvrMgHuH4+ArVzmX6kux1x5e0QRTmL 0l31KvBq+aXqLYLLlYlNV7oGX3BnBpfwGT94sxL+m6EJAjlm1//AVe8lrb2+9w7Cv4yv cDK8npQAs9sqOtzYwRI5pkJOt6Op0nFCRcpmAQYqCpreV5gHVLnyRl5PJMgL4v/nvkrd vGvw== X-Gm-Message-State: AElRT7FIHZJruAAdUbim70A+9dQAyaGArewpiYM9fFEYzjLMoinY+Aj4 gacMS25h3P3I/tb9sahX1ijpXQ== X-Google-Smtp-Source: AG47ELswBSPvhBFJODvkcJHAWqdsinrQ0Z0/LsXJogSGqFTJ7s50I6jrvowZitjAr8/nYo7oOJvffw== 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 <ard.biesheuvel@linaro.org> To: wsa@the-dreams.de 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180325_121018_992481_63E702E9 X-CRM114-Status: GOOD ( 11.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <linux-arm-kernel.lists.infradead.org> List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe> List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/> List-Post: <mailto:linux-arm-kernel@lists.infradead.org> List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help> List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe> Cc: andy.shevchenko@gmail.com, jassisinghbrar@gmail.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel <ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org> Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP |
> + if (!msgs || num < 1) > + return -EINVAL; I think this case justifies WARN (or WARN_ON, I always mix them up).
On 3 April 2018 at 17:03, Wolfram Sang <wsa@the-dreams.de> wrote: >> + if (!msgs || num < 1) >> + return -EINVAL; > > I think this case justifies WARN (or WARN_ON, I always mix them up). > OK.
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;
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 <ard.biesheuvel@linaro.org> --- drivers/i2c/i2c-core-base.c | 3 +++ 1 file changed, 3 insertions(+)