Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp368321ybx; Wed, 6 Nov 2019 01:53:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyyt3IpNB8SqICSMis20m5I1HSv1JvNU7zKtmypBJgldMn1/ky0d245ojLEq1Hf8DeWOWZF X-Received: by 2002:a17:906:694e:: with SMTP id c14mr34645580ejs.122.1573034002056; Wed, 06 Nov 2019 01:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573034002; cv=none; d=google.com; s=arc-20160816; b=VhWkoO+IkR6avYn6fn3O5pW5i8+10EGoAuc4iK5xwSxsfVH6ORccQInwrb0SoWTlkr 8dCbwlkAidqGiPzFJHCeRgd9jUwe+xesEXG/xZIkFBzAAKYVprd6f2z1m6GQvo/VhXdp qmSZldCQP7cR+q1/toJXkLtcEb31X4sMA+zfu2GqB8YenVPpeoPGx0uCS0Qfi9raTCBr 7H20zxG4l7LG1I8EgWC6D3AkXJY3QoZFtGSWm6ccc0jRKrquCS/TfRlr2L0uFEJFRgu4 5CY0+A4t0PWwfRS+O7vWTqJZXJdhId1w5HLVMkIxEJ2q5DvQP+SqFj4XpGg0dibx6RI2 iDQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XNefu+dvI2onuSm1TZeH+oNAYW+d5s+j7ImUUdBuH84=; b=aIy55ulkPSV4SXBgmfpSvBb9OSjqhRoOHy5/d6LhakzIDZXWYJae2Z/V5z8kS++fb6 sHK2FuXIIF/8+UXSx42wTbycrZO6V5dGr3C/9gBKcbc4O78fFIJDgzwx24+hc7opURMR zYH97SMBhoqc4V+VcGJS0IxigbFncWBtNWfSTpuGdgJh63tASI6mlIcvb2SG9W51fp1/ 2yyBx2vEV3eZDJm7LV8q+5dmn9i1RTjJeROn2x0Gv12MCHYq/GAtqvoQ7gHlo3UByPak /OwBT5AeA0JnAxBxqD5c72oGTpPecU242C54QWR32QdAVf1YaBoq7W3M7jWmTwEj39wW xgBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a28si12885229edc.5.2019.11.06.01.52.58; Wed, 06 Nov 2019 01:53:22 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730038AbfKFJug (ORCPT + 99 others); Wed, 6 Nov 2019 04:50:36 -0500 Received: from sauhun.de ([88.99.104.3]:50156 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727015AbfKFJug (ORCPT ); Wed, 6 Nov 2019 04:50:36 -0500 Received: from localhost (p54B33505.dip0.t-ipconnect.de [84.179.53.5]) by pokefinder.org (Postfix) with ESMTPSA id 340A62C053E; Wed, 6 Nov 2019 10:50:34 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , Wolfram Sang , linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/12] i2c: replace i2c_new_probed_device with an ERR_PTR variant Date: Wed, 6 Nov 2019 10:50:19 +0100 Message-Id: <20191106095033.25182-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191106095033.25182-1-wsa+renesas@sang-engineering.com> References: <20191106095033.25182-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the general move to have i2c_new_*_device functions which return ERR_PTR instead of NULL, this patch converts i2c_new_probed_device(). There are only few users, so this patch converts the I2C core and all users in one go. The function gets renamed to i2c_new_scanned_device() so out-of-tree users will get a build failure to understand they need to adapt their error checking code. Signed-off-by: Wolfram Sang --- Documentation/i2c/instantiating-devices.rst | 10 ++++----- Documentation/i2c/writing-clients.rst | 8 +++---- drivers/i2c/i2c-core-base.c | 25 ++++++++++++++++----- include/linux/i2c.h | 12 +++++++--- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Documentation/i2c/instantiating-devices.rst b/Documentation/i2c/instantiating-devices.rst index 1238f1fa3382..875ebe9e78e3 100644 --- a/Documentation/i2c/instantiating-devices.rst +++ b/Documentation/i2c/instantiating-devices.rst @@ -123,7 +123,7 @@ present or not (for example for an optional feature which is not present on cheap variants of a board but you have no way to tell them apart), or it may have different addresses from one board to the next (manufacturer changing its design without notice). In this case, you can call -i2c_new_probed_device() instead of i2c_new_device(). +i2c_new_scanned_device() instead of i2c_new_device(). Example (from the nxp OHCI driver):: @@ -139,8 +139,8 @@ Example (from the nxp OHCI driver):: i2c_adap = i2c_get_adapter(2); memset(&i2c_info, 0, sizeof(struct i2c_board_info)); strscpy(i2c_info.type, "isp1301_nxp", sizeof(i2c_info.type)); - isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, - normal_i2c, NULL); + isp1301_i2c_client = i2c_new_scanned_device(i2c_adap, &i2c_info, + normal_i2c, NULL); i2c_put_adapter(i2c_adap); (...) } @@ -153,14 +153,14 @@ simply gives up. The driver which instantiated the I2C device is responsible for destroying it on cleanup. This is done by calling i2c_unregister_device() on the pointer that was earlier returned by i2c_new_device() or -i2c_new_probed_device(). +i2c_new_scanned_device(). Method 3: Probe an I2C bus for certain devices ---------------------------------------------- Sometimes you do not have enough information about an I2C device, not even -to call i2c_new_probed_device(). The typical case is hardware monitoring +to call i2c_new_scanned_device(). The typical case is hardware monitoring chips on PC mainboards. There are several dozen models, which can live at 25 different addresses. Given the huge number of mainboards out there, it is next to impossible to build an exhaustive list of the hardware diff --git a/Documentation/i2c/writing-clients.rst b/Documentation/i2c/writing-clients.rst index dddf0a14ab7c..ced309b5e0cc 100644 --- a/Documentation/i2c/writing-clients.rst +++ b/Documentation/i2c/writing-clients.rst @@ -185,14 +185,14 @@ Sometimes you know that a device is connected to a given I2C bus, but you don't know the exact address it uses. This happens on TV adapters for example, where the same driver supports dozens of slightly different models, and I2C device addresses change from one model to the next. In -that case, you can use the i2c_new_probed_device() variant, which is +that case, you can use the i2c_new_scanned_device() variant, which is similar to i2c_new_device(), except that it takes an additional list of possible I2C addresses to probe. A device is created for the first responsive address in the list. If you expect more than one device to be -present in the address range, simply call i2c_new_probed_device() that +present in the address range, simply call i2c_new_scanned_device() that many times. -The call to i2c_new_device() or i2c_new_probed_device() typically happens +The call to i2c_new_device() or i2c_new_scanned_device() typically happens in the I2C bus driver. You may want to save the returned i2c_client reference for later use. @@ -237,7 +237,7 @@ Device Deletion --------------- Each I2C device which has been created using i2c_new_device() or -i2c_new_probed_device() can be unregistered by calling +i2c_new_scanned_device() can be unregistered by calling i2c_unregister_device(). If you don't call it explicitly, it will be called automatically before the underlying I2C bus itself is removed, as a device can't survive its parent in the device driver model. diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 6a5183cffdfc..380bde2dc23e 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2277,10 +2277,10 @@ int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr) EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read); struct i2c_client * -i2c_new_probed_device(struct i2c_adapter *adap, - struct i2c_board_info *info, - unsigned short const *addr_list, - int (*probe)(struct i2c_adapter *adap, unsigned short addr)) +i2c_new_scanned_device(struct i2c_adapter *adap, + struct i2c_board_info *info, + unsigned short const *addr_list, + int (*probe)(struct i2c_adapter *adap, unsigned short addr)) { int i; @@ -2310,11 +2310,24 @@ i2c_new_probed_device(struct i2c_adapter *adap, if (addr_list[i] == I2C_CLIENT_END) { dev_dbg(&adap->dev, "Probing failed, no device found\n"); - return NULL; + return ERR_PTR(-ENODEV); } info->addr = addr_list[i]; - return i2c_new_device(adap, info); + return i2c_new_client_device(adap, info); +} +EXPORT_SYMBOL_GPL(i2c_new_scanned_device); + +struct i2c_client * +i2c_new_probed_device(struct i2c_adapter *adap, + struct i2c_board_info *info, + unsigned short const *addr_list, + int (*probe)(struct i2c_adapter *adap, unsigned short addr)) +{ + struct i2c_client *client; + + client = i2c_new_scanned_device(adap, info, addr_list, probe); + return IS_ERR(client) ? NULL : client; } EXPORT_SYMBOL_GPL(i2c_new_probed_device); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index aaf57d9b41db..df3044513464 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -452,10 +452,16 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf * a default probing method is used. */ extern struct i2c_client * +i2c_new_scanned_device(struct i2c_adapter *adap, + struct i2c_board_info *info, + unsigned short const *addr_list, + int (*probe)(struct i2c_adapter *adap, unsigned short addr)); + +extern struct i2c_client * i2c_new_probed_device(struct i2c_adapter *adap, - struct i2c_board_info *info, - unsigned short const *addr_list, - int (*probe)(struct i2c_adapter *adap, unsigned short addr)); + struct i2c_board_info *info, + unsigned short const *addr_list, + int (*probe)(struct i2c_adapter *adap, unsigned short addr)); /* Common custom probe functions */ extern int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr); -- 2.20.1