From patchwork Thu Aug 28 14:35:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 36226 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 40152202DD for ; Thu, 28 Aug 2014 14:37:12 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf4748132qge.0 for ; Thu, 28 Aug 2014 07:37:12 -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=DH3tNfzOkDZdwm7nuqFcDA3ZJyPqB+WaUVwE1WRjr0o=; b=RDFTeGwVsI297UhbWTckOhyYlqw8mDBWabYzNDvEN8l7f2XcmGCP3mVEyBBCcUFaPr xVfF9be5VbSVtCPQteCw/5S5hDcrUfN1d+FiZws55YyVvfi8nhrLxBMfBhwzzXLSes2B BmmG65HIr5n1Ezm0gtxu3/59+wZe344eoR5KQIZivgOvU3olfD8o2vHmuyct7DBErlaX ZZSC1jw7ZCU3pCJkxC6RsjQS24DHqFxwcm7sjJpOJSnKYXgK4nxFyFMVVBn0iXmNTs52 ZE5lU2HtdYylssBbfA7EtNV4dtDhl+A2janllFVU/bJi6GyvoIydnMjAngkdPX+Oej22 kz1A== X-Gm-Message-State: ALoCoQlengNpslfugcReHVF//B0fGlaLBtUVX9TQh2nO3BOsrZgv2v8RYDAzUlbfeCuxKqGYFL0v X-Received: by 10.236.11.80 with SMTP id 56mr2270886yhw.22.1409236632093; Thu, 28 Aug 2014 07:37:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.70 with SMTP id g64ls562821qgf.85.gmail; Thu, 28 Aug 2014 07:37:11 -0700 (PDT) X-Received: by 10.52.83.227 with SMTP id t3mr3090745vdy.20.1409236631936; Thu, 28 Aug 2014 07:37:11 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id yt9si3689481vdb.21.2014.08.28.07.37.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:37:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hy4so891250vcb.24 for ; Thu, 28 Aug 2014 07:37:11 -0700 (PDT) X-Received: by 10.220.169.72 with SMTP id x8mr1289748vcy.45.1409236631817; Thu, 28 Aug 2014 07:37:11 -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.221.45.67 with SMTP id uj3csp246748vcb; Thu, 28 Aug 2014 07:37:11 -0700 (PDT) X-Received: by 10.70.47.161 with SMTP id e1mr6509661pdn.71.1409236630908; Thu, 28 Aug 2014 07:37:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id so2si6871082pab.132.2014.08.28.07.37.09 for ; Thu, 28 Aug 2014 07:37:10 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751660AbaH1Of4 (ORCPT + 26 others); Thu, 28 Aug 2014 10:35:56 -0400 Received: from mail-qg0-f50.google.com ([209.85.192.50]:51945 "EHLO mail-qg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751546AbaH1Ofx (ORCPT ); Thu, 28 Aug 2014 10:35:53 -0400 Received: by mail-qg0-f50.google.com with SMTP id q108so806556qgd.37 for ; Thu, 28 Aug 2014 07:35:53 -0700 (PDT) X-Received: by 10.140.30.66 with SMTP id c60mr6877528qgc.30.1409236553174; Thu, 28 Aug 2014 07:35:53 -0700 (PDT) Received: from localhost.localdomain (host86-152-0-170.range86-152.btcentralplus.com. [86.152.0.170]) by mx.google.com with ESMTPSA id o2sm5797541qgo.17.2014.08.28.07.35.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Aug 2014 07:35:52 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, wsa@the-dreams.de, grant.likely@linaro.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linus.walleij@linaro.org Subject: [PATCH 1/8] i2c: Add pointer dereference protection to i2c_match_id() Date: Thu, 28 Aug 2014 15:35:31 +0100 Message-Id: <1409236538-21274-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409236538-21274-1-git-send-email-lee.jones@linaro.org> References: <1409236538-21274-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.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.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org 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: , 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 632057a..d3c8e9f 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 && client)) + return NULL; + while (id->name[0]) { if (strcmp(client->name, id->name) == 0) return id; @@ -96,8 +99,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)) @@ -108,9 +109,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; }