From patchwork Tue Apr 3 19:11:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10321691 Return-Path: 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 5F63C602C8 for ; Tue, 3 Apr 2018 19:12:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B926E26220 for ; Tue, 3 Apr 2018 19:12:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD50327D16; Tue, 3 Apr 2018 19:12:52 +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 28DFC26220 for ; Tue, 3 Apr 2018 19:12:52 +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=k2KtuLwrqf+a3r9WUKc6qLg7lG08JHw/scyz7luRyK8=; b=U3OVia0Cu8BlMSaNNz1v+uLtnZ UX7FSUlNZMJhKrFUB/KyP6X5qNxVqEagwdBEnbsAfaCtGeiHh/68ChuBXjA/9+ojxoVxkRlf/XTjm aZ+FaS6LFf14lUTT7xbQY3rsFMcQgIJQfY0JB0fY+uVEBXl9b//b7NJd32KYs9WGqqK6Nr3rsbnxp g61aeFv4HI77NoMZ78ogvBMaOdMn017/MI7iFIdmnnK/2FB0wOnooPVHjlZtxLF41FzcoPF6jYSjD KYm8ZbO2Z1Zrr2soJrRGPH0fYWQ5Fpa/dDne6tEEHgRlqeXddrhYaW23qIFMN9H4gaxM5dITKizuF vqkdX38g==; 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 1f3RMG-0007HP-2E; Tue, 03 Apr 2018 19:12:40 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3RLm-0006yV-IP for linux-arm-kernel@lists.infradead.org; Tue, 03 Apr 2018 19:12:12 +0000 Received: by mail-wm0-x242.google.com with SMTP id r82so37560568wme.0 for ; Tue, 03 Apr 2018 12:12:06 -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=cIsfmCaG1eTi2Vegv49ijJbnU+PkN09SgF1pSIiomUA=; b=OfFAlDimscehezy0c2MZHiTvPGU4elQt5NgsNg8sEHKA/AtLaqcWlPMa+FwxwbeXdL ymHjyONBS1NFNUY041iF+TW4xU9c4LaRx0AkOHcRF3ETHhEWGTCTGcbrff5jDAEstLAC MDE5/r2zFhA6LSpZ3oFNszixp3gOtFy09w82A= 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=cIsfmCaG1eTi2Vegv49ijJbnU+PkN09SgF1pSIiomUA=; b=CMcKjulINa6a3ylILoj6Tb4md4CXgW1vLvmdAkQ1sgIkk8T/WVuwq2kUZiq4JNP3rJ GYSCCCm2rhBnNvmXzbs7VZvFIEiU6RBJZL0jti8U081cWJPjji6CxFqjTOvE9A8/Chg5 M2NHLbZsWvDwhvkNl6o9O9DdrLl406OR4TspFF2EpRQwxmTdP5q95iOw4nGvCrx8Kt1/ NT77ePAEs+xe2OLf4ModjkUTnGfQC4LKReYbvkSfwITk6QME8px0Um9VtszX7VHqJ5Oc xm0GZOWuvqvhnLKv9Ob5HlWhvG0VhBfwcBtc1MoGChKeajBRRVbAs1sRiLYHBX1/QS+M 3GSw== X-Gm-Message-State: ALQs6tBAR3/QedpZn9qJ/RIq3To3nxOrh+qyeRnHHk1JMg7W2UCAngIA pnyY9WCPpB6j9j+fu/FzfWeUNw== X-Google-Smtp-Source: AIpwx496syprwPFxu+Yvuomfp+9Y2HxiEiSt4c1unxEfWAQquCN5JzBHwGUqh8S4Id7iFkI4V7sq3A== X-Received: by 10.28.21.77 with SMTP id 74mr5431813wmv.76.1522782725466; Tue, 03 Apr 2018 12:12:05 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id y100sm25120682wmh.2.2018.04.03.12.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Apr 2018 12:12:04 -0700 (PDT) From: Ard Biesheuvel To: wsa@the-dreams.de Subject: [PATCH v7 3/4] i2c: add param sanity check to i2c_transfer() Date: Tue, 3 Apr 2018 21:11:50 +0200 Message-Id: <20180403191151.14924-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180403191151.14924-1-ard.biesheuvel@linaro.org> References: <20180403191151.14924-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180403_121210_675628_93048096 X-CRM114-Status: GOOD ( 12.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andy.shevchenko@gmail.com, jassisinghbrar@gmail.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index c8bfe008f208..e2ca5c331ecb 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 (WARN_ON(!msgs || num <= 0)) + return -EINVAL; + if (adap->quirks && i2c_check_for_quirks(adap, msgs, num)) return -EOPNOTSUPP;