From patchwork Fri Dec 15 17:43:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="s7WloNnr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyyVP5NRtz9ryk for ; Sat, 16 Dec 2017 04:44:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755899AbdLORo2 (ORCPT ); Fri, 15 Dec 2017 12:44:28 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:41002 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755650AbdLORo1 (ORCPT ); Fri, 15 Dec 2017 12:44:27 -0500 Received: by mail-wm0-f67.google.com with SMTP id g75so19072404wme.0; Fri, 15 Dec 2017 09:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=KyX88uEtMQ3364t/TX/7WHD7Ud/01PuQoKpoAALZdr0=; b=s7WloNnrOVB/dawwupvuTQLAwrVA01InGR+uBr6LPChPT5PfRO87GhqXX85Y4kXOf1 JlRpUaiqukS4nmB4vrZF2gESh3cglbe0q++higpkd6TIIHvNagYRoul6llboxJYWxa80 u/9hbZnUi1Y07Lib0wcdcA9pggQJOLeE+PidDH5U2okY0TMPMbWNXj7qWnahIMyp9WNq NrIEHUorJIl1i/UtKZiLlTAGgvfTwux9ZKSRNbqAEzbiqyhX1KzY5QNWzPQnT8prDv/T eQ86s2VcJYWqvXVEWzNDdjNUChVehPGq3Q8JY3/arKTAfwjMWJs4AdCPwBr2O2c2BQQf Ee1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=KyX88uEtMQ3364t/TX/7WHD7Ud/01PuQoKpoAALZdr0=; b=mv/mwNDBMlu4HIPuY8aZ1AN+kzXmv5FBdfy2jpSPlX2p5PpiwOUSDBqYPvKQLbFCtX UZyjGdQe/ggR0ulS8FpZ+r33Lpkn5sUrVXo7wHvmXijNvYpiPGTjvPokYVTYa52R0+hR qvtl1+YR+PIxMOAdK5NpPjOW+rmFoPo6a0tYu6Ub51Zjq+K73ep7gi51Agd1dGInpmwV F8ItfrW9yU4+EAwAireqcXCHdYxZcAnn3vj7u52kglYmlG6rz/bjS9IdeRY3rasDgGdS GXWIWOAJRp5I8YHGOw51OSaDRdUGnMixoXUGvt12OE4pZh5fFtwlYEyCNpf9M4wPVf7z roLA== X-Gm-Message-State: AKGB3mJaHTYeb09Uz1zq4Y+ryrhQcT95LeXa0m5y7zHP0lYqhV38zOlp bYcpivbXehHUlcPYOs91RL5H5g== X-Google-Smtp-Source: ACJfBovj9ISPWL3YjWSYGbpsizoh7tV08CfMVzict2SKzFAKedA1izkwUHsNv/KpzeghHbp/cEIo3Q== X-Received: by 10.80.214.202 with SMTP id l10mr17759799edj.58.1513359865511; Fri, 15 Dec 2017 09:44:25 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b0d3:a11f:88fd:f202? (p200300EA8BC0E400B0D3A11F88FDF202.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b0d3:a11f:88fd:f202]) by smtp.googlemail.com with ESMTPSA id a38sm5811964edf.3.2017.12.15.09.44.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:44:24 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy To: Bartosz Golaszewski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , Linux Kernel Mailing List References: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Message-ID: <8d2c0c10-e308-d038-4b68-e030404abe26@gmail.com> Date: Fri, 15 Dec 2017 18:43:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently i2c_new_device and i2c_new_dummy return just NULL in error case although they have more error details internally. Therefore move the functionality into new functions returning detailed errors and add wrappers for compatibilty with the current API. This allows to use these functions with detailed error codes within the i2c core or for API extensions. Signed-off-by: Heiner Kallweit Reviewed-by: Bartosz Golaszewski --- v3: - prefix i2c_new_device and i2c_new_dummy with two underscores instead one v4: - add missing kernel doc - add reviewed-by --- drivers/i2c/i2c-core-base.c | 70 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index bb34a5d41..3b962456c 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -656,7 +656,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources, } /** - * i2c_new_device - instantiate an i2c device + * __i2c_new_device - instantiate an i2c device * @adap: the adapter managing the device * @info: describes one I2C device; bus_num is ignored * Context: can sleep @@ -669,17 +669,17 @@ static int i2c_dev_irq_from_resources(const struct resource *resources, * before any i2c_adapter could exist. * * This returns the new i2c client, which may be saved for later use with - * i2c_unregister_device(); or NULL to indicate an error. + * i2c_unregister_device(); or an ERR_PTR to indicate an error. */ -struct i2c_client * -i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) +static struct i2c_client * +__i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) { struct i2c_client *client; int status; client = kzalloc(sizeof *client, GFP_KERNEL); if (!client) - return NULL; + return ERR_PTR(-ENOMEM); client->adapter = adap; @@ -746,7 +746,29 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) client->name, client->addr, status); out_err_silent: kfree(client); - return NULL; + return ERR_PTR(status); +} + +/** + * i2c_new_device - instantiate an i2c device + * @adap: the adapter managing the device + * @info: describes one I2C device; bus_num is ignored + * Context: can sleep + * + * This function has the same functionality like __i2_new_device, it just + * returns NULL instead of an ERR_PTR in case of an error for compatibility + * with current I2C API. + * + * This returns the new i2c client, which may be saved for later use with + * i2c_unregister_device(); or NULL to indicate an error. + */ +struct i2c_client * +i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) +{ + struct i2c_client *ret; + + ret = __i2c_new_device(adap, info); + return IS_ERR(ret) ? NULL : ret; } EXPORT_SYMBOL_GPL(i2c_new_device); @@ -793,7 +815,7 @@ static struct i2c_driver dummy_driver = { }; /** - * i2c_new_dummy - return a new i2c device bound to a dummy driver + * __i2c_new_dummy - return a new i2c device bound to a dummy driver * @adapter: the adapter managing the device * @address: seven bit address to be used * Context: can sleep @@ -808,15 +830,37 @@ static struct i2c_driver dummy_driver = { * different driver. * * This returns the new i2c client, which should be saved for later use with - * i2c_unregister_device(); or NULL to indicate an error. + * i2c_unregister_device(); or an ERR_PTR to indicate an error. */ -struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) +static struct i2c_client * +__i2c_new_dummy(struct i2c_adapter *adapter, u16 address) { struct i2c_board_info info = { I2C_BOARD_INFO("dummy", address), }; - return i2c_new_device(adapter, &info); + return __i2c_new_device(adapter, &info); +} + +/** + * i2c_new_dummy - return a new i2c device bound to a dummy driver + * @adapter: the adapter managing the device + * @address: seven bit address to be used + * Context: can sleep + * + * This function has the same functionality like __i2_new_dummy, it just + * returns NULL instead of an ERR_PTR in case of an error for compatibility + * with current I2C API. + * + * This returns the new i2c client, which should be saved for later use with + * i2c_unregister_device(); or an ERR_PTR to indicate an error. + */ +struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) +{ + struct i2c_client *ret; + + ret = __i2c_new_dummy(adapter, address); + return IS_ERR(ret) ? NULL : ret; } EXPORT_SYMBOL_GPL(i2c_new_dummy); @@ -939,9 +983,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, info.flags |= I2C_CLIENT_SLAVE; } - client = i2c_new_device(adap, &info); - if (!client) - return -EINVAL; + client = __i2c_new_device(adap, &info); + if (IS_ERR(client)) + return PTR_ERR(client); /* Keep track of the added device */ mutex_lock(&adap->userspace_clients_lock); From patchwork Fri Dec 15 17:44:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vh1En3p2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyyVv6X0Hz9ryk for ; Sat, 16 Dec 2017 04:44:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755650AbdLORoy (ORCPT ); Fri, 15 Dec 2017 12:44:54 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:46358 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755867AbdLORo2 (ORCPT ); Fri, 15 Dec 2017 12:44:28 -0500 Received: by mail-wm0-f65.google.com with SMTP id r78so19036346wme.5; Fri, 15 Dec 2017 09:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=k3UiCq5HGveqxP9g2EG3Jlj74VN6rl0fASmj1RcyYHo=; b=vh1En3p2ES02W+XqH/nGSXw7XE4etEYig+W7Y9SN74AP4j+wlTvii6/HJnaO+kWYG1 KMT9UMBJ1iGx8+sBMk57Mk9431L4rvCTHeNmfS8BI2qfvtPemIB77uz9MQk40m1Jfp/6 SRtfV7k6pXU6z1WB3h+uJRtmMhimFyZt5xPoT7foBxGxP3BroFSCu6h3pAJdsmzc1tAJ tcpM3fwCbVJxzed9jiG5KgZNBmPeA5CX3f+1H6ci2+/f0UFz6ptiaBKv5YCcQMYpXed2 WbtGRRwjiE1dwDo/kRr9/OSjQPkg50GzsCb4PqdslwrV0nJVStHQO+1kX9qXFPZhVCbN WZxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=k3UiCq5HGveqxP9g2EG3Jlj74VN6rl0fASmj1RcyYHo=; b=qAq4tB/HtgsZP8creyu1gnH9qofRPY4P/KBWSphP+6A/1WVxa0t9MLWl/kAU1LAlgp 5M2Avh6aU+hXrZXc/mBrOlqNjkOUWw9tehc/aA+fqLGVWZYXC6kQvUYPxy+buJESWJVQ PtRCqhm3/kQf6hj4At8yQHdRzOfJrcKEdnvaxXdVEFyN11pjaMWr13d4ezIu8ibIlXLn C5ji6PD7nFuqxSu1AJuZcCL7t9Wnb5GN4ATXGF5MfFgc2spp8J9mp7OFc0b/o/hfNuKD 4Fzy9widPdRFZUkj/2xycCxUJzX7gN/8ADpQmm3ZQdGGt5U6E59eLKUHaQlfOa/XOBMs AdcQ== X-Gm-Message-State: AKGB3mIgTkF7OF+cYDkVuyxdyTnbMG9WPscW7UmpzVfIl6HERl2VRR+t vNgEzbnENh58kJ+EVfxMgZi5YQ== X-Google-Smtp-Source: ACJfBoth1Ne3XLVRM27xto8CMrQJIZg05XV5A08flGfsMz/7F+faui6ac6P04qjGfP0LiDiM+h+KXg== X-Received: by 10.80.171.22 with SMTP id s22mr18379817edc.67.1513359867039; Fri, 15 Dec 2017 09:44:27 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b0d3:a11f:88fd:f202? (p200300EA8BC0E400B0D3A11F88FDF202.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b0d3:a11f:88fd:f202]) by smtp.googlemail.com with ESMTPSA id g25sm5781272edc.68.2017.12.15.09.44.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:44:26 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 2/3] i2c: core: add device-managed version of i2c_new_dummy To: Bartosz Golaszewski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , Linux Kernel Mailing List References: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Message-ID: Date: Fri, 15 Dec 2017 18:44:04 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org i2c_new_dummy is typically called from the probe function of the driver for the primary i2c client. It requires calls to i2c_unregister_device in the error path of the probe function and in the remove function. This can be simplified by introducing a device-managed version. Note the changed error case return value type: i2c_new_dummy returns NULL whilst devm_new_i2c_dummy returns an ERR_PTR. Signed-off-by: Heiner Kallweit Reviewed-by: Bartosz Golaszewski --- v2: - use new function _i2c_new_dummy with detailed error codes v3: - no changes v4: - reflect renaming to __i2c_new_dummy - add reviewed-by --- Documentation/driver-model/devres.txt | 3 +++ drivers/i2c/i2c-core-base.c | 38 +++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 3 +++ 3 files changed, 44 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index c180045eb..6e2bccf85 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -259,6 +259,9 @@ GPIO devm_gpio_request_one() devm_gpio_free() +I2C + devm_i2c_new_dummy + IIO devm_iio_device_alloc() devm_iio_device_free() diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 3b962456c..7a6669f07 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -864,6 +864,44 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) } EXPORT_SYMBOL_GPL(i2c_new_dummy); +static void devm_i2c_release_dummy(struct device *dev, void *res) +{ + i2c_unregister_device(*(struct i2c_client **)res); +} + +/** + * devm_i2c_new_dummy - return a new i2c device bound to a dummy driver + * @dev: device the managed resource is bound to + * @adapter: the adapter managing the device + * @address: seven bit address to be used + * Context: can sleep + * + * This is the device-managed version of i2c_new_dummy. + * Note the changed return value type: It returns the new i2c client + * or an ERR_PTR in case of an error. + */ +struct i2c_client *devm_i2c_new_dummy(struct device *dev, + struct i2c_adapter *adapter, + u16 address) +{ + struct i2c_client *ret, **dr; + + dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL); + if (!dr) + return ERR_PTR(-ENOMEM); + + ret = __i2c_new_dummy(adapter, address); + if (IS_ERR(ret)) { + devres_free(dr); + } else { + *dr = ret; + devres_add(dev, dr); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_i2c_new_dummy); + /** * i2c_new_secondary_device - Helper to get the instantiated secondary address * and create the associated device diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 5d7f3c185..aca6ebbb8 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -441,6 +441,9 @@ extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); extern struct i2c_client * i2c_new_dummy(struct i2c_adapter *adap, u16 address); +extern struct i2c_client * +devm_i2c_new_dummy(struct device *dev, struct i2c_adapter *adap, u16 address); + extern struct i2c_client * i2c_new_secondary_device(struct i2c_client *client, const char *name, From patchwork Fri Dec 15 17:44:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XAF29lBE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyyVn369wz9t2d for ; Sat, 16 Dec 2017 04:44:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932080AbdLORoe (ORCPT ); Fri, 15 Dec 2017 12:44:34 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40135 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932088AbdLORoa (ORCPT ); Fri, 15 Dec 2017 12:44:30 -0500 Received: by mail-wm0-f68.google.com with SMTP id f206so19013684wmf.5; Fri, 15 Dec 2017 09:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=dOJwHi8cykj5jB+HmwtbzPNA1kydhnshxRd/CS/5Ic8=; b=XAF29lBEq+Gztj7gzon6Ta2rOf6mjntdD8Ar4evA6RN0x0Q5j4i2aqL/Toy2uHW70T WlVsv7+NKiCQqIkem7+zCCQf/0FpZtBrmHGB+R+VZxY+6fs/ZbkokPmxgXmriX4c63Uu EN8hi8pFXGNGWS9+7spZv282buh6n6plFQqYmX7e2HSi7jIB3Z/JbQ69D2YUjIz00Vqk JcPR+7uDqbrDlmE0Dv0zYQhwQUz8wfTXPJNcnh++jSMybAzchR7BP7Xsw0cWzagIt/sw yLBnlpAN9N892hUtEGxpU4kjG/QyrQ2qdVHWiKaTP5KRa4aCozQvSoTp8Y1Zg1s+3Z8m wksw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=dOJwHi8cykj5jB+HmwtbzPNA1kydhnshxRd/CS/5Ic8=; b=pTGhlV4hOP6ROElplMDO8V5iltDqpWS8hQ4om2kl+PUTwCKUCOFuP3USroKKlEFl0K f+mbWEWfYoaivrdqrQexZX9uk8IWfFXNCEMQve5nrFXHKGGk14Y35mlmXvQfE9eqgiyK b3DZ/ldJgn+TLmt4RLOgpuctjyjtRYtc86KlpLvV72CFigNQ0rNN7cH9eC41CDeGrdou Axft+eq0qqp2iL4WGg29xdwervIZl6BkQ/HCqvOTVfsWXxfxdm3Ci1RdgH0XKAPmuIvn BXv8C4ABlNMyFcDFcUaLP1NVW1LBfK0JILqt4Fw55rbA7AbjctSVRWgHbszj7Y19W7yQ lZtw== X-Gm-Message-State: AKGB3mKcDdtX6+iE2kss5r7OkPoppaN/wIOJ5pzDNMRQMcunMmu57ylC 99N/XEenmT6pKRBYJDqb/eh9dQ== X-Google-Smtp-Source: ACJfBotGGRehvXJ3IUQRLitCLvzAgieYdMfQPurkOOi16U9gu4n+ESUczZaKo88OA9WjNJrV6yUsEQ== X-Received: by 10.80.217.6 with SMTP id t6mr18421315edj.217.1513359868518; Fri, 15 Dec 2017 09:44:28 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b0d3:a11f:88fd:f202? (p200300EA8BC0E400B0D3A11F88FDF202.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b0d3:a11f:88fd:f202]) by smtp.googlemail.com with ESMTPSA id j39sm6160783ede.38.2017.12.15.09.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:44:28 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v4 3/3] eeprom: at24: switch to device-managed version of i2c_new_dummy To: Bartosz Golaszewski , Wolfram Sang , Peter Rosin Cc: "linux-i2c@vger.kernel.org" , Linux Kernel Mailing List References: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Message-ID: Date: Fri, 15 Dec 2017 18:44:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <083569b1-489a-d84f-1a87-bca52fad53e1@gmail.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Make use of recently introduced device-managed version of i2c_new_dummy to simplify the code. Signed-off-by: Heiner Kallweit Reviewed-by: Bartosz Golaszewski --- v2: - small improvements regarding code readability v3: - no changes v4: - no changes --- drivers/misc/eeprom/at24.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 625b00166..5f3a27a69 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -621,20 +621,19 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) /* use dummy devices for multiple-address chips */ for (i = 1; i < num_addresses; i++) { - at24->client[i].client = i2c_new_dummy(client->adapter, - client->addr + i); - if (!at24->client[i].client) { + struct at24_client *cl; + + cl = &at24->client[i]; + cl->client = devm_i2c_new_dummy(&client->dev, client->adapter, + client->addr + i); + if (IS_ERR(cl->client)) { dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); - err = -EADDRINUSE; - goto err_clients; - } - at24->client[i].regmap = devm_regmap_init_i2c( - at24->client[i].client, config); - if (IS_ERR(at24->client[i].regmap)) { - err = PTR_ERR(at24->client[i].regmap); - goto err_clients; + client->addr + i); + return PTR_ERR(cl->client); } + cl->regmap = devm_regmap_init_i2c(cl->client, config); + if (IS_ERR(cl->regmap)) + return PTR_ERR(cl->regmap); } i2c_set_clientdata(client, at24); @@ -686,10 +685,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) return 0; err_clients: - for (i = 1; i < num_addresses; i++) - if (at24->client[i].client) - i2c_unregister_device(at24->client[i].client); - pm_runtime_disable(&client->dev); return err; @@ -698,15 +693,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) static int at24_remove(struct i2c_client *client) { struct at24_data *at24; - int i; at24 = i2c_get_clientdata(client); nvmem_unregister(at24->nvmem); - for (i = 1; i < at24->num_addresses; i++) - i2c_unregister_device(at24->client[i].client); - pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev);