From patchwork Fri Jun 20 12:02:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 32264 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f200.google.com (mail-yk0-f200.google.com [209.85.160.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE4EC203C2 for ; Fri, 20 Jun 2014 12:03:21 +0000 (UTC) Received: by mail-yk0-f200.google.com with SMTP id 20sf7937730yks.7 for ; Fri, 20 Jun 2014 05:03:21 -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=JOoibFIor9VI/kaeZDQ9SplOVT9GI13quc1XDv5zmak=; b=dG42ptvLgPX0iHhoHX8wG72iRMkP6sBtPicgRjPw6H9ZOSfpVUr3zY1E7EekWdZTga 1bTEKBebAwguAL9faQh0AH9dQDimaFcWLOFNi4m0nKbinbb9MO6S1yuOidiw9WG14cp4 cqnNaDW9p2w6nTQd6dyFvrgQtRZ0BIAw1E4OeUkcPFYLIdvqIGhLYjhuqgwxW+U9vEiu yqOzeJS8yn9wlO8GOPfVZLV0oDIg7SfEkz2qQlCGGQmIEAM+QBdVoorbBMtoAgxJyIYa 75o1Ez8xRQ6aKPnIwzFVtczs7XnsLxj2h2/57/ToE0R+4nsxymQcgLKSoViSjBXkWUzK PL9g== X-Gm-Message-State: ALoCoQnGY2nII16FTyphkhccMG1ixuJVWLuoWY0B+bkvNF/RZoydQBioHYVVMORXp+FNJv8VNvuP X-Received: by 10.236.67.103 with SMTP id i67mr1023244yhd.56.1403265801766; Fri, 20 Jun 2014 05:03:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.202 with SMTP id j68ls924608qgj.28.gmail; Fri, 20 Jun 2014 05:03:21 -0700 (PDT) X-Received: by 10.58.29.164 with SMTP id l4mr2647785veh.8.1403265801679; Fri, 20 Jun 2014 05:03:21 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id zy2si3855152vdb.95.2014.06.20.05.03.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 05:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id i13so3430913veh.8 for ; Fri, 20 Jun 2014 05:03:21 -0700 (PDT) X-Received: by 10.220.59.65 with SMTP id k1mr2591030vch.22.1403265801601; Fri, 20 Jun 2014 05:03:21 -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.221.37.5 with SMTP id tc5csp16581vcb; Fri, 20 Jun 2014 05:03:21 -0700 (PDT) X-Received: by 10.50.67.65 with SMTP id l1mr2640802igt.30.1403265800769; Fri, 20 Jun 2014 05:03:20 -0700 (PDT) Received: from mail-ig0-f179.google.com (mail-ig0-f179.google.com [209.85.213.179]) by mx.google.com with ESMTPS id x3si2470499igl.24.2014.06.20.05.03.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 05:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.213.179 as permitted sender) client-ip=209.85.213.179; Received: by mail-ig0-f179.google.com with SMTP id uq10so428566igb.0 for ; Fri, 20 Jun 2014 05:03:20 -0700 (PDT) X-Received: by 10.50.67.65 with SMTP id l1mr2640766igt.30.1403265800534; Fri, 20 Jun 2014 05:03:20 -0700 (PDT) Received: from localhost.localdomain (host109-148-235-194.range109-148.btcentralplus.com. [109.148.235.194]) by mx.google.com with ESMTPSA id qn5sm3890078igb.7.2014.06.20.05.03.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 05:03:20 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: wsa@the-dreams.de, grant.likely@linaro.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linus.walleij@linaro.org, Lee Jones Subject: [PATCH 2/9] i2c: Add pointer dereference protection to i2c_match_id() Date: Fri, 20 Jun 2014 13:02:26 +0100 Message-Id: <1403265753-25851-4-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1403265753-25851-1-git-send-email-lee.jones@linaro.org> References: <1403265753-25851-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.128.177 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 checks in i2c_device_match(). This patch paves the way for other, similar code trimming. Acked-by: Grant Likely Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7c7f4b8..d3802dc 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -82,6 +82,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 && client)) + return NULL; + while (id->name[0]) { if (strcmp(client->name, id->name) == 0) return id; @@ -95,8 +98,6 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; - if (!client) - return 0; /* Attempt an OF style match */ if (of_driver_match_device(dev, drv)) @@ -107,9 +108,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; }