From patchwork Fri Dec 15 23:05:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849416 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="NRzsyZLC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yz5gL0q2jz9s7m for ; Sat, 16 Dec 2017 10:07:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756368AbdLOXHk (ORCPT ); Fri, 15 Dec 2017 18:07:40 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37659 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755848AbdLOXHj (ORCPT ); Fri, 15 Dec 2017 18:07:39 -0500 Received: by mail-wm0-f66.google.com with SMTP id f140so20245755wmd.2; Fri, 15 Dec 2017 15:07: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=ztDjaaQ/Ihiv/lfKnTzKXlcRvdUvASdC4x2+DNnc99s=; b=NRzsyZLCoj6/5ukBM2L3ZZjns1PMqMvB3nVMiie+RqCCmgS4MkaDmC/GZVQLafQO6W n75Njix7jdB/jk/jHSvUzaZ/peSeo6uILxaxV/FD9k/rPMcwWL0YqIGLIlWe87JpwRl+ AgCCdlPKtT7PpQEJvw7CgRZ0fiZh0m8vFUXC9e4dJtKP3KI+X/XimiCqvTPZzoEtEQ7u jbijuh3ei8/Rk9GfPDOsNj5Nh0nicY+mJAZc5l9bJ2D4+0hw4z0BdxyXvOb4VDcNGVyH +cDh/8wNowFvgqrnVCOOWb9SBSj/EjWRIrWbjCWp+2vh5l5kSgkTka0uOPFVdiuYVSfa wBcA== 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=ztDjaaQ/Ihiv/lfKnTzKXlcRvdUvASdC4x2+DNnc99s=; b=H4z5sWzUlIBUwn1vgsL4vso5BBHR0ut6FiLJkW9sA8IP2xkmPj9zfOpd/hBLd2b7Il tpH7alIfH9Jcn8l7YQjyOtClutKe6APrZJ5+XLnT6HXF7h0uq06dbKSV4kmNCrM5Whpg trT3aHX+goqK7mT3afbSwDSMu5IRktxc4WH00ivb9I06LJ+3Z0m9TzQCO/HBzYJSVqoj FLpkua4gCe3W8PNTeRPcDJZWH7Nt+FlrGbkAH9Di7zcCyrCpIdhPzObYl3wB291km0z+ 7o/3EgFAuwdJeJ8knPJrGa2w1xZUNlV+icIxg9wr636TEUMuuJwjCJ7afig6NAc96znh bsoQ== X-Gm-Message-State: AKGB3mJmdWpxH7MtxkSBg149xJYAzsZgddu3oaln8LbPqh8y6A+QnHch ptr5IFMznGwbAuxfJfeVUNNYSQ== X-Google-Smtp-Source: ACJfBosM0SuwVC3m827D8AwnWtb+njW9bguGrYC+Ut2QJ1Tm4qMJRXOevB82YWSl2/RDOn0nJ+KvNA== X-Received: by 10.28.65.65 with SMTP id o62mr6924365wma.112.1513379257706; Fri, 15 Dec 2017 15:07:37 -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 q32sm4443989wrb.95.2017.12.15.15.07.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 15:07:37 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 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: Message-ID: <47a92255-982c-8e91-9774-2004509a1dd6@gmail.com> Date: Sat, 16 Dec 2017 00:05:27 +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: 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 --- 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 Fri Dec 15 23:05:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849418 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="G2jwGpLP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yz5gx20sTz9s7m for ; Sat, 16 Dec 2017 10:08:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755824AbdLOXIM (ORCPT ); Fri, 15 Dec 2017 18:08:12 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33036 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755978AbdLOXHk (ORCPT ); Fri, 15 Dec 2017 18:07:40 -0500 Received: by mail-wm0-f66.google.com with SMTP id g130so32575421wme.0; Fri, 15 Dec 2017 15:07:40 -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=UnJ/TN7xtb5Snq8v954nqoK3SyYeTnKVt2b/93NPxY0=; b=G2jwGpLP+VC3sH6aNxIqpu80kD7Kkvt5ILxYLdNm061AD5dc4Jx2oIZez7VsVKv70C 9vGEdSSKMRahpKvCQfGsx9kTaJEWMGfESlwfxIyw7SXlnnzocKYMWQrc24CiW0q4anD8 SKVYNRGkzO+XtS7H+ECc86SJ9Pzd63ccNqzWIHbDClPyYBe30mYDUemG4aWPmnIIGddE KLZXgdrhOLZ+HvC3hRpofQUCq7fd8SMb9wXlDGDxcPH0QIKwSpxVIMr/5anFYjg0zxiG swBPWUB/kKQIB5ricW8cPT4b1Vs8xBedC7VM8O/xgurfCO93uyVaqqClAjbGLFC36qro O6xQ== 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=UnJ/TN7xtb5Snq8v954nqoK3SyYeTnKVt2b/93NPxY0=; b=ZZXmio9x+JVS+BRiK8aezhYR0fiLweArG+eiMODVT0FQoganK6x+Zir3VmKQk3lu6U j9nTBdMiYgVuSyfoJU3TJP1CPgtuqDP82yVLwUbEoNPOW7Lqex7crqlN/Kj2VNkjzyuq af0LiNuMNDUVXlGHXECLCHk3uuE+ZVyWObIfJVh0caDoL5Iwe130LUMhffeXGzyKserM XoDi+r0zQlZ0vW7NJMHuZ239PePL7j9PZUWUcG1UCJWehNgmW65YOFokxmreQ7rl+WFK 2MSG09PzafUu1D1/Qyiz7M3J3R6e/221OE78aOj/s0zcmip8ZOIbd+A6iTG/yjAfOYDr phIg== X-Gm-Message-State: AKGB3mLHC/TyHD6bsbgD+5dE4xyuk7uhgnn1AxTfzHredS4gNIqoHOua +7RJ3lJPUQzfZYebTEfy2Ubkvw== X-Google-Smtp-Source: ACJfBou5qI6cttEZ/7gGxYbaHFxMOOvXTmjLMhlrYlaCFQOG+mD4oeez6jqxlyInPRZbztVwRhpsgw== X-Received: by 10.28.105.14 with SMTP id e14mr6050878wmc.74.1513379259103; Fri, 15 Dec 2017 15:07:39 -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 38sm7933230wry.34.2017.12.15.15.07.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 15:07:38 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 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: Message-ID: Date: Sat, 16 Dec 2017 00:05:42 +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: 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 v5: - improve readability by adding struct i2c_dummy_devres --- 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..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 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 Fri Dec 15 23:07:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 849417 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="Um8nLuCW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yz5gl4F9Dz9s7v for ; Sat, 16 Dec 2017 10:08:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756711AbdLOXHr (ORCPT ); Fri, 15 Dec 2017 18:07:47 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:35076 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756528AbdLOXHm (ORCPT ); Fri, 15 Dec 2017 18:07:42 -0500 Received: by mail-wr0-f193.google.com with SMTP id z104so367219wrb.2; Fri, 15 Dec 2017 15:07:41 -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=W9jtJLLTySOai3R5d9W2E9HtAJAIlVg4oH3GcWr8sqc=; b=Um8nLuCWpM0LkFacEcsHk7CHVDlbd+XQ1ORwIURCUqUxOtBne1VxyEpwGLYKFXuSyQ yuSR7/+/a277Z1wwIngZPgBboRBpD2TzBLbsbC9GfKYJcI7YhxIt2uge9v6s0NwWf9dr T+RSWNPYXf9twt/q/dZqfwXx+64gGd4MmcmVr6OEyapt9x9beYQg7VhuOs5ogln/FlZG qqGqtCAkjB5Cyi0nTHF6bpJ/uAMQGAG/PPZwxmPJvDsSt/0DpBgg+HkkTFwRm+NE0FOB LO6QJqiOx9YuM8vw7qFkqRlp2bkOWJMOffBf1WyYY3fZ7gudZCoJfvkrVMDBCsM1uMdn XIAg== 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=W9jtJLLTySOai3R5d9W2E9HtAJAIlVg4oH3GcWr8sqc=; b=crIRa8r8jjUXh+94DT2+rV91JJba0kmykbUNsfMCGuNrJOReSjwDKhHSeqtwEgWIDY 86EoO5cw+K0kw19xCvX5MVswcDweJwNhXPjKEy4qSrs8nAnoJFRCp1m+QhoBpLl8Oby7 wYLJFXTDXfdQX18mSJ2tLTj8pREVauTys+Blt553PD80f5Y2PXoU4BRzXcRwoXY+ra+W WCA/v/2xkkZ5t5qX5LTqKSS5wzrYCYyMmzIKarWundg6HNQsZRxI3xJGWslMjeLiHko8 bVoyYiDfm8E0T5DTUpsfUIg/I4EzPK62u+4+jC445EcPiP24bpUCl3AGPIXQtKdSm7b9 yIcA== X-Gm-Message-State: AKGB3mLEjTM2V5+yPpzYieIiHFQjtNoi7OYJhGHNmtE0vNybrG3ln4Ua 1ODjqkSpqVnuymtVrBU43k6d/g== X-Google-Smtp-Source: ACJfBouRVxdWYII4l1h7etGROchBs/PruQyb3JOiBt97rqvXVJaVMRGhxHvpE97vI18bCm0e9pcRaA== X-Received: by 10.223.202.1 with SMTP id o1mr11383833wrh.233.1513379260625; Fri, 15 Dec 2017 15:07:40 -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 u79sm3662478wma.26.2017.12.15.15.07.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 15:07:40 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v5 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: Message-ID: <1a7cd44c-529a-6bbd-c07c-19d3f93a73c1@gmail.com> Date: Sat, 16 Dec 2017 00:07:18 +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: 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 --- v2: - small improvements regarding code readability v3: - no changes v4: - no changes v5: - 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 848fda8be..fce00fbe4 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -636,20 +636,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); @@ -701,10 +700,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; @@ -713,15 +708,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);