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