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: 894740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="OfFAlDim"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40FzHD3nVTz9s0m for ; Wed, 4 Apr 2018 05:12:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005AbeDCTMH (ORCPT ); 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-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 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(+) 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;