From patchwork Wed Dec 20 06:23:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 851268 X-Patchwork-Delegate: wolfram@the-dreams.de 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="ryLYx/ti"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z1l9f3bWVz9s7v for ; Wed, 20 Dec 2017 17:24:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754328AbdLTGYg (ORCPT ); Wed, 20 Dec 2017 01:24:36 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:44240 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754261AbdLTGYf (ORCPT ); Wed, 20 Dec 2017 01:24:35 -0500 Received: by mail-wm0-f66.google.com with SMTP id t8so7626662wmc.3; Tue, 19 Dec 2017 22:24:34 -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=Bge/MOLwx1WRZUjQSoSaYcM0nrcrF8Uz1A4sHx9zlQs=; b=ryLYx/tiiDTD4kw+cYqXsgJ2rmLZE/Mvok4LUvn1Knr+1LvC9mcOYxRarsij4q3Jdg BHGFdDo7rKsci8kYtWRuzLaemZPzS/ZXFiXYLMyElu5fzGnBSwKx42ibJfXR+2yjSRg5 2dY+bo79aJ1+ZIA0ILcQz17Ug9VccscY7sv0SJkQLTzf15Be2/RX2btp8irFU5cltmcK evON33wCbReCEm1HtBeiaakh9mDWe7QPMYTJbIKx4hs/Nr6snNFQBEpvUaw+Jrvobac7 +Jun3+5mbYME7lcvB6OiMfg00jZT0Ckp7LbrRMcpWcYAlm4WzKJ8aLi0rKeKLcUWd8O6 Wuag== 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=Bge/MOLwx1WRZUjQSoSaYcM0nrcrF8Uz1A4sHx9zlQs=; b=kbuv7FZ0mxf0ngYQljeF0sTAAyxuYzZ4OEtdcOxksyRo0bsCOTytl6om9hz1CZA7qA 4OC14fVKqPXF2fB/u1p6gLxjslGmBnqcBHuUhbisEHwCTGc8YP2ID+3EbTQdajLRc3Vi 9lER58sP2tk+t5lnMtnFNoQeisyjIkU+IZiwf96lHM7yXgM2Oa3nzkaIyI90gtuoqUTK +PdvYfLNV/COT5e9dCBm6GEIGtcu0S+PsTpFBLb2AZKUo7Ye40I//p3XK8BCajdc7T5a JeMOCfhv4LaTi2bsxPN8gW8whteiEYRmJ8egXi0Nv0aerRDfQnC7YTuzifMyX0LPoJ7d P4Bw== X-Gm-Message-State: AKGB3mLWtjCiScgerPIndPQAwWjR62kKBR7i0fBOYL1eut18yS0U/iKL NxzeMfRikmKg5smw7Hpk75DgGQ== X-Google-Smtp-Source: ACJfBotQE8GZv8K7NB8xgd8vKahkHH2Hp+/4A3IYWrQuetd9IPZYMKJIKhTcxD+RlP6Fajd31hJqyg== X-Received: by 10.80.204.72 with SMTP id n8mr3798008edi.64.1513751073989; Tue, 19 Dec 2017 22:24:33 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:9881:a13:154c:d69f? (p200300EA8BC0E40098810A13154CD69F.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:9881:a13:154c:d69f]) by smtp.googlemail.com with ESMTPSA id j3sm13060032edh.55.2017.12.19.22.24.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 22:24:33 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v6 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: <5a66eaa1-9735-4b63-be66-b640f993bd21@gmail.com> Message-ID: Date: Wed, 20 Dec 2017 07:23:49 +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: <5a66eaa1-9735-4b63-be66-b640f993bd21@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 v5: - fix a copy & paste error in a kernel doc comment v6: - no changes --- 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..cb3f29fb8 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 NULL 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 Wed Dec 20 06:24:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 851269 X-Patchwork-Delegate: wolfram@the-dreams.de 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="PNr08D+K"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z1lB10y3Zz9s7v for ; Wed, 20 Dec 2017 17:24:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932191AbdLTGYl (ORCPT ); Wed, 20 Dec 2017 01:24:41 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38856 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754312AbdLTGYh (ORCPT ); Wed, 20 Dec 2017 01:24:37 -0500 Received: by mail-wm0-f68.google.com with SMTP id 64so7558110wme.3; Tue, 19 Dec 2017 22:24:36 -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=A4UqaMxHZ3eNyKFon93TCTcf4QlsuE1jlTs3q8iChPM=; b=PNr08D+KLeDpqj7hQI62lQtcViMDoeGBukPxFikw339NzKwlqlsu6iGvQt9O+vfvTs DQLqizwnSQHaoEHAOIJm0NFqTI86WnW8r2KqwwKRkizEAR5B1e1rCd7wrQHrPSam5ZLV ZqKWI/8uM0y3+gbQfOZM1ZaODOLbjf4VoWTCw3vjdGo5rhy634KQn6ha8WTTfMFLR1oU goLrN+Bip1+UOAiQp4oMEJdWp9xJSXlmVj9Owhq6b3kiClANMJOIHJLQQbMX/StxbFqo aae0dlj8ALefYw/OTGfUx4v1qADb5CFdzvZP/QHwjOEKOTJWLOBT0k2aSkHPNIxFOe6L M8jA== 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=A4UqaMxHZ3eNyKFon93TCTcf4QlsuE1jlTs3q8iChPM=; b=qF8Zc58tiH9bqqHJbb1uRciGyqQ06gjGVxyTsUxwbTENWsOdtnT6UmXkpot3Nzrmyh r4p3LjolHC+9fB2zW7WD8towlLpipw3X58Jki84uB5e2qFg337JYLfMEJOIFNx6qB2At QBG+fCU7QjCQofyt7m8Vg1u7kbXfnYnst6Q/gwd2uzn+fOFJgLE4HNPuYR7+3sL6EeFe V01x9BTD6bKxyN/uEazF0MWxrAtEU4M/9E8wz0zDzn+g7MPY72oB0sQ48TwJ+YoT/Ukz STvE+EswCSTj7mnjU09enUm++ZMsonT8Hi8u83a+NMMgtb15ZK1WBSET0hE42RSf6Rfa rBoA== X-Gm-Message-State: AKGB3mLD+8ZLyTEzvUq1qBXV+H6Iv759zrMoQT1qFettBxNz56RaLg0A FIMku8sFIeI5uYI3oIIvE6nF1Q== X-Google-Smtp-Source: ACJfBouEJpJUUdMQHBHJ2VYZzcgdPundRq9TjThFwGEVal/0iP82ivgMUBrfDmwnG9xA5yisSpqEfQ== X-Received: by 10.80.192.85 with SMTP id u21mr3850362edd.37.1513751075547; Tue, 19 Dec 2017 22:24:35 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:9881:a13:154c:d69f? (p200300EA8BC0E40098810A13154CD69F.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:9881:a13:154c:d69f]) by smtp.googlemail.com with ESMTPSA id e46sm16164830edb.93.2017.12.19.22.24.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 22:24:35 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v6 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: <5a66eaa1-9735-4b63-be66-b640f993bd21@gmail.com> Message-ID: <97e93fcd-155d-0742-3f2f-c481d2359c11@gmail.com> Date: Wed, 20 Dec 2017 07:24:11 +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: <5a66eaa1-9735-4b63-be66-b640f993bd21@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 --- v2: - use new function _i2c_new_dummy with detailed error codes v3: - no changes v4: - reflect renaming to __i2c_new_dummy v5: - improve readability by adding struct i2c_dummy_devres v6: - add braces to function name in documentation --- Documentation/driver-model/devres.txt | 3 +++ drivers/i2c/i2c-core-base.c | 45 +++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 3 +++ 3 files changed, 51 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index c180045eb..22a40deed 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 cb3f29fb8..4b05abbfa 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -864,6 +864,51 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) } EXPORT_SYMBOL_GPL(i2c_new_dummy); +struct i2c_dummy_devres { + struct i2c_client *client; +}; + +static void devm_i2c_release_dummy(struct device *dev, void *res) +{ + struct i2c_dummy_devres *this = res; + + i2c_unregister_device(this->client); +} + +/** + * 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_dummy_devres *dr; + struct i2c_client *client; + + dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL); + if (!dr) + return ERR_PTR(-ENOMEM); + + client = __i2c_new_dummy(adapter, address); + if (IS_ERR(client)) { + devres_free(dr); + } else { + dr->client = client; + devres_add(dev, dr); + } + + return client; +} +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 Wed Dec 20 06:24:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 851270 X-Patchwork-Delegate: bartekgola@gmail.com 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="IROPToO4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z1lB56Ftzz9sCZ for ; Wed, 20 Dec 2017 17:25:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932316AbdLTGY6 (ORCPT ); Wed, 20 Dec 2017 01:24:58 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:42755 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754405AbdLTGYi (ORCPT ); Wed, 20 Dec 2017 01:24:38 -0500 Received: by mail-wm0-f66.google.com with SMTP id b199so7704125wme.1; Tue, 19 Dec 2017 22:24:38 -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=CtnrejcVAjSPqvc2iEqP4WFgLWMR7XjmGEwIeMaJb1k=; b=IROPToO4Q0uGQAAgLzJUuduywGgr2U8Z5Hm1YkjlMOrs+cqFgqqItp/ph7qIaORRAk Ek8ax7mhMoT4c1Y4O+CY3bjUPJ+6vgf5Y+xxKbzKRkH6Yd11TrbhwIigniF8e24Zhpz9 XCzuqiys700sf6+NPFj0aorIdhWgS9yX/zL1ppQzcPeyCMizh1eVQFEhtGlGbj0P4vFK pg9XJs4cTSevbTFDIrJ66uJ3Q9yK4i1E7C9OIT/wCtzZA+qoqwZBE6YOb/xU/MD0Dkjt ly2otPV5K7GMHcFryovOeoFg/1fAJ83+NgN8O3f6R8rw6zi3HDGf4pqoJScKYSUiuYzj l6+w== 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=CtnrejcVAjSPqvc2iEqP4WFgLWMR7XjmGEwIeMaJb1k=; b=MxN3MEjptMY1MyRaS8fdJYbESPp3gd2zRwTndTwuxAi8939yYDavZbb0LFFtQp+nsr 2MZoZEzUBzsudBvx+/2A8gPfCsKWnQ/Joi8BGbsjX8MeVLCsTflIXiZTmj9FvxdLDTb1 EhSusWobN3WiTNrdG0OTMh+sn5zI6VCEbf7F958s6wLUhWxIYNg01Jj2cvxPEohXqEhR PG2E+fA00N3Ic1A/EZxoI3+/4V52i6MGj7uua2ta7vJ/edmcF0OBbEw+zBGn9pV1J8Em N+SB7bcwR5gbGoowsJqcYNIMR5drZgl+cnQQBeeZY9E4Q98wi6ZCMKbrNlIts7d5EkxW UYVw== X-Gm-Message-State: AKGB3mJ4RG4rUr5jW/Sib4z/CLlcFBrTXZ4ReWKh1NK+pYh8JabsTtHv e7iUNMuP38RchxS3PJxybUaMYg== X-Google-Smtp-Source: ACJfBotYu4z231i/qudXHuA0WPzcJ6m7e0KEn0+oqcc7ykh8G66ehLJmSfv9gXWmcn621GK4vhUrQA== X-Received: by 10.80.215.29 with SMTP id t29mr3899648edi.45.1513751077155; Tue, 19 Dec 2017 22:24:37 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:9881:a13:154c:d69f? (p200300EA8BC0E40098810A13154CD69F.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:9881:a13:154c:d69f]) by smtp.googlemail.com with ESMTPSA id a16sm14900164edd.19.2017.12.19.22.24.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 22:24:36 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v6 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: <5a66eaa1-9735-4b63-be66-b640f993bd21@gmail.com> Message-ID: Date: Wed, 20 Dec 2017 07:24:25 +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: <5a66eaa1-9735-4b63-be66-b640f993bd21@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 v5: - no changes v6: - rebased --- drivers/misc/eeprom/at24.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index b44a3d2b2..6232765bb 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -626,21 +626,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, - ®map_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, ®map_config); + if (IS_ERR(cl->regmap)) + return PTR_ERR(cl->regmap); } i2c_set_clientdata(client, at24); @@ -692,10 +690,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; @@ -704,15 +698,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);