From patchwork Fri Jul 17 14:08:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 6816071 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 22FA99F818 for ; Fri, 17 Jul 2015 14:09:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F5BF205B8 for ; Fri, 17 Jul 2015 14:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C056020791 for ; Fri, 17 Jul 2015 14:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757888AbbGQOJS (ORCPT ); Fri, 17 Jul 2015 10:09:18 -0400 Received: from sauhun.de ([89.238.76.85]:45247 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758091AbbGQOJR (ORCPT ); Fri, 17 Jul 2015 10:09:17 -0400 Received: from p4fe258cf.dip0.t-ipconnect.de ([79.226.88.207]:49572 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ZG6KC-0006ax-4v; Fri, 17 Jul 2015 16:09:16 +0200 From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-sh@vger.kernel.org, Magnus Damm , Simon Horman , Laurent Pinchart , Geert Uytterhoeven , Wolfram Sang , Andrey Danin , linux-tegra@vger.kernel.org Subject: [RFC 8/9] i2c: take address space into account when checking for used addresses Date: Fri, 17 Jul 2015 16:08:28 +0200 Message-Id: <1437142109-31975-9-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437142109-31975-1-git-send-email-wsa@the-dreams.de> References: <1437142109-31975-1-git-send-email-wsa@the-dreams.de> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang It is not enough to compare the plain address value, we also need to check the flags enabling a different address space. E.g. it is valid to have address 0x50 as a 7-bit address and 0x050 as 10-bit address on the same bus. Same for addresses when we are the slave. Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 4a92eded4ece9c..021ff232beaae3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -834,7 +834,7 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp) struct i2c_client *client = i2c_verify_client(dev); int addr = *(int *)addrp; - if (client && client->addr == addr) + if (client && i2c_encode_flags_to_addr(client) == addr) return -EBUSY; return 0; } @@ -988,7 +988,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) } /* Check for address business */ - status = i2c_check_addr_busy(adap, client->addr); + status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client)); if (status) goto out_err; @@ -2284,7 +2284,7 @@ static int i2c_detect_address(struct i2c_client *temp_client, return err; } - /* Skip if already in use */ + /* Skip if already in use (7 bit, no need to encode flags) */ if (i2c_check_addr_busy(adapter, addr)) return 0; @@ -2400,7 +2400,7 @@ i2c_new_probed_device(struct i2c_adapter *adap, continue; } - /* Check address availability */ + /* Check address availability (7 bit, no need to encode flags) */ if (i2c_check_addr_busy(adap, addr_list[i])) { dev_dbg(&adap->dev, "Address 0x%02x already in " "use, not probing\n", addr_list[i]);