Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1305665pxa; Thu, 13 Aug 2020 06:01:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAZKiAI58+WvSZTiQuIVigFJ2hOy/edLj7X2dbjZ16L3nEuL/WWef5mUSn1bKZ+TIVU2H7 X-Received: by 2002:a05:6402:6c8:: with SMTP id n8mr4652049edy.195.1597323700742; Thu, 13 Aug 2020 06:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597323700; cv=none; d=google.com; s=arc-20160816; b=QtkYd4STepy/eY4+IdYpnlW9BrghMBebuIcsYN+q7lULc0forSZc/31qRA/Vx1mA4s wirtgPtEsvh5lusPwt2MfkNpLokDt8WwGHBHOZSV6fkZG8zpkKRK7wbakl3ftiOBZ9FE EJn0uQT/QoXLHGWd6nnGl1zGYEmtvPeeihh+HJonYRkx/GSBWmVVhNuJLchOSr29YDr/ zFTQ3rJrsEhtgyY98MXdgEff/v8z8HFJ/zXz5d6N9TTU8bZvW0jlKh0+pAY37qicj4E8 Hvmhhqcl6/nnxZfaPbadsbZGh+hIoUlYph3rCeUi7k2FrgjQGVzza1iuXR50ABxYFRHj koxA== 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; bh=gTPtLLpVlGWVqCEQ50i6eGJ0HyGEAaWaZg6X6EHGJ8Y=; b=PDLZn3SaZsWweVL0Jn+ay5KDfoEZJCnwYwgN/L07s1A9MksDLYI/IwmFJXXeIn8JUE Gyv+Ay4OVU9mfeWDyEm7f3naaErNcqgw1ahG2FG/oECUisGLn20+wT13FyKIcgnsh2fa SDdf2TN/itrwgBMnRG8dlQ056D3htHAih0BHy8qAoIp0f/jQxmMZ4WXb9rtq5+BblQfF midW/7KSFuaD8ZttxgaLy+Frj/StBwvByChzl+qvBwoNVMifKRdhVPVkj8JqGOFxbjTB mqDvbYThFWlsO6pPWTbgw/1Puuaa8DtSaBSwQyuoJbrexIiohbzwROOKOtU1Z34JhmBc /5ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N2wAovWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id d24si3277506edz.145.2020.08.13.06.01.14; Thu, 13 Aug 2020 06:01:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N2wAovWQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726600AbgHMM6V (ORCPT + 99 others); Thu, 13 Aug 2020 08:58:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgHMM6T (ORCPT ); Thu, 13 Aug 2020 08:58:19 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E4FC061757; Thu, 13 Aug 2020 05:58:18 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id u20so2785912pfn.0; Thu, 13 Aug 2020 05:58:18 -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=gTPtLLpVlGWVqCEQ50i6eGJ0HyGEAaWaZg6X6EHGJ8Y=; b=N2wAovWQSI8dNBnAOPeeCXGOCZvLZ/zlHpkRNfRRrXr7TK+FK1x0d0t928qClLtlsJ ePcFzX6FIsx+3Zag95C1ASGvtL1i0gN7g4PQrk0FyILr1vLpIE7c1c/DdloHGOAT4DzQ S3u9a8O8S3x5c2Ez9w0hxSGirLz2Y0e4r8f545233XTtkXYeCHcV/wqgo41VYDlAobvK AYHKoIPG7e4fKvriHYYRgCYaCH/+TTlmmFFi80Bm+buFPoXkja5tV+wLDQQyNC8CaUvF w8bWztwBSf9wYmh7/0ApV/eVRfLXtYJ1Fcugvp3IHeReLEom8EYfdMp3iTNFg6Fa8+0u LkRw== 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=gTPtLLpVlGWVqCEQ50i6eGJ0HyGEAaWaZg6X6EHGJ8Y=; b=hOYq7ytX7N5gmbc8dEteytU2xHM+y2NBtCaTBL7VSBnFGpIozXaI065cIY5yQGFjt+ RfBpQv1aRF2KiFofqA6vPMT6JW6/GxOBOyur+XBni1EjYrY1D7wW4EWq6SFwIXuNDvju 7XniLa0Wq9HFHn+M4ebK7y5L3DJ+hQeALM6LF8UGPStGquq6AVZ+p6AckBuxT+uF84yO BCbIh9nLu4nAI5nEGqS5SQuvwY6AC+tcITZVtdf8zKIYCdoPzGnDGQaoXi6ZECZzug/N cmAq2lio8qigmnd8YstGkGZ3LwlnML+ltx+2gIkeKg16kcX5oQeehR6BfWQx9ULBwGc1 rrMA== X-Gm-Message-State: AOAM533YeM0smjgoof/bBEwhxCNrtkLrBdLlV3hJqzXEak+nNFNYWtIZ WDXynJ3EN79NVASME3NIVw== X-Received: by 2002:a63:925d:: with SMTP id s29mr3531093pgn.423.1597323498077; Thu, 13 Aug 2020 05:58:18 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:cea:b0c7:809d:c953:9730:34b1]) by smtp.gmail.com with ESMTPSA id t19sm5820505pfc.5.2020.08.13.05.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 05:58:16 -0700 (PDT) From: madhuparnabhowmik10@gmail.com To: wim@linux-watchdog.org, linux@roeck-us.net Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, andrianov@ispras.ru, ldv-project@linuxtesting.org, Madhuparna Bhowmik Subject: [PATCH] drivers: watchdog: pc87413_wdt: Fix Race condition bug Date: Thu, 13 Aug 2020 18:24:51 +0530 Message-Id: <20200813125451.19118-1-madhuparnabhowmik10@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Madhuparna Bhowmik After misc_register the open() callback can be called. However the base address (swc_base_addr) is set after misc_register() in init. As a result, if open callback is called before pc87413_get_swc_base_addr() then in the following call chain: pc87413_open() -> pc87413_refresh() -> pc87413_swc_bank3() : The value of swc_base_addr will be -1. Therefore, do misc_register() after pc87413_get_swc_base_addr(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Madhuparna Bhowmik --- drivers/watchdog/pc87413_wdt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/pc87413_wdt.c b/drivers/watchdog/pc87413_wdt.c index 73fbfc99083b..ad8b8af2bdc0 100644 --- a/drivers/watchdog/pc87413_wdt.c +++ b/drivers/watchdog/pc87413_wdt.c @@ -512,6 +512,10 @@ static int __init pc87413_init(void) if (ret != 0) pr_err("cannot register reboot notifier (err=%d)\n", ret); + pc87413_select_wdt_out(); + pc87413_enable_swc(); + pc87413_get_swc_base_addr(); + ret = misc_register(&pc87413_miscdev); if (ret != 0) { pr_err("cannot register miscdev on minor=%d (err=%d)\n", @@ -520,10 +524,6 @@ static int __init pc87413_init(void) } pr_info("initialized. timeout=%d min\n", timeout); - pc87413_select_wdt_out(); - pc87413_enable_swc(); - pc87413_get_swc_base_addr(); - if (!request_region(swc_base_addr, 0x20, MODNAME)) { pr_err("cannot request SWC region at 0x%x\n", swc_base_addr); ret = -EBUSY; -- 2.17.1