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: 132783 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4175547ljb; Tue, 3 Apr 2018 12:12:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx48j9PRVAxsGNo6Uvl+PXeM61b0EjG2UKX4thU5XI/rEnjAXCzubucyEHgi1sFsXaBoi2AnU X-Received: by 10.98.60.4 with SMTP id j4mr11453411pfa.229.1522782728162; Tue, 03 Apr 2018 12:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522782728; cv=none; d=google.com; s=arc-20160816; b=RIt0ay/xkVHr1xx/flUwYZrTlyS6zESArJ6PeP/tetridO8co5TG8WU8KnReDu+knv V0WQAoRCEwhNvoSgIW++EsoUktONTLseIvrGWz9VtzLEGZ/0lqDYdd25/BhDYLvdPxRA ljObl1jlJU3+ZE6fCf9FtWAp2UaJ4g+K+/gTHUNhAqn76DHf/fvcBvnFmfT/hGyvvO3A 5gkU1A1Opf4vOAOqR5ZN1KYNiuH98LkosvamL4Xd67aLjigb8UdixuIrjmhAF5V+m3Z4 vnBFcpOL30YT1RbpLttz9rs69b4yCj+q+6V3Pb4oGY8N3k3nCu24tHl8sX4qGPuj+WzP OZ7w== 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=cIsfmCaG1eTi2Vegv49ijJbnU+PkN09SgF1pSIiomUA=; b=PuA9Sh0sAhn0cqmBNFuNfLqAqzHO1RWAaWKjaBwHwnmbL3GCZ8HHK8RLl2jqSYUgsA pcln0ZURljGUGq8wGEMwh7PVPY5HFpzmykAPFd4xxvNi4qPp3kK+1JJRXaYNIHWhLsCC 00IwXWVsg3liFiTIXo/FNNXoXgU+druR2GU2zatyghGCrqrgY8KUUzf3URWr92D3Jntr dxRYhHU99D35DBMzHm597IWqijDyBvvrDZ1wl4Nw3ciZmIxp9GTl13jphE+FOOBYRm2f EKRJ1PVkjZnPsR5GXR+0Nyxr58ZonXPGhM0r2o/wZglXBvab45LjdQgBl/RberWukcQl Lm4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OfFAlDim; 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 s78si2646947pfa.374.2018.04.03.12.12.07; Tue, 03 Apr 2018 12:12:08 -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=OfFAlDim; 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 S1753005AbeDCTMH (ORCPT + 3 others); Tue, 3 Apr 2018 15:12:07 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38156 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753156AbeDCTMG (ORCPT ); Tue, 3 Apr 2018 15:12:06 -0400 Received: by mail-wm0-f65.google.com with SMTP id i3so13446497wmf.3 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=jcByWwpbb/DjhqEOkE/fx0zaLi/diRPHQGJMbZm7TZp1cY4rPdSyQoXBx+tdbH+1KI vmc5sNV1gj30pVRHY5iuVMJc9j5G2b0Q49OuSxmc0dJQbrQ4jIVE+0v6lZGHSEj9g6+s Xqqup0ZiGbPJG23pngWkTi3x4IcYA8NZnSKB5STmuF/lSqQpah4zmpgZ0HwEEij2UZ+a m0S4WEWLlSu+xkGDjEpB5sNXB5Lramcb2LGa18t8TaEiozkbuLb4hg6lC28zbkDhPZy1 zMrztHHm/VDkq5+ZyKsbt6w6E9CqwyTv/7Lg5NGXlkERGDVDfvJTGi4gb7Pg/M98tLGh CbTA== X-Gm-Message-State: ALQs6tBjCgpXDczFpRcAQOh/hJx55DyfPE6F4uCINMz5QQ8VGlxmibbj I278fMabDfj/gDPdxwNvvmuPHA== 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 Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jassisinghbrar@gmail.com, andy.shevchenko@gmail.com, Ard Biesheuvel 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> 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..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;