From patchwork Thu Nov 30 06:49: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: 842915 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="S5SAWtsu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgQ5Tfnz9sCZ for ; Thu, 30 Nov 2017 17:49:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753073AbdK3GtW (ORCPT ); Thu, 30 Nov 2017 01:49:22 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:43178 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753068AbdK3GtV (ORCPT ); Thu, 30 Nov 2017 01:49:21 -0500 Received: by mail-wm0-f67.google.com with SMTP id i71so10847912wmf.2 for ; Wed, 29 Nov 2017 22:49:20 -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=pNmCM35JALNqYnFb/di/ot4cWVH5kV8M3XY8OAh8cm4=; b=S5SAWtsu8MrJ7RHnkziFE0QndOieI3OjiwGshEwnpuCC3zhYYnBfe+b0cvy8oWZKJ0 MgUx2Dh3vBDXzr/1zCZWw866qYLPvxFbVjCJmpFRbHItoHq5oaGkLjvbkt6E2kdLmI++ 0p8uZ0mASyphbb+b5ZW9m9JoBCLJvOnE8Pu2FnoQD0eQiWicbnEOUJFwo8n4IwpJXPdc V97qVgEionJUVzQARvVv4BgweZh4Lp9yzYsvJK46t4H7G3IrpB/QnvzEmzKrZjGTPOKz AbSp049xNo7ZAksIc6/QCdG/SoW49/Y+CWhpv3fpTJB9nlYKo+EO7XW8cKjSEOUGK/6w +s3w== 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=pNmCM35JALNqYnFb/di/ot4cWVH5kV8M3XY8OAh8cm4=; b=fyn/jbdfNrYMCFiSSOsDCIVxcVwkhvF16of0RYyogf1IZPBVV1kOPJxsZo3cK/+Tyo OahC80UFTYlbj7xaanEeCfuYeeoKTIbRiyXiuQJkZx4ONsQhFtPkhH+y4OLkp+MrRuCd mQW8/7HvG9X0rC/6dcJHXLkSkj0jlyzzYgv1INi/xhxhX99KCIIDQz0FjN60RHZj2PiJ 5wo1N5BEe9YXmkoNyOhbuvQTS3YOMMZdc3h5R90fMslrsuw+Hb4n1FZbROxDJQaRgd9M y8O/b/V7050SyED9VbWlJhG9ibuGktBIR0q1AWfLZbqc90b9jnswuuounsUTCZAzGZ1A t3tQ== X-Gm-Message-State: AJaThX5RGlXdkEwPcxToJUK3y+SPuX1Mt5v7jlYhDFczP5Zkqt3KfhQc o3FKsBabWn40stxNnv+e/J7HBA== X-Google-Smtp-Source: AGs4zMb7gkAoro7Q1yh2hQttWjl1glsaiUo09cBxcE51BX6jLek782f9H+1+Sz8IdiU6Tf1vC4jkGA== X-Received: by 10.80.185.67 with SMTP id m61mr5454222ede.239.1512024559743; Wed, 29 Nov 2017 22:49:19 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:18fb:3267:4d37:78c7? (p200300EA8BC0E40018FB32674D3778C7.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:18fb:3267:4d37:78c7]) by smtp.googlemail.com with ESMTPSA id g25sm2609991edc.68.2017.11.29.22.49.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:19 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 3/7] eeprom: at24: simplify probe a little by replacing &client->dev To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 30 Nov 2017 07:49: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: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org We have lots of places in probe where &client->dev is used, replace it with a variable to simplify code a little. In addition remove redundant check for client->dev.of_node when using of_match_device, this function can deal with a NULL of_node. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 48 +++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 90fefd1cf..d56be71f1 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -511,26 +511,25 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) int err; unsigned i, num_addresses; const struct regmap_config *config; + struct device *dev = &client->dev; u8 test_byte; - if (client->dev.platform_data) { - chip = *(struct at24_platform_data *)client->dev.platform_data; + if (dev->platform_data) { + chip = *(struct at24_platform_data *)dev->platform_data; } else { /* * The I2C core allows OF nodes compatibles to match against the * I2C device ID table as a fallback, so check not only if an OF * node is present but also if it matches an OF device ID entry. */ - if (client->dev.of_node && - of_match_device(at24_of_match, &client->dev)) { - magic = (kernel_ulong_t) - of_device_get_match_data(&client->dev); + if (of_match_device(at24_of_match, dev)) { + magic = (kernel_ulong_t) of_device_get_match_data(dev); } else if (id) { magic = id->driver_data; } else { const struct acpi_device_id *aid; - aid = acpi_match_device(at24_acpi_ids, &client->dev); + aid = acpi_match_device(at24_acpi_ids, dev); if (aid) magic = aid->driver_data; } @@ -541,7 +540,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) magic >>= AT24_SIZE_BYTELEN; chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); - at24_get_pdata(&client->dev, &chip); + at24_get_pdata(dev, &chip); chip.setup = NULL; chip.context = NULL; @@ -552,15 +551,13 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.flags |= AT24_FLAG_READONLY; if (!is_power_of_2(chip.byte_len)) - dev_warn(&client->dev, - "byte_len looks suspicious (no power of 2)!\n"); + dev_warn(dev, "byte_len looks suspicious (no power of 2)!\n"); if (!chip.page_size) { - dev_err(&client->dev, "page_size must not be 0!\n"); + dev_err(dev, "page_size must not be 0!\n"); return -EINVAL; } if (!is_power_of_2(chip.page_size)) - dev_warn(&client->dev, - "page_size looks suspicious (no power of 2)!\n"); + dev_warn(dev, "page_size looks suspicious (no power of 2)!\n"); /* * REVISIT: the size of the EUI-48 byte array is 6 in at24mac402, while @@ -588,7 +585,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) else config = ®map_config_8; - at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + + at24 = devm_kzalloc(dev, sizeof(struct at24_data) + num_addresses * sizeof(struct at24_client), GFP_KERNEL); if (!at24) return -ENOMEM; @@ -604,8 +601,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) return PTR_ERR(at24->client[0].regmap); if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { - dev_err(&client->dev, - "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); + dev_err(dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); return -EINVAL; } @@ -622,8 +618,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->client[i].client = i2c_new_dummy(client->adapter, client->addr + i); if (!at24->client[i].client) { - dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); + dev_err(dev, "address 0x%02x unavailable\n", + client->addr + i); err = -EADDRINUSE; goto err_clients; } @@ -638,27 +634,27 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) i2c_set_clientdata(client, at24); /* enable runtime pm */ - pm_runtime_set_active(&client->dev); - pm_runtime_enable(&client->dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); /* * Perform a one-byte test read to verify that the * chip is functional. */ err = at24_read(at24, 0, &test_byte, 1); - pm_runtime_idle(&client->dev); + pm_runtime_idle(dev); if (err) { err = -ENODEV; goto err_clients; } - at24->nvmem_config.name = dev_name(&client->dev); - at24->nvmem_config.dev = &client->dev; + at24->nvmem_config.name = dev_name(dev); + at24->nvmem_config.dev = dev; at24->nvmem_config.read_only = !writable; at24->nvmem_config.root_only = true; at24->nvmem_config.owner = THIS_MODULE; at24->nvmem_config.compat = true; - at24->nvmem_config.base_dev = &client->dev; + at24->nvmem_config.base_dev = dev; at24->nvmem_config.reg_read = at24_read; at24->nvmem_config.reg_write = at24_write; at24->nvmem_config.priv = at24; @@ -673,7 +669,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) goto err_clients; } - dev_info(&client->dev, "%u byte %s EEPROM, %s, %u bytes/write\n", + dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", chip.byte_len, client->name, writable ? "writable" : "read-only", at24->write_max); @@ -688,7 +684,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (at24->client[i].client) i2c_unregister_device(at24->client[i].client); - pm_runtime_disable(&client->dev); + pm_runtime_disable(dev); return err; }