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);