From patchwork Thu Nov 30 06:48:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842913 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="C4apzAvL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgN3Kpvz9sCZ for ; Thu, 30 Nov 2017 17:49:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753052AbdK3GtT (ORCPT ); Thu, 30 Nov 2017 01:49:19 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:44846 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753030AbdK3GtS (ORCPT ); Thu, 30 Nov 2017 01:49:18 -0500 Received: by mail-wm0-f65.google.com with SMTP id t8so10816899wmc.3 for ; Wed, 29 Nov 2017 22:49:17 -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=pvFnvXL5hCyHXMs3UxhayF/1q9jk1zYSVyFQrI5CzrM=; b=C4apzAvLrdg9X9OLRhl0jQiXuiR+f4k/KChzoky8oZRRnu9bH6pWIOFvoDzYbwfKYD 22yxf8aIms1332CqO8J3VPu2wnmMFSxHO65em18jDPbZBY6YuWihpT1FU7XN4+wx50Tf TBUxBPuFBqM6dfPTesv4gs+IBO8mlKrpPt5O0b+ez7Gpb5R97dC5hIr7CcH6vZkxXbfF kwelxs3D4vD22cGbb7nEN/jQmJurq9VVCXm2Sp27LvsY/ToyfFlxQkXa025CgWSQMvlI BxtPUxF8CBmqUErVgpD5xEH0tfsZoa40a1GFZFYaI1uHIgvrtopOfu1VAzHiuhVpKkG6 czuA== 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=pvFnvXL5hCyHXMs3UxhayF/1q9jk1zYSVyFQrI5CzrM=; b=aYXx/whxkmFEGPMG8ubHm6AqBn6sWXipa2ie6LxlxsfKcecYRKPD5wIsDvqVn+nypp rRBUp5sKXmddBXX5L6vksIp+abIbFq7iasoqcsimEecvPR0+6J9haJQJubMNoMuRdDbs W9i0tDsk5SdBTmsHVdYYoFxc3D6qd2SlkGDP8KHhMfM/1rEpfB4ooOzU7WHrvOQxhL21 TFcOHkesh0AOktntI+Cg/kPWxnW0d0/y/ap0S9NR/d3M7kbmjGKeTxQ9XjRYuUA5iJ5y oF07lXoDsKCfAE2ZeHyXZV5HVn7EqjxijylaNeVkgdy2o/f1ranbtdFbD1RZN3ObZXBW YPlA== X-Gm-Message-State: AJaThX4a6Nig0XBcFSAiKrTdokqRj8UwOU/j5dFgsNmYLq/Z07pSKrT2 NSsSYNMTh976ONrYs+1s92qPTg== X-Google-Smtp-Source: AGs4zMbfP1DzuCAiigOOEk7TpWYnwvhDaIYMf3j4IStgkKbGZF3wSccaE4gqlTMG9x0bjjz6HdvOrw== X-Received: by 10.80.203.12 with SMTP id g12mr11573400edi.14.1512024557109; Wed, 29 Nov 2017 22:49:17 -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 e49sm2975778eda.90.2017.11.29.22.49.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:16 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 1/7] eeprom: at24: don't explicitely include header files which are implicitely included To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <5fd1ad39-db94-e774-b77c-8081bfed7817@gmail.com> Date: Thu, 30 Nov 2017 07:48:58 +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 Don't explicitely include header files which are implicitely included. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index cd87f1b21..c75bb9b45 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -10,15 +10,10 @@ * (at your option) any later version. */ #include -#include #include #include #include #include -#include -#include -#include -#include #include #include #include From patchwork Thu Nov 30 06:49:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842914 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="WxJEYkah"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgP3MrBz9sMN for ; Thu, 30 Nov 2017 17:49:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753058AbdK3GtU (ORCPT ); Thu, 30 Nov 2017 01:49:20 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35062 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753030AbdK3GtT (ORCPT ); Thu, 30 Nov 2017 01:49:19 -0500 Received: by mail-wm0-f65.google.com with SMTP id f9so10342992wmh.0 for ; Wed, 29 Nov 2017 22:49:19 -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=/of3BwygMJmdFK3exgtde6lJ+DpCt4qys7f/wdjXG/4=; b=WxJEYkahXUzk4IjfYpoWAa0FGPxAqkW8bmsgvPgdnBPPxUkXz/pViwBIhvXN2CNe4N 5+etYAJ0gmaIZKjLGPYomXlYK7CxCru8NLY5PBNvKShNHujyZPmq6a1P9nD0/5yVT3qD uLy0L/IHYXK5Cc/nXO0Zy0KdG6RCbPTiP8IL6FsrDykN74/8OcaXpL4LEq6+KJ02+yOI 8WHhUafuIhcvJF4nXvAyr733gewoUj3kqZtNoEEG+fW8Zg0sIysRIzoHvLicdQHFkddt p0HQtLV2k2av9cuNvhW6xVEVUUx2kDnO7KSh/XQefUcuvkQot0u73pA0PRcgPOl/MbRh UOHw== 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=/of3BwygMJmdFK3exgtde6lJ+DpCt4qys7f/wdjXG/4=; b=UClBvtRNd7zDd4+9mIMLuAToXKdft0XPeM67RBcQ+1JBV2duS+4SXhJC5+VnmX6ytw YKO+HmpXkTnCKrCFCsal4AI+FYslM0wLPslHUq7ARGp91MlWRk9uJKCfwXovzjqmvnp6 zSUi3ErUMo/+NUcpfiFIpsG/16+g1751ULuZQ79I5Zj3Hd1a9AQ1okTwp5YgWT9ldIbj V2VSwN8H4iJZqoeXfb67LAPYcoQGQLFGKONIB+IHAP5IrKH6pZUwMDsKmsi9xalNLWWI 3az786qznHuAJzSr3CTpB/XvZ9vYbWQNkYkagKWmR9MUl0mBZPwnao6TvQ5SaLMBXyFJ nMUQ== X-Gm-Message-State: AJaThX41eD5TzeSqLs5Q4NO5oBdMvzLO22X2nrx+wNFm7qLBOaO9aTaN aUQWbt/sEcnvDn2pfazrJr9HOw== X-Google-Smtp-Source: AGs4zMYlOoEitUbPQKTdpldcLfB0xj05zR7Gt0oVJNhp5c85Q69EvujyWtvMyHAdEFGhwksSHAiROQ== X-Received: by 10.80.136.124 with SMTP id c57mr11198808edc.191.1512024558441; Wed, 29 Nov 2017 22:49:18 -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 j3sm2612596edh.55.2017.11.29.22.49.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:18 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 2/7] eeprom: at24: consider that SERIAL and MAC flags imply read-only To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 30 Nov 2017 07:49:00 +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 Flags AT24_FLAG_SERIAL and AT24_FLAG_MAC imply read-only. Therefore handle this in the code instead of specifying AT24_FLAG_READONLY in the config data in these cases. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index c75bb9b45..90fefd1cf 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -131,38 +131,29 @@ static const struct i2c_device_id at24_ids[] = { { "24c00", AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) }, /* old variants can't be handled with this generic entry! */ { "24c01", AT24_DEVICE_MAGIC(1024 / 8, 0) }, - { "24cs01", AT24_DEVICE_MAGIC(16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, + { "24cs01", AT24_DEVICE_MAGIC(16, AT24_FLAG_SERIAL) }, { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) }, - { "24cs02", AT24_DEVICE_MAGIC(16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, - { "24mac402", AT24_DEVICE_MAGIC(48 / 8, - AT24_FLAG_MAC | AT24_FLAG_READONLY) }, - { "24mac602", AT24_DEVICE_MAGIC(64 / 8, - AT24_FLAG_MAC | AT24_FLAG_READONLY) }, + { "24cs02", AT24_DEVICE_MAGIC(16, AT24_FLAG_SERIAL) }, + { "24mac402", AT24_DEVICE_MAGIC(48 / 8, AT24_FLAG_MAC) }, + { "24mac602", AT24_DEVICE_MAGIC(64 / 8, AT24_FLAG_MAC) }, /* spd is a 24c02 in memory DIMMs */ { "spd", AT24_DEVICE_MAGIC(2048 / 8, AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, { "24c04", AT24_DEVICE_MAGIC(4096 / 8, 0) }, - { "24cs04", AT24_DEVICE_MAGIC(16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, + { "24cs04", AT24_DEVICE_MAGIC(16, AT24_FLAG_SERIAL) }, /* 24rf08 quirk is handled at i2c-core */ { "24c08", AT24_DEVICE_MAGIC(8192 / 8, 0) }, - { "24cs08", AT24_DEVICE_MAGIC(16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, + { "24cs08", AT24_DEVICE_MAGIC(16, AT24_FLAG_SERIAL) }, { "24c16", AT24_DEVICE_MAGIC(16384 / 8, 0) }, - { "24cs16", AT24_DEVICE_MAGIC(16, - AT24_FLAG_SERIAL | AT24_FLAG_READONLY) }, + { "24cs16", AT24_DEVICE_MAGIC(16, AT24_FLAG_SERIAL) }, { "24c32", AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) }, { "24cs32", AT24_DEVICE_MAGIC(16, AT24_FLAG_ADDR16 | - AT24_FLAG_SERIAL | - AT24_FLAG_READONLY) }, + AT24_FLAG_SERIAL) }, { "24c64", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) }, { "24cs64", AT24_DEVICE_MAGIC(16, AT24_FLAG_ADDR16 | - AT24_FLAG_SERIAL | - AT24_FLAG_READONLY) }, + AT24_FLAG_SERIAL) }, { "24c128", AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) }, { "24c256", AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) }, { "24c512", AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) }, @@ -556,6 +547,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.context = NULL; } + /* both flags imply read-only */ + if (chip.flags & AT24_FLAG_SERIAL || chip.flags & AT24_FLAG_MAC) + 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"); 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; } From patchwork Thu Nov 30 06:49:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842916 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="hBZOPp8z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgR6tQwz9sCZ for ; Thu, 30 Nov 2017 17:49:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753128AbdK3GtX (ORCPT ); Thu, 30 Nov 2017 01:49:23 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37323 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753072AbdK3GtW (ORCPT ); Thu, 30 Nov 2017 01:49:22 -0500 Received: by mail-wm0-f65.google.com with SMTP id f140so10271166wmd.2 for ; Wed, 29 Nov 2017 22:49:21 -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=DQEOBqKOv0bNJcPCaddE6YoOVkGULxrP4HP0MzSayfM=; b=hBZOPp8zmUeRlcP+5fqAnQv1w9TP75pGmxSsZtnvomM/rKeKXahUNv7YABc1swOw5Q 8H1RaAxa/4m+E3BEtbN0TQBxowqwz6FtFrdXXVkBiBebE0in+rKYorbdO6EQTbGEOHhp fHmPcZjwhZu9+dohS6kzB84QdLYyO6x1pP7E/q6rQndwN8ZwUYN5qiVIjdlsWlI7067Q Upi8BvzXs9FjXw5uNJ2W4FurNq02bEwgB9TCMn19cJn7WRYjz7KiWFwbo61mJv4SPolH yIh8SFkaSJz6W21OdiAPzNQJWsvU9pFQElC9HJJcTkjbDko2VL5ZePa31z0PM9ELaV0w FxFg== 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=DQEOBqKOv0bNJcPCaddE6YoOVkGULxrP4HP0MzSayfM=; b=YJ9hDpf21UqiqWNLVbzV9qvdaFlnliH0/OYghIk0p73z5HjViqXC2167KSLX1x46Wz HNMp8HF33ladm0DxgHgmAdA2Q8MAz0KvHTWsDYUhfdCQafKpaaXpZz9zjV3ljcCrGnQ9 XNAdnX1ucypXyWoNrZhDrDDN7/0y65n9OWHdVuja3UG4j0zFPBCbY36d/qNYpcoh53cU F/43BgQ65NMOR9lZXKDPq021BIn2fAx75p7au40wXpa/sCP947VAt5lAx23a1FW8EqbC fKxC8OuOThBFOOaqxsCO46yD0y/AWoQbBe6LUcnqFiPVNegGgtVA7J/NqyY5WA+1clWp rHOQ== X-Gm-Message-State: AJaThX4sMuWTvcsSV5pmGcPVaqGg/aJSJurPd8Rx4bCd1g7ePFEqvn0j LpXvYq8InV2mIxoS3WVfKJtabw== X-Google-Smtp-Source: AGs4zMaLn+8Vw5QncOGpSEJyvO22pXZmDuusoNMw4TSbZSOxuNPHOiGiviMYZ14A4u5A6QkHoAs+Yw== X-Received: by 10.80.182.118 with SMTP id c51mr11634701ede.204.1512024561090; Wed, 29 Nov 2017 22:49:21 -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 s6sm2634147edd.23.2017.11.29.22.49.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:20 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 4/7] eeprom: at24: simplify functions at24_read/write a little To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <1b2f8ac8-02ae-d615-8c23-6d90f52be555@gmail.com> Date: Thu, 30 Nov 2017 07:49:06 +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 Simplify functions at24_read/write a little. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index d56be71f1..837f1d88c 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -374,24 +374,20 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) mutex_lock(&at24->lock); while (count) { - int status; + ret = at24_regmap_read(at24, buf, off, count); + if (ret < 0) + goto out; - status = at24_regmap_read(at24, buf, off, count); - if (status < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(&client->dev); - return status; - } - buf += status; - off += status; - count -= status; + buf += ret; + off += ret; + count -= ret; } - +out: mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); - return 0; + return ret < 0 ? ret : 0; } static int at24_write(void *priv, unsigned int off, void *val, size_t count) @@ -424,24 +420,20 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) mutex_lock(&at24->lock); while (count) { - int status; + ret = at24_regmap_write(at24, buf, off, count); + if (ret < 0) + goto out; - status = at24_regmap_write(at24, buf, off, count); - if (status < 0) { - mutex_unlock(&at24->lock); - pm_runtime_put(&client->dev); - return status; - } - buf += status; - off += status; - count -= status; + buf += ret; + off += ret; + count -= ret; } - +out: mutex_unlock(&at24->lock); pm_runtime_put(&client->dev); - return 0; + return ret < 0 ? ret : 0; } static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip) From patchwork Thu Nov 30 06:49:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842917 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="ZQNHv9Me"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgT5lldz9sCZ for ; Thu, 30 Nov 2017 17:49:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753151AbdK3GtY (ORCPT ); Thu, 30 Nov 2017 01:49:24 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:41287 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753145AbdK3GtX (ORCPT ); Thu, 30 Nov 2017 01:49:23 -0500 Received: by mail-wm0-f65.google.com with SMTP id g75so10958693wme.0 for ; Wed, 29 Nov 2017 22:49:23 -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=GT6KbsABCOquZdM1yPYiO1nbu20vxqOKUn0o1exR3Jo=; b=ZQNHv9MeBKmWJAv22G2x+Lg/A5Ec/qDzQczncNqv8ZrmZGClPfd/6WAJSZqzyTzz83 bPF6jgFGMcV1CiSNdIXmdCO40QzDDW5vPj9rmKoB1btWoZFtXdPFkbwBDZ1UH9TVloNc rtooTWeudSK7/lQ0ymEYv5qyKGVH+zI516z5YupTVrJ/ENEwgrU6wUU2KOIT6wKKkVsn DN09TkW0yxMAkB6DltaFu3q19JB+114L33LITYpGqEArxVI4UMlWt5Wv6tAbbOuppkqg YRdnj3W/1L4o4EJE9CJDkwg7pqmHxOHj+/Vi3F1Pj9nSG+D6VSeboeTrbRuW2b5hBLFh j3vA== 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=GT6KbsABCOquZdM1yPYiO1nbu20vxqOKUn0o1exR3Jo=; b=NOYJ9eDzRcA4eS2beW9pk5zLruKq5NmuS04UfKnvUGxKwDMZVR1/wwrCN6VsCrkmUC +GxOeA0yj0pCcn78sOmIM4yYKyGBsP0CXg4O5/+xea4JXv6Cs778j5LGwRDWGzrK0rOp MzP9B4I8y8XhC8UIBAUKdtp5BhFei3veHBo0ycum1wVFGzeVgkaniOBK6FH7eSyJwLSZ ka25pVzCFOoNrfvE/E/4XfjQOse7n1QU/MiEmwneM94INa+/CAZ+zZ7RsEv+Rx0s7nm2 xaT+9Vaat3ZnpqbBNnEg1tuwFT/aSmmo+EBr2/qAyEKvwG5Db/8o8xRgD/Jg7Fb11t2v wqhw== X-Gm-Message-State: AJaThX7TaPv6Ni60ztHZ3FIz7FTXV4yasDuMdY+XuL2hv+J0ob0uF/au cQ/bNpt0X3JfSVkupJKlXuAONw== X-Google-Smtp-Source: AGs4zMZOrYmIDBM3U5IG2O0sFgDU3G33IVKyuYvQoFWSvweNJWDr8fZJJw2zavf+bh2KJasz/bGMgg== X-Received: by 10.80.149.152 with SMTP id w24mr11475884eda.76.1512024562345; Wed, 29 Nov 2017 22:49:22 -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 p45sm2969569edc.30.2017.11.29.22.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:21 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 5/7] eeprom: at24: zero-initialize variable chip in probe To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <0f7340b5-9766-debe-37b5-04b38e5344de@gmail.com> Date: Thu, 30 Nov 2017 07:49:08 +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 Zero-initialize variable chip to be on the safe side. This also allows ro remove some explicit NULL initializations. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 837f1d88c..8fef6d5a8 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -496,7 +496,7 @@ static const struct regmap_config regmap_config_16 = { static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct at24_platform_data chip; + struct at24_platform_data chip = {}; kernel_ulong_t magic = 0; bool writable; struct at24_data *at24; @@ -533,9 +533,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); at24_get_pdata(dev, &chip); - - chip.setup = NULL; - chip.context = NULL; } /* both flags imply read-only */ From patchwork Thu Nov 30 06:49:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842919 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="c0Bajic5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgc0Vqrz9sMN for ; Thu, 30 Nov 2017 17:49:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753072AbdK3Gt3 (ORCPT ); Thu, 30 Nov 2017 01:49:29 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:45771 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753068AbdK3GtY (ORCPT ); Thu, 30 Nov 2017 01:49:24 -0500 Received: by mail-wm0-f65.google.com with SMTP id 9so10814136wme.4 for ; Wed, 29 Nov 2017 22:49:24 -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=QIk8QproAJV3f4Pj2skgQXiNrX7yCCUoIRAReODOUUY=; b=c0Bajic52QR5RQk3+nKahc8RNxl69cMltwDcdlYf+pICPaaZIyA4E0DWif9o6UZcMU KQX2abqAu0TghiEkeXMriBeNKWH7sXF5vocJTZr4Tr/vp9sqSl3BI15aEKFNnv2/urOe oRchOaT4fsl5jLzdnsmyIpbrdglxdFlsAiKFdfYdxXZ6jt8nANK1THnqEIa3ZLFR54St /4WtmIj2QB96N0JED7LcM1saMoU+N+Y5RS/9kMkt/91NViSQTpX7TPfDX3LpfziDUu/L sxXFpU1ClV/L0P95ib1IUfWDfkih4T+UrFwh6djhY4hJl3fNTjHqLv78iA9wK71yn0nb f07A== 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=QIk8QproAJV3f4Pj2skgQXiNrX7yCCUoIRAReODOUUY=; b=OUORWUWo6OLMLkA2NCJLkHAUGnfgbsR6DQHFwoqBNMvcROnPzEFbaZTzKx8x8WZE9+ Ko8eNFHcRPjDp01xpb9wXjPceEccN3/WaGjMdBwUaNz8AJEhg4UggH7vnDVEJqpD/hET Lw+8bXnKXZNbzagNtHqM4G+YZuFLMRdviQqAVibBKB5rbrhoXiqer/2+0Lsyap41ryLI +yWjfL8jdtIsk0kq77JiZO+KB2e5f5UZgh5BPjjJX9DJ9HmpTTD5scxJfJ2lsnzZUL/R 8twwo7k/LJJgS1sHROd1yJ21cYwas3gT6/JRQBo9Z7rDYCHzxE4fAbKmmsByqfXT3myS SJJA== X-Gm-Message-State: AJaThX6aS/k/+EzNw5aZ3QJUMmbi39XjWFjW5BU2xVn48GI193+lXc3F ozAUEdIIA5F26cIndKsvez9xrQ== X-Google-Smtp-Source: AGs4zMZqxcXnZ75yzTNW2StEvco2DLDFOA7KDG/ZqPWRy6XuVGE1FSrxL2NfLNUNtsyYmzl46Uc1IA== X-Received: by 10.80.190.76 with SMTP id b12mr11413394edi.184.1512024563582; Wed, 29 Nov 2017 22:49:23 -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 i17sm2591497ede.64.2017.11.29.22.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:23 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 6/7] eeprom: at24: don't check chip.byte_len for power of two To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: Date: Thu, 30 Nov 2017 07:49:10 +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 When using AT24_FLAG_SERIAL and AT24_FLAG_MAC we expose just parts of the chip. These parts can have arbitrary size (e.g. a 6 byte MAC), so remove the check for power of two. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 8fef6d5a8..74d2347a1 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -539,8 +539,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (chip.flags & AT24_FLAG_SERIAL || chip.flags & AT24_FLAG_MAC) chip.flags |= AT24_FLAG_READONLY; - if (!is_power_of_2(chip.byte_len)) - dev_warn(dev, "byte_len looks suspicious (no power of 2)!\n"); if (!chip.page_size) { dev_err(dev, "page_size must not be 0!\n"); return -EINVAL; From patchwork Thu Nov 30 06:49:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 842918 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="sXhb3Hor"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynSgZ2Dj7z9sCZ for ; Thu, 30 Nov 2017 17:49:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753190AbdK3Gt2 (ORCPT ); Thu, 30 Nov 2017 01:49:28 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37333 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753072AbdK3Gt0 (ORCPT ); Thu, 30 Nov 2017 01:49:26 -0500 Received: by mail-wm0-f65.google.com with SMTP id f140so10271374wmd.2 for ; Wed, 29 Nov 2017 22:49:25 -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=mvv57WQRc2WB4FYcKo7sve9iwtCWXoj3D1uxi0fKCvE=; b=sXhb3HorIQ1EUpZEPDG6iNyNiyfJJQoGVVhtNCDtChpKYyZhch+L5taSGHa1mn/1NL EwwzB6gh4Ri9i7VY2L6cKW53Arqz+OuwhbyA8P3p+BEjAly1MkpamVuAXjWVDrUpcrcO cV1McilUF3SR/Bn2WP+npT884jibmKzvmoW3ABM9zgM2frNLLayfnfJtzuQbgVe5pezl asOX9TLzWBMJd8tEErBS7/+/FVLQw8FIep4rivI+Ns9eqaNp9jLuq+on3BMfP1aFxt6r UHD9Vxe41fm1Y+chlbveVvGvFWI1n9SBFrNufIC8UglLWQTyNXdAjFISwGyDWgV5s2ID rpug== 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=mvv57WQRc2WB4FYcKo7sve9iwtCWXoj3D1uxi0fKCvE=; b=eFspzthbtMU+41CDDqRFc/U0KP7O7UuOd/CVk1rkNa05Jp4yrrBlLkYO4B13y1GG34 gZ1DMlnxXFbCL0M95pyjCaAjkFiTK+Vx4cwVXc3KbD9+KUTpnVs6J4ySGki+4s6YFbd3 bSrxSoa7GckfbHuXjHyHKbe+NUPad2Ld9ePPkQ9Rkk4vBCb3hwNwDoBo6vhA4zkD4NCj l+D7Yo8wYhpzNHbdTMroTbuCWBu0GxKupxYWIgcFIJtzx56eTiuMtif4BjghJJqqPCda pTnBPmK6WnFRXG8c9lVaZe2yqYpZYTSXJum293TEaOf0B40V5rvVDxhSi2qf2T+uk2JY gZtQ== X-Gm-Message-State: AJaThX64QuiQDYEp6B/XpGwbLCHjyEQlmalzPDUef8j3+HHUUhi07Y0K /wFjLYtzVGE0w5Ntr08O7U47Nw== X-Google-Smtp-Source: AGs4zMZo5+oOENkjRTBn2VRteZ2IlIph16INE6U2fn6aKR1uBAs6/peD0ozlSZNzLUPpmhI5w4e4cg== X-Received: by 10.80.142.239 with SMTP id x44mr11321041edx.13.1512024564915; Wed, 29 Nov 2017 22:49:24 -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 h56sm3311819ede.15.2017.11.29.22.49.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 22:49:24 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 7/7] eeprom: at24: don't check page_size for read-only chips and reorder checks To: Bartosz Golaszewski Cc: "linux-i2c@vger.kernel.org" References: Message-ID: <314c04db-33b9-2cd2-c254-be7071cafdab@gmail.com> Date: Thu, 30 Nov 2017 07:49:13 +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 we check for a proper page_size value also for read-only chips where this value isn't used. Therefore remove these checks for read-only chips. In addition reorder checks to do sanity checking first. Signed-off-by: Heiner Kallweit --- drivers/misc/eeprom/at24.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 74d2347a1..2348da953 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -535,16 +535,28 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24_get_pdata(dev, &chip); } + if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { + dev_err(dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); + return -EINVAL; + } + /* both flags imply read-only */ if (chip.flags & AT24_FLAG_SERIAL || chip.flags & AT24_FLAG_MAC) chip.flags |= AT24_FLAG_READONLY; - if (!chip.page_size) { - dev_err(dev, "page_size must not be 0!\n"); - return -EINVAL; + writable = !(chip.flags & AT24_FLAG_READONLY); + if (writable) { + if (!chip.page_size) { + dev_err(dev, "page_size must not be 0!\n"); + return -EINVAL; + } + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && + !i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) + chip.page_size = 1; + if (!is_power_of_2(chip.page_size)) + dev_warn(dev, "page_size looks suspicious (no power of 2)!\n"); } - if (!is_power_of_2(chip.page_size)) - 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 @@ -556,11 +568,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (chip.flags & AT24_FLAG_MAC && chip.byte_len == 4) chip.byte_len = 6; - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && - !i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) - chip.page_size = 1; - if (chip.flags & AT24_FLAG_TAKE8ADDR) num_addresses = 8; else @@ -587,12 +594,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (IS_ERR(at24->client[0].regmap)) return PTR_ERR(at24->client[0].regmap); - if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { - dev_err(dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); - return -EINVAL; - } - - writable = !(chip.flags & AT24_FLAG_READONLY); if (writable) { at24->write_max = min_t(unsigned int, chip.page_size, io_limit); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&