Received: by 10.192.165.148 with SMTP id m20csp3805241imm; Mon, 7 May 2018 20:19:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrI5dISKnhMZk+Frr2wUWfx7R07gNiqWw2Km88KbzcC49b+aRYXFcpt9sXwlzHauf9XzKtn X-Received: by 2002:a63:41c7:: with SMTP id o190-v6mr32144689pga.57.1525749561990; Mon, 07 May 2018 20:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525749561; cv=none; d=google.com; s=arc-20160816; b=FP4zjP2e9j/8kHZOjdTnagFih5Y72p9Vgn9gGG9p3AqOZlNzRIcu6zQNn3z7tjmsny B4DOxLnj721h6i2tmtmAyIPKPyEPfZFEMwXCcx8hVEr6z7cmDp+bCmF4thqPEqVxnQmL mFaJ+LyjVr99L9DwztF58tpKEc8i9CXS25ARmwz0/p52KW4T76AGnn2NN2O3nQFa4C+U z5W7sef5DAUgMaCqX8Am9oEYBdSQXD4NhPZ+irj3cjsLQa0t8ZldbsJScSEYsKU/nHDL Bx5zVRprN+CzTw/74zZ1sYrVD6WQTTfzYJRjqZkNoCsJNqAzZlb/HBhOBl6ZUtrAhZ1o UUpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=rhUE+4ZpBJGMmxXEZVaKpwGCz7+w2ghRnTjMCT2g9gA=; b=LgDBn/i1DRFdmhy30n46JcBWWWLnBTjkyXU4U1tngMMVE5c/fGZ7DnTz2oZy4L1eL5 iimz7q/hWct4CntAO/y+qgnqFQvvpksXB3ekw9pcnw02dpjtL8AWYsAN4sU2eZroEc+K gix6hVyqVpFPT7I258QI88I1WP7v/d5lqSlE1R6jB5rg56KsW96v5qOMX2RFwYH5ps8N uiyGFpMmEz8UAeLrMzyDWwKVCEkDqdh3WzKxahbcgcE0jM9uYwKLabUDyWWui42mWHzT RSortVKc5rTKSKhd/qwkrB0OQ3HHVdHga6eweUw/K8NwHk3ueN2YKnQkDpVHbjKMtawh 2Mtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cesD5BvR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4-v6si10742177pgr.301.2018.05.07.20.19.07; Mon, 07 May 2018 20:19:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cesD5BvR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753991AbeEHDSl (ORCPT + 99 others); Mon, 7 May 2018 23:18:41 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42829 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753997AbeEHDSe (ORCPT ); Mon, 7 May 2018 23:18:34 -0400 Received: by mail-pg0-f68.google.com with SMTP id p9-v6so17623045pgc.9; Mon, 07 May 2018 20:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rhUE+4ZpBJGMmxXEZVaKpwGCz7+w2ghRnTjMCT2g9gA=; b=cesD5BvRbmjlda7rwYMFuFAPgZbBpmLy1fGDJEjjiajbasYtGj7azYs45ZCyh0jaKg PwEbyjJGqVedUNaEm+mfB49wBzHqg3gx4CBp8Brovqx1eaq4snwhPnSiXzPJN/qcjCOD m2Rouv7SK0Hqq6osFksYTe3LvRf2pH86EDtJFkXjgz0ZESES4fs0DX4iFPcRmz9U53KZ omJR6mrIKgnCfD50igRHgfoYIgVXbq84jsy51CBBhQnoTie39Ecz2moxHB+QaP/urHyP mzQxJfP3Xj2fBwI6oknbuZTQeCUpbPMSnBYa4SCr9M8bj1K8OLYJkV+y3qHo6uG5QVSC xxvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rhUE+4ZpBJGMmxXEZVaKpwGCz7+w2ghRnTjMCT2g9gA=; b=sLa0DASq+Xh5pX/LYLNIgSNVjZuWgSuQqcVP/vSBP0M1tcijoqLltAs+dmAWHboFwk uLXBJYQwlItwkZ5yF282ODXPCzCiIkcwAiY3M/4DrYDORPEjqexlmBnRq4T4aGdQS8fN u1rLtL+S7xPchaJ9OqXCEsZ8PhYpeTvApLNYa9H8yODVwXcm4e1eSU9QMGqDN+Z7UB+F iyLc5XFKKHtOGNvKbh+04fbSjIcvif674JkD/JJXYo+BqkX2bC+HEW4W6W6vXJjSesXF sUGGSWPJGd20jQTFZogHzOuTuWE+BbIlHlpLUgM4dd7yPT0daFwqC+xRLvOy6j0vzij1 5Gtg== X-Gm-Message-State: ALQs6tCclf1tZIGb+ldSNF6SUAD5o8mKZk5SGuSEsYsqqP1rReBLpwbC mRm9/YneaNrZSkdsswvFDk0= X-Received: by 2002:a63:3c0c:: with SMTP id j12-v6mr32465061pga.203.1525749514073; Mon, 07 May 2018 20:18:34 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:18bf:4b0b:7f52:49b]) by smtp.gmail.com with ESMTPSA id r76sm7201479pfl.1.2018.05.07.20.18.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 20:18:33 -0700 (PDT) From: Jia-Ju Bai To: morbidrsa@gmail.com, wim@linux-watchdog.org, linux@roeck-us.net Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] watchdog: mena21_wdt: Fix a possible data race in a21_wdt_set_timeout Date: Tue, 8 May 2018 11:18:25 +0800 Message-Id: <20180508031825.12525-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The write operation to "wdt->timeout" is protected by the lock on line 118, but the read operation to this data on line 105 is not protected by the lock. Thus, there may exist a data race for "wdt->timeout". To fix this data race, the read operation to "wdt->timeout" should be also protected by the lock. Signed-off-by: Jia-Ju Bai --- drivers/watchdog/mena21_wdt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c index 25d5d2b8cfbe..05ca69042829 100644 --- a/drivers/watchdog/mena21_wdt.c +++ b/drivers/watchdog/mena21_wdt.c @@ -102,14 +102,15 @@ static int a21_wdt_set_timeout(struct watchdog_device *wdt, return -EINVAL; } + mutex_lock(&drv->lock); + if (timeout == 30 && wdt->timeout == 1) { + mutex_unlock(&drv->lock); dev_err(wdt->parent, "Transition from fast to slow mode not allowed\n"); return -EINVAL; } - mutex_lock(&drv->lock); - if (timeout == 1) gpio_set_value(drv->gpios[GPIO_WD_FAST], 1); else -- 2.17.0