From patchwork Wed Jun 4 12:09:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31347 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 58CF2203AC for ; Wed, 4 Jun 2014 12:10:18 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf21135482pdj.0 for ; Wed, 04 Jun 2014 05:10:17 -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=Fra16tNfazTWc9Qloj2JvxF6SzGjcodxlMxRAnr8o/M=; b=Sm+4bvwcSRjKNIqFhqTcStx4pgzJ5mw2wW/w3c0vq8nkHw1B+ILHTO8ElpKzJ0ZKIq ZjCvup9V+RalwKDDE/2EH9Rrwgev1qjc27B2ntH0K2Cbu4n3xxmhNtJDNVd5y6Ayw1nj qNjamwZZeRlcGMkRd8PZqsTZVdfiunDMqldWpzxL5+I9Fn8uFXjf8Lpw/JwXXehy4z5o 7bGQrWEmlqA5lVwjOMllPM6FVd9DSe9lHjer8lkVsMPguj9b8VaTraITVRCHEtB21fnE Nw/i9WzU8Cyv+1vFTA4hhhKxlzJNPcIGDcNLGIOwroV2Ry50t4q7R9jhpuOQePndrrgS Aogw== X-Gm-Message-State: ALoCoQlIFeItSrzW+kHhDLPWKP3PgTD+/0SVL4wMv/BeIpp1tvjzOky6xjfMOGBOhMqujrOalsln X-Received: by 10.68.230.193 with SMTP id ta1mr20033450pbc.6.1401883817355; Wed, 04 Jun 2014 05:10:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls3104891qgf.48.gmail; Wed, 04 Jun 2014 05:10:17 -0700 (PDT) X-Received: by 10.58.94.232 with SMTP id df8mr513247veb.72.1401883817231; Wed, 04 Jun 2014 05:10:17 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id q13si109669vci.29.2014.06.04.05.10.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.176 as permitted sender) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id jz11so8518787veb.7 for ; Wed, 04 Jun 2014 05:10:17 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr42682579vcb.0.1401883817106; Wed, 04 Jun 2014 05:10:17 -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.54.6 with SMTP id vs6csp39868vcb; Wed, 4 Jun 2014 05:10:16 -0700 (PDT) X-Received: by 10.50.1.111 with SMTP id 15mr6500272igl.7.1401883816482; Wed, 04 Jun 2014 05:10:16 -0700 (PDT) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by mx.google.com with ESMTPS id tr4si29520092igb.7.2014.06.04.05.10.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.223.180 as permitted sender) client-ip=209.85.223.180; Received: by mail-ie0-f180.google.com with SMTP id tp5so7187972ieb.11 for ; Wed, 04 Jun 2014 05:10:16 -0700 (PDT) X-Received: by 10.51.17.97 with SMTP id gd1mr6709893igd.18.1401883816185; Wed, 04 Jun 2014 05:10:16 -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 on9sm10028136igb.11.2014.06.04.05.10.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:15 -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/7] i2c: Add pointer dereference protection to i2c_match_id() Date: Wed, 4 Jun 2014 13:09:51 +0100 Message-Id: <1401883796-17841-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401883796-17841-1-git-send-email-lee.jones@linaro.org> References: <1401883796-17841-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.176 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 --- 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; }