From patchwork Fri Jun 6 15:52:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31492 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 515B6202DA for ; Fri, 6 Jun 2014 15:52:51 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id l4sf3373357lbv.9 for ; Fri, 06 Jun 2014 08:52:49 -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=J5ocrF5Y76ARcMn6iub0W4czSASElUQjgQufi5MFMMQ7z8OaUsHiuud2Np1+NWA1j8 j3JKtkEsAxX7l1s/5mMps/Vi1i6yEE91KNMigmJ10HX/dyMA6eyBDxIISv4Y+90BuRW4 A24U6w2XHsBYpHNRT/pf5W63dQcJu9J2+wHf4/Uxt7Umka/kxYYAUe0BPfC7TdZ738Ut l6edA/EanwQ30XCxqmPtYfge8DnwReo/qxhgdnE91f07KguKjS5BIzfhZPsd+BzOUKq4 /CoDkKlVAeKUvTZGiu0dOnOHQ9X26RHHTjTZ8fT3o3ApNsK1VtH23MDW0lvYgVZt/FoP rsMQ== X-Gm-Message-State: ALoCoQmtYaNsviBsDoUihz9kENvoOd5duz2x7p82oAnkx6QXiIAmt6QZwsIrQ4bekJ8lA73dsN95 X-Received: by 10.180.188.73 with SMTP id fy9mr1103599wic.0.1402069969932; Fri, 06 Jun 2014 08:52:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.98 with SMTP id d89ls736391qgf.57.gmail; Fri, 06 Jun 2014 08:52:49 -0700 (PDT) X-Received: by 10.52.15.233 with SMTP id a9mr4725525vdd.93.1402069969759; Fri, 06 Jun 2014 08:52:49 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id a11si5424710vcf.3.2014.06.06.08.52.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id db11so3443154veb.1 for ; Fri, 06 Jun 2014 08:52:49 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr6633011vcb.18.1402069969671; Fri, 06 Jun 2014 08:52:49 -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 vs6csp115242vcb; Fri, 6 Jun 2014 08:52:49 -0700 (PDT) X-Received: by 10.42.25.210 with SMTP id b18mr7052918icc.74.1402069968917; Fri, 06 Jun 2014 08:52:48 -0700 (PDT) Received: from mail-ig0-f169.google.com (mail-ig0-f169.google.com [209.85.213.169]) by mx.google.com with ESMTPS id ie9si9408659icb.72.2014.06.06.08.52.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.213.169 as permitted sender) client-ip=209.85.213.169; Received: by mail-ig0-f169.google.com with SMTP id a13so1052521igq.2 for ; Fri, 06 Jun 2014 08:52:48 -0700 (PDT) X-Received: by 10.43.75.2 with SMTP id yy2mr7565780icb.54.1402069968626; Fri, 06 Jun 2014 08:52:48 -0700 (PDT) Received: from localhost.localdomain (host86-181-29-77.range86-181.btcentralplus.com. [86.181.29.77]) by mx.google.com with ESMTPSA id j1sm27388094ige.0.2014.06.06.08.52.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:48 -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, linus.walleij@linaro.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, Lee Jones Subject: [PATCH 1/9] i2c: Add pointer dereference protection to i2c_match_id() Date: Fri, 6 Jun 2014 16:52:24 +0100 Message-Id: <1402069952-28022-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402069952-28022-1-git-send-email-lee.jones@linaro.org> References: <1402069952-28022-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.170 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; }