Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp853948pxk; Thu, 17 Sep 2020 19:09:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5aRytlyOxcJUXdB6u5QtpwsQLIgHrnHx65TOLoMVuss5hDlAMGyq0MpvmjYuBEsMlMwHP X-Received: by 2002:a17:906:e4c:: with SMTP id q12mr32974646eji.425.1600394981727; Thu, 17 Sep 2020 19:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394981; cv=none; d=google.com; s=arc-20160816; b=u2qTJFzmu/J6OKGBc1kvgDTNrpUHWJbn6V/h2FcYJ5yW5gSMc29OpcR8RHw6R/Yea2 wtiMPeR6guJqJQVZ0TcFo89KV5AJpESZSKM9PPbtkYUDz3zqRkG05V+VybmO6W49XBHd CHF9nL3upbVXXBLWmLgipOzG9VFMS2VHrwQcuJDhMNRofFB8X+P15XYbw57M7gjdqcqx K0zXZkul0lQ5UYK37FKWXxvt/vmyp4A2AHgCXdRndjtUvhrEpJGt0qMeTgU5l4OMOi0w isyoDlgF8ACx3tDdQrPie95V/ovHEEhZkarr09AkjLqsmHfqSJOUh3UNtLpiFB9eEptR R3Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dRrvckx030fYTHwXQngtE2lTUDPAUXW5I5GNUnK2gc8=; b=j3SgIktWmaywQfQns/inqpOdBAFpzahr8twU5FDxDIFa4J1ggjVhw+OWcCNR0+B6Bc ggR2p9jMMWWCawz1o8Cw4EBZzvmM6Gp0yzUHUSQmf114yasgdHb1NGsogyCHoSTQqfdM qRkzD1trki637PBhRqGoZ4ybxCQ/iXgbXHGGMlirdKCJkutHyY17rvLhSZxkUSeLjRiL 6mqyfAgMSlstwEH/OYToXmhmem0hVUsfZ4d4qjt9Ii4U8dvcidZeCZxRbx/sqCWfCPWb A6B4Pi0xbFoUj6NOXk6fVq7GPpFPSI1aFBYYORLuq2n70X9M+qH00EE8A8Kwokc22pPO h2+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tKB4xkMV; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si1096385edj.64.2020.09.17.19.09.18; Thu, 17 Sep 2020 19:09:41 -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=@kernel.org header.s=default header.b=tKB4xkMV; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727783AbgIRCGe (ORCPT + 99 others); Thu, 17 Sep 2020 22:06:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:55092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbgIRCGG (ORCPT ); Thu, 17 Sep 2020 22:06:06 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 238A22376F; Fri, 18 Sep 2020 02:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394765; bh=Ep7b5mM1MrRuSLGuARiHo7eHefUyapE1mHyhqARkDMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tKB4xkMVKaJVQnw4egYM7XSP3MBpoaeBFFWMZxnjFEe1wF2QhbNL9LPTogb19ager qxn7PVUKjtRlsTfq9DnBrY9Fsx+D72wAxXJYPHG01xYU3TN/WPo0VCesOS3JWU3rJf R6cycMJxIQXre8vpUNeRw45ow2PVBGbiRGAWquYE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Madhuparna Bhowmik , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.4 241/330] drivers: char: tlclk.c: Avoid data race between init and interrupt handler Date: Thu, 17 Sep 2020 21:59:41 -0400 Message-Id: <20200918020110.2063155-241-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Madhuparna Bhowmik [ Upstream commit 44b8fb6eaa7c3fb770bf1e37619cdb3902cca1fc ] After registering character device the file operation callbacks can be called. The open callback registers interrupt handler. Therefore interrupt handler can execute in parallel with rest of the init function. To avoid such data race initialize telclk_interrupt variable and struct alarm_events before registering character device. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Madhuparna Bhowmik Link: https://lore.kernel.org/r/20200417153451.1551-1-madhuparnabhowmik10@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/char/tlclk.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c index 6d81bb3bb503f..896a3550fba9f 100644 --- a/drivers/char/tlclk.c +++ b/drivers/char/tlclk.c @@ -777,17 +777,21 @@ static int __init tlclk_init(void) { int ret; + telclk_interrupt = (inb(TLCLK_REG7) & 0x0f); + + alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL); + if (!alarm_events) { + ret = -ENOMEM; + goto out1; + } + ret = register_chrdev(tlclk_major, "telco_clock", &tlclk_fops); if (ret < 0) { printk(KERN_ERR "tlclk: can't get major %d.\n", tlclk_major); + kfree(alarm_events); return ret; } tlclk_major = ret; - alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL); - if (!alarm_events) { - ret = -ENOMEM; - goto out1; - } /* Read telecom clock IRQ number (Set by BIOS) */ if (!request_region(TLCLK_BASE, 8, "telco_clock")) { @@ -796,7 +800,6 @@ static int __init tlclk_init(void) ret = -EBUSY; goto out2; } - telclk_interrupt = (inb(TLCLK_REG7) & 0x0f); if (0x0F == telclk_interrupt ) { /* not MCPBL0010 ? */ printk(KERN_ERR "telclk_interrupt = 0x%x non-mcpbl0010 hw.\n", @@ -837,8 +840,8 @@ out3: release_region(TLCLK_BASE, 8); out2: kfree(alarm_events); -out1: unregister_chrdev(tlclk_major, "telco_clock"); +out1: return ret; } -- 2.25.1