From patchwork Fri Sep 11 11:55:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 53448 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 551F3215BF for ; Fri, 11 Sep 2015 11:59:56 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf23598169lbb.3 for ; Fri, 11 Sep 2015 04:59:55 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=qHJFm/l5lL9XeAYA8j5W9/3tR5WOrrGHmo7+rIGYh+M=; b=N0MrtQnfufdMPVXgznkO7lyQcy3D1zF3fozuE6LFSk2nTZAX920KLKZIpwawjTBVhk +1xFp7aoSHx3WlJlvcoFKgFy40vs8vBrvVHEeMBOa3ZI/9qRfa+NbuqAHOeUJQFcQ2Fr y2pKPY9OrPStsbHk4WjpCpkIkVLkZbZBnsRveyg31VfroYjoCIKIX6vcumwBKT/37Whe gUse5w8ToP9ztn1gAypDDb5jNp0OzTr7z16kx3OCbqqbGLGgV+1Kz+MbqjyW7gMHiyJ+ hxNh6olaY4851CpV9gVNxgu5lLuoqGL7DS90VAE5klvW3P4FEpnMjTsqs4Y1RKYxqG3J 8C8A== X-Gm-Message-State: ALoCoQmD4JThIw6Xn4V4pjI/D8Wsy6yffI+MVUwDoTGiz7oFE9+ffs+QWP4phv2W0XdRHGDIcZOQ X-Received: by 10.152.224.129 with SMTP id rc1mr11204989lac.10.1441972795336; Fri, 11 Sep 2015 04:59:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.167 with SMTP id x7ls346012lad.53.gmail; Fri, 11 Sep 2015 04:59:55 -0700 (PDT) X-Received: by 10.152.1.72 with SMTP id 8mr27367196lak.70.1441972795092; Fri, 11 Sep 2015 04:59:55 -0700 (PDT) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com. [2a00:1450:4010:c03::229]) by mx.google.com with ESMTPS id ai2si12044lbc.68.2015.09.11.04.59.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 04:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) client-ip=2a00:1450:4010:c03::229; Received: by lahg1 with SMTP id g1so16245598lah.1 for ; Fri, 11 Sep 2015 04:59:55 -0700 (PDT) X-Received: by 10.152.203.134 with SMTP id kq6mr41898580lac.106.1441972794999; Fri, 11 Sep 2015 04:59:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1542783lbq; Fri, 11 Sep 2015 04:59:54 -0700 (PDT) X-Received: by 10.50.141.198 with SMTP id rq6mr3279655igb.54.1441972793911; Fri, 11 Sep 2015 04:59:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si138799igh.40.2015.09.11.04.59.53; Fri, 11 Sep 2015 04:59:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753048AbbIKL7v (ORCPT + 28 others); Fri, 11 Sep 2015 07:59:51 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:36535 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751932AbbIKL5r (ORCPT ); Fri, 11 Sep 2015 07:57:47 -0400 Received: by wicgb1 with SMTP id gb1so59619461wic.1; Fri, 11 Sep 2015 04:57:46 -0700 (PDT) X-Received: by 10.180.82.98 with SMTP id h2mr15503044wiy.37.1441972666058; Fri, 11 Sep 2015 04:57:46 -0700 (PDT) Received: from localhost.localdomain (cpc17-aztw24-2-0-cust759.aztw.cable.virginm.net. [92.237.134.248]) by smtp.gmail.com with ESMTPSA id wj4sm25354wjb.10.2015.09.11.04.57.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Sep 2015 04:57:44 -0700 (PDT) From: Kieran Bingham To: Wolfram Sang , Samuel Ortiz , Lee Jones Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, grant.likely@linaro.org, javier@osg.samsung.com, Kieran Bingham Subject: [RESEND PATCH v4 1/8] i2c: Add pointer dereference protection to i2c_match_id() Date: Fri, 11 Sep 2015 12:55:57 +0100 Message-Id: <1441972564-9621-2-git-send-email-kieranbingham@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441972564-9621-1-git-send-email-kieranbingham@gmail.com> References: <1441972564-9621-1-git-send-email-kieranbingham@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: kieranbingham@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Lee Jones 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 Signed-off-by: Kieran Bingham --- 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 c83e4d1..30d8a77 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -450,6 +450,9 @@ static inline int acpi_i2c_install_space_handler(struct i2c_adapter *adapter) 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; @@ -463,8 +466,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)) @@ -475,9 +476,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; }