From patchwork Sun Jul 17 18:40:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 72175 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp70581qga; Sun, 17 Jul 2016 11:40:17 -0700 (PDT) X-Received: by 10.66.197.195 with SMTP id iw3mr37146372pac.82.1468780816913; Sun, 17 Jul 2016 11:40:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zo9si22294825pac.196.2016.07.17.11.40.16; Sun, 17 Jul 2016 11:40:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751142AbcGQSkN (ORCPT + 1 other); Sun, 17 Jul 2016 14:40:13 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37728 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751138AbcGQSkM (ORCPT ); Sun, 17 Jul 2016 14:40:12 -0400 Received: by mail-wm0-f42.google.com with SMTP id i5so89887141wmg.0 for ; Sun, 17 Jul 2016 11:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=0laFK+yVLnxr4dMr6YUHlmB0WUbhEot5xw2ZgVm743A=; b=D3hmB4EBD1q9mjngj70HfAcoSdMr+ZJ45RB7te9VX4tt9hce2NKrzY0z5J6VsqsOlg 5KU3yojt5tV15cUJm2MLtg3kBA1JAHITdHQxW1qdUsGxl7JAxE6kM/6XGr9ypiUdxwpt 0NxwblMGMk21R4HcIc4MkC9NMvy2m/3wt++0/gNFpjaBTft3yWShvcFKhahn0KPbJ2e7 izDDOgKzMJ117WWJXEfFR6aqI7HKydwLn/TKpMn8x9YkH1bMlomV4yzj8g8WLH71OuDZ y2xraSR+aeIIshP2chGae3y9TIWPZQkwYhHBLI+WlL573zZS4v63qQgXiKbAyOyLTWzj VfBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0laFK+yVLnxr4dMr6YUHlmB0WUbhEot5xw2ZgVm743A=; b=Tzsl3+V53c/WOwW4PnzZ9sGZTQJP5DUThQEoF45d5TY8CficY4pGWqO4T2P1KKBf80 M9gsL72zlsHlqvZhmThCPbHDb3aL8dyd0nh5qJCBq0D85fthUrqjGvqKUB1xVt/8ZMDX 0n69bJBevMR99xUK/vpRviYdOH7AWFQtQvW8Vi8GVfUcq4l3JpQpLIq6lwL/tMO+gWUD 0TVK06bLHFn6H3nLVQjXqxF0wwpove2OlAPPo1cr7JUrE0rYageVUjyAVjaeMhsW9lcw fc+FuMxdShO0mQnul4/i6aWebNlL1jXMl+pZL9GeyLMYSimDS+ViOI3c1n+eGiFyjRL6 SdHA== X-Gm-Message-State: ALyK8tJFBlaQ2bRDnPT7asrRavLBMSeGpT4eqpPW/fMdG1+SPBlKIRTc9S2gAu+RhjVxQ74D X-Received: by 10.28.128.207 with SMTP id b198mr52018738wmd.56.1468780810593; Sun, 17 Jul 2016 11:40:10 -0700 (PDT) Received: from bgdev-debian.lan (jua06-1-82-242-157-225.fbx.proxad.net. [82.242.157.225]) by smtp.gmail.com with ESMTPSA id 17sm10414665wmf.6.2016.07.17.11.40.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 Jul 2016 11:40:09 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML , Andrew Lunn , Srinivas Kandagatla , Maxime Ripard , GregKH Cc: Bartosz Golaszewski Subject: [PATCH] eeprom: at24: tweak the loop_until_timeout() macro Date: Sun, 17 Jul 2016 20:40:06 +0200 Message-Id: <1468780806-13034-1-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org loop_until_timeout() replaced a do {} while loop in the at24 driver with a for loop which, under certain circumstances (such as heavy load or low value of the write_timeout argument), can lead to the code in the loop never being executed. Make sure that at least one iteration of the code enclosed within loop_until_timeout() is always executed. Suggested-by: Wolfram Sang Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 0b8fafdb..1f62aaf 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -116,7 +116,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); /* * Both reads and writes fail if the previous write didn't complete yet. This * macro loops a few times waiting at least long enough for one entire page - * write to work. + * write to work while making sure that at least one iteration is run before + * checking the break condition. * * It takes two parameters: a variable in which the future timeout in jiffies * will be stored and a temporary variable holding the time of the last @@ -124,9 +125,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); * holding at least 32 bits. */ #define loop_until_timeout(tout, op_time) \ - for (tout = jiffies + msecs_to_jiffies(write_timeout), \ - op_time = jiffies; \ - time_before(op_time, tout); \ + for (tout = jiffies + msecs_to_jiffies(write_timeout), op_time = 0; \ + op_time ? time_before(op_time, tout) : true; \ usleep_range(1000, 1500), op_time = jiffies) static const struct i2c_device_id at24_ids[] = {