From patchwork Wed Jul 6 02:57:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 71413 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp637687qgy; Tue, 5 Jul 2016 19:57:37 -0700 (PDT) X-Received: by 10.66.135.40 with SMTP id pp8mr38272426pab.113.1467773852787; Tue, 05 Jul 2016 19:57:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si1486847pfg.270.2016.07.05.19.57.32; Tue, 05 Jul 2016 19:57:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752720AbcGFC5Z (ORCPT + 1 other); Tue, 5 Jul 2016 22:57:25 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:34849 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751739AbcGFC5O (ORCPT ); Tue, 5 Jul 2016 22:57:14 -0400 Received: by mail-pf0-f177.google.com with SMTP id c2so75744449pfa.2 for ; Tue, 05 Jul 2016 19:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=3GGok6qPnlPXXUesv0kJyJLtlpcM1t8KmedghH6KpTI=; b=IAj8ZRjGTco8qFInjAkMoplF+o8xIsZz8mG7xntbtpHjJWMwbbdWBjG6nhcWkYBPKq f0WcKoJnyHQT4EPZJvaHTYCa4G31aynVqDaAABGeRJRWxCvq31ziqanxgbb6dVP6i7T9 AWi/JPwRyzmpNFqjSBt9Q0uRKr8YkqrXz6d8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=3GGok6qPnlPXXUesv0kJyJLtlpcM1t8KmedghH6KpTI=; b=RnBFZU4Vw2fyBW/dCS+Jnb6GbiDJCZWTBFM8b+AO2fnK0qbpdIfLVTn/Ez3vd9Vxxg 0L4yhIm82x4KI7t6HPEakQxoVySsQNRwte9T8zqJ3356xOSZSEeVPzJ9m0pQQ+0BprI7 xmBerUTBaaJpmwigbwRoAQqt2poIlcH/UtNX7F+g3b4oDr/BKDTOWOdeqUrdYJsaqHhn YIC3/+tWsZQz3LrmPxVlh/TB7LWS49u2Xd4Qh5G9rHFWJDpJp1smG53Xx2Md0jxzFgeF aJrO18OrYUimqtv0J0MagHHimHyAOU776a4VZMwjHReMUGDJ2IUwSTsen/qXxqYE58/k lbWQ== X-Gm-Message-State: ALyK8tJ7XcE5Ljh8jWve7HhDqQFxfrtGGZFJEpVQGTvwPUMjZSq0eaiqnB7mxGpAJzF2XG/+ X-Received: by 10.98.210.66 with SMTP id c63mr37676712pfg.25.1467773833450; Tue, 05 Jul 2016 19:57:13 -0700 (PDT) Received: from localhost ([12.201.7.201]) by smtp.gmail.com with ESMTPSA id p4sm1544630pac.46.2016.07.05.19.57.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jul 2016 19:57:12 -0700 (PDT) From: Viresh Kumar To: Wolfram Sang , Jean Delvare Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Johan Hovold , Alex Elder , Viresh Kumar Subject: [PATCH 1/2] i2c-dev: don't get i2c adapter via i2c_dev Date: Tue, 5 Jul 2016 19:57:06 -0700 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org There is no code protecting i2c_dev to be freed after it is returned from i2c_dev_get_by_minor() and using it to access the value which we already have (minor) isn't safe really. Avoid using it and get the adapter directly from 'minor'. Signed-off-by: Viresh Kumar --- drivers/i2c/i2c-dev.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 6ecfd76270f2..66f323fd3982 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -485,13 +485,8 @@ static int i2cdev_open(struct inode *inode, struct file *file) unsigned int minor = iminor(inode); struct i2c_client *client; struct i2c_adapter *adap; - struct i2c_dev *i2c_dev; - - i2c_dev = i2c_dev_get_by_minor(minor); - if (!i2c_dev) - return -ENODEV; - adap = i2c_get_adapter(i2c_dev->adap->nr); + adap = i2c_get_adapter(minor); if (!adap) return -ENODEV;