Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1995059pxa; Mon, 3 Aug 2020 04:56:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN5NJ93knKNjwtYz5Y/Ox5cF5x+Fb3LnEwQRulQG3i1FN68nXz2H/ASix257vNjqjy5maN X-Received: by 2002:a05:6402:22c2:: with SMTP id dm2mr14954033edb.182.1596455774196; Mon, 03 Aug 2020 04:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596455774; cv=none; d=google.com; s=arc-20160816; b=rka50P676M0KGFAMGh9gI+3WDQs/jXyaeRTEHyWg7LxKOPNb2UdqaDB2g9xz8F3CMl fo0efJfmAg3+Kz9GEvs+Xl8/81Lt8/xXmZCfCq4SuohadB1wlKlu0Ncdyb1zrN3YJBvD DTcyQbHA6qERSZshgTw0BK8CLXuboJ+vzvdwYxitrv0QIlxZfLpNn+EFkPtpW1oTEro/ ntLl8T6aUiSzw+ZEuxOiIgjz7q0enVXS9LSiyFi5AXFffy6LdFWFnGZa2T9QY74jM4PD Jr0BBfk8kMMYQ9Qmgnm68Y4F7XJTZToP0/zhGRwskys7pA3UZZ3W8PDF71LTgZVPiJH+ dLbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=+kV2sjM6QyMHMD1QugYjSHMR+cl9DqAemi2USpIWe80=; b=cY0rSQkusd+HvHThZvRbx8+UH9a8S4bwz9estVBtSTyrfnJ7notXs5KFeGdnxYFkwO XcgGYfiV3kJMZXAaaqMXdr7ffreB8hGzaCzBSjOYwbC7ROOwVTC1RM+THvqA1h8b/NAy jekzLO/8Hi/rw1vsy9fCdvjSSYxuRjt3qzMyKLtJr0SRX4nxUntU0TWCQLo3qfNblUM0 1z6PWjydZqBAX/vcO88HmSi1aw/kAyN6LiwnPT2hRF9RV5zfkH08eOocVcJxTvHqEHnF YRmvVmSE1UESiM7fk6P+EdxYZa4kfcLrRw44clpwwsZwpAFIUCDuEx/uOxEjfnPf5oDm yP0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2OXXZz6L; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si3445732edb.401.2020.08.03.04.55.50; Mon, 03 Aug 2020 04:56:14 -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=2OXXZz6L; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbgHCLyT (ORCPT + 99 others); Mon, 3 Aug 2020 07:54:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726511AbgHCLyK (ORCPT ); Mon, 3 Aug 2020 07:54:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E72E92076C; Mon, 3 Aug 2020 11:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596455624; bh=5A1oCPWgnKkZFBnhgIH4zbdWjtzCqsJZ8eSK6EddM5E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2OXXZz6L8TwDyNZXlLmZqydukYYfMfQYoZFCePUAzM+ZD246LX1U0Oz2zH3/vCFNz n8uyUL5FTO+PZQl7z9mtnFkszBAEY9qjNsHAT3d7+ruCdlndM3EfNLZ9dYaRTTnNip H0GMlrreLx2/YcO2gKlu9WAtib0gcqrDe0knmAMs= Date: Mon, 3 Aug 2020 13:53:28 +0200 From: Greg KH To: madhuparnabhowmik10@gmail.com Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, andrianov@ispras.ru, ldv-project@linuxtesting.org Subject: Re: [PATCH] drivers: char: applicom.c: Add lock for protecting DeviceErrorCount Message-ID: <20200803115328.GA955269@kroah.com> References: <20200803105049.11089-1-madhuparnabhowmik10@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200803105049.11089-1-madhuparnabhowmik10@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 03, 2020 at 04:20:49PM +0530, madhuparnabhowmik10@gmail.com wrote: > From: Madhuparna Bhowmik > > The variable DeviceErrorCount is used to keep track of the number of > errors in read, write and interrupt routines, however it was not > protected by proper locking. > Therefore, this patch adds a spinlock: error_lock to protect the > variable. > > Found by Linux Driver Verification project (linuxtesting.org). > > Signed-off-by: Madhuparna Bhowmik > --- > drivers/char/applicom.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c > index 14b2d8034c51..6df7450b8b99 100644 > --- a/drivers/char/applicom.c > +++ b/drivers/char/applicom.c > @@ -106,6 +106,7 @@ static DECLARE_WAIT_QUEUE_HEAD(FlagSleepRec); > static unsigned int WriteErrorCount; /* number of write error */ > static unsigned int ReadErrorCount; /* number of read error */ > static unsigned int DeviceErrorCount; /* number of device error */ > +DEFINE_SPINLOCK(error_lock); /* lock to protect error count variables */ That's a horrible global name, shouldn't it be static? > > static ssize_t ac_read (struct file *, char __user *, size_t, loff_t *); > static ssize_t ac_write (struct file *, const char __user *, size_t, loff_t *); > @@ -428,7 +429,9 @@ static ssize_t ac_write(struct file *file, const char __user *buf, size_t count, > spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags); > printk(KERN_WARNING "APPLICOM driver write error board %d, DataFromPcReady = %d\n", > IndexCard,(int)readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY)); > + spin_lock_irqsave(&error_lock, flags); Why all of these irqsave? > DeviceErrorCount++; Does this really matter? Who cares if we drop one of these, or any other of these debugging-only values? thanks, greg k-h