From patchwork Sat Aug 8 20:33:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 6975921 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 062FBC05AC for ; Sat, 8 Aug 2015 20:33:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A9752062A for ; Sat, 8 Aug 2015 20:33:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 373F920610 for ; Sat, 8 Aug 2015 20:33:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992685AbbHHUd4 (ORCPT ); Sat, 8 Aug 2015 16:33:56 -0400 Received: from sauhun.de ([89.238.76.85]:55349 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2992525AbbHHUd4 (ORCPT ); Sat, 8 Aug 2015 16:33:56 -0400 Received: from p4fe257ec.dip0.t-ipconnect.de ([79.226.87.236]:35279 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ZOAoU-0004PU-OD; Sat, 08 Aug 2015 22:33:54 +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 , Stephen Warren , Stephen Warren Subject: [PATCH 05/10] i2c: make address check indpendent from client struct Date: Sat, 8 Aug 2015 22:33:22 +0200 Message-Id: <1439066007-13951-6-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439066007-13951-1-git-send-email-wsa@the-dreams.de> References: <1439066007-13951-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=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 We want to use this function with struct boardinfo soon, so let's just pass the parameters really needed. We also extend the type of addr, so more types can be input. Remove a superfluous dangling comment while here. Tested-by: Andrey Danin Acked-by: Stephen Warren Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 28766b7208bcc2..4a83d39a5aabe2 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -796,15 +796,15 @@ static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client) /* This is a permissive address validity check, I2C address map constraints * are purposely not enforced, except for the general call address. */ -static int i2c_check_addr_validity(const struct i2c_client *client) +static int i2c_check_addr_validity(unsigned addr, unsigned short flags) { - if (client->flags & I2C_CLIENT_TEN) { + if (flags & I2C_CLIENT_TEN) { /* 10-bit address, all values are valid */ - if (client->addr > 0x3ff) + if (addr > 0x3ff) return -EINVAL; } else { /* 7-bit address, reject the general call address */ - if (client->addr == 0x00 || client->addr > 0x7f) + if (addr == 0x00 || addr > 0x7f) return -EINVAL; } return 0; @@ -982,8 +982,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) strlcpy(client->name, info->type, sizeof(client->name)); - /* Check for address validity */ - status = i2c_check_addr_validity(client); + status = i2c_check_addr_validity(client->addr, client->flags); if (status) { dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n", client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr);