From patchwork Mon Jun 2 13:41:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31286 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 74EB020AE6 for ; Mon, 2 Jun 2014 13:41:24 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id la4sf1884531vcb.11 for ; Mon, 02 Jun 2014 06:41:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=BhayG8OLxm7Dl7xXIujTgSP5AjYCZmbfYlKrKetlgms=; b=mgMOHCuZjKYFjisxD3Eiv4SkEeDmwsC5cL37Pqyk6evipK7KVyo+Vws05PUY3chjkj KDPMmSfbGR1UvJhYhTfUUkCbW691lPnPbH1oGbpbcHtCze2lAnt1iECvaknmlZOm8TnL wfUATEqL3gjdivAm3jqyjL5gOzWsk3UlHDaDIEB63aCYmFKbtEYi1WJuimaZdUiqx0io 9cAf4nzyfJO418h55tGYrBy2Gmf2UU7cCXK9737GWEPvwnOZIwLmCNHh4fCt7wuIcu1D jLEOpB6VXs9r1j9C7LeMihPRtCi0z0jG9ngh52sI6oIIi1eVo3fPosz4VXV4E0WpjoqZ BOnA== X-Gm-Message-State: ALoCoQnYbd757avKW+EitZyIvwIbberRTkWlEmX54s1kp+XTzFdDodxYETTlF1bM/0CX9Tg9Gy3C X-Received: by 10.52.142.72 with SMTP id ru8mr11204483vdb.0.1401716484240; Mon, 02 Jun 2014 06:41:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.247 with SMTP id l110ls1914584qgf.90.gmail; Mon, 02 Jun 2014 06:41:24 -0700 (PDT) X-Received: by 10.220.159.4 with SMTP id h4mr30444520vcx.1.1401716484067; Mon, 02 Jun 2014 06:41:24 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id dj5si7883777vcb.21.2014.06.02.06.41.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id id10so5071014vcb.20 for ; Mon, 02 Jun 2014 06:41:24 -0700 (PDT) X-Received: by 10.58.2.74 with SMTP id 10mr510420ves.61.1401716483997; Mon, 02 Jun 2014 06:41:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp98747vcb; Mon, 2 Jun 2014 06:41:23 -0700 (PDT) X-Received: by 10.50.66.240 with SMTP id i16mr19314712igt.19.1401716483474; Mon, 02 Jun 2014 06:41:23 -0700 (PDT) Received: from mail-ie0-f172.google.com (mail-ie0-f172.google.com [209.85.223.172]) by mx.google.com with ESMTPS id tr4si16286341igb.7.2014.06.02.06.41.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:23 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.223.172 as permitted sender) client-ip=209.85.223.172; Received: by mail-ie0-f172.google.com with SMTP id tp5so4459421ieb.3 for ; Mon, 02 Jun 2014 06:41:23 -0700 (PDT) X-Received: by 10.42.98.73 with SMTP id r9mr2411464icn.87.1401716483222; Mon, 02 Jun 2014 06:41:23 -0700 (PDT) Received: from localhost.localdomain (host109-148-113-200.range109-148.btcentralplus.com. [109.148.113.200]) by mx.google.com with ESMTPSA id hy3sm6561043igb.1.2014.06.02.06.41.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:22 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, wsa@the-dreams.de Cc: linus.walleij@linaro.org, grant.likely@linaro.org, linux-i2c@vger.kernel.org, Lee Jones Subject: [PATCH 2/3] i2c: Add pointer dereference protection to i2c_match_id() Date: Mon, 2 Jun 2014 14:41:02 +0100 Message-Id: <1401716463-23457-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401716463-23457-1-git-send-email-lee.jones@linaro.org> References: <1401716463-23457-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Here we're providing dereference protection for i2c_match_id(), which saves us having to do it each time it's called. We're also stripping out the (now) needless check in i2c_device_match(). This patch paves the way for other, similar code trimming. Signed-off-by: Lee Jones Acked-by: Grant Likely --- drivers/i2c/i2c-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 2e47641..d0c7180 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -83,6 +83,9 @@ void i2c_transfer_trace_unreg(void) static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, const struct i2c_client *client) { + if (!id) + return NULL; + while (id->name[0]) { if (strcmp(client->name, id->name) == 0) return id; @@ -108,9 +111,10 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) return 1; driver = to_i2c_driver(drv); - /* match on an id table if there is one */ - if (driver->id_table) - return i2c_match_id(driver->id_table, client) != NULL; + + /* Finally an I2C match */ + if (i2c_match_id(driver->id_table, client)) + return 1; return 0; }