Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp412156ybh; Thu, 12 Mar 2020 04:26:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuGWo8FPbuRuH+CBhohLRvRAjv7zftf5VV1kEHLy6MgZ1rksCmTGljFzdtgLF/fEC8PcoWI X-Received: by 2002:a9d:6c05:: with SMTP id f5mr5923719otq.232.1584012393734; Thu, 12 Mar 2020 04:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584012393; cv=none; d=google.com; s=arc-20160816; b=ppSY0HiwVS9CNQNGKuIgVFncIKiArwiNQCPfO0i9G/rwPx7PxBw/lX0yUx0yRPSM7k I2WvJMT8TSJ0wbIfTRTya/eMMj4E2lzuZ4jqwC9ay6oRcYxNCrFkcY7bW/xGZxTR/6am ECuy0k9RIJ5BaKL2p1e1FVdY+Rlqv1GpXSETawp1G30UIjRdLA2p73Bg8v3BKO1fPva3 gtfBihHfcHPCC7ks/mqUmeJuiApRTgQNSZnMUlcf8VGA6sgiGs3NriXzFr4+Ee0swJog g6dM9HtnscUcjaSat2jIOIi7UrHYyo5EQzaM8SI+CZjfiEljswTP71kvBVo6VzcjVyp/ aLQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=A+UyqCpk3ehSt3fATLD0YEXeimmgtg13K4AzSgQmvuk=; b=irykH4CjI1sCsKxiWLlz1XfO8W/sEdlCErXtZyCutScdLvnQgFj3zwN5HdrxD7gIGH PF1e58uyXlbfpcoa+iOYYascQfsLtc8yWMEf4hYZsN6doBFh96alpNn2WdVq66odS/El gedkYz5cVKaAS/Y2o4KyUQld9poscoeLLmZhJtNleKrUtFmCYOz4DEW5NjJ36v3whU2Q lA+/Pci/sVOplg0UPBI00I/e+iEPPduumiPMXpk7p5KD0y4fnvkBacG8e/obmDLHND5e BAvOr93Ib/Bh7tLIhpH0gX/qNtEXhBfcfM14G6/ckWv1bBNuHn5ICVukuJP3IGjvfuUe 4xiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dV6uNS3O; 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 q16si2704606otm.231.2020.03.12.04.26.21; Thu, 12 Mar 2020 04:26:33 -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=dV6uNS3O; 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 S1727178AbgCLLZa (ORCPT + 99 others); Thu, 12 Mar 2020 07:25:30 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41735 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbgCLLZa (ORCPT ); Thu, 12 Mar 2020 07:25:30 -0400 Received: by mail-pl1-f196.google.com with SMTP id t14so2545708plr.8; Thu, 12 Mar 2020 04:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=A+UyqCpk3ehSt3fATLD0YEXeimmgtg13K4AzSgQmvuk=; b=dV6uNS3On5Y7E6b8hIAPmZsRMN/v1Wv8qa1ree/XxcdVVojFZQXywk8QPUsvwNpTwd DOphPAdwQNK/w4zKmPtFyeo8TRc8tv8DQlWJIj7AnnBrDgQveuAiw19Cq2rNe6MoaS3A QW8vM/251xCi2WGieVQAc0nrqH0d4zpLWIPOxhb3qYpeRJ2HakLYFc6XgmK7zYlLBWNv TkuzI/gY+VEPlb6hS8FN9r1QN4WylYkvULTbEvJXslj62QLUVSyU4XQXU6oYnEK+PhbN bY65hYM5Epw6m2T7XTwKZcg75l/ISsAR87lqOFVyxQkTCNO7H5J1ujlYImo2BhfRn0/Q WIFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=A+UyqCpk3ehSt3fATLD0YEXeimmgtg13K4AzSgQmvuk=; b=Ky2oLzHe9bXmGqGJ1yI0ig91zUTyO56Ar1DiQOgvV6IMnwK/TrLGI0qYWe9+s2i/vI Gg61o3UuSnAAm1UlHlgLTXaXZlXpkOMlCD3daa4JT3XpE2jmEZ6bEKPbBXN60ucfay+o UGNa92Gfc7hjBZPKGjU4ScQqalalzJUVwg16vKwD0aGYBcaCbeOkTbQmXDBfyPbUJ2uh A+k+03dYQvHuXGBjufHg8CCrzCcV7QW/MXcF6XIyuolPlnFj4YguXQZZQtg1n3ghD/Aa aGMsIJLaex/1jXxYp59ihi94hkb+CKn418ryKwS79T0rptk7Q21vAn1332tX3+uvXqm4 gG8w== X-Gm-Message-State: ANhLgQ3ZV4fuKKq5XfPu5Ne/ATxtQz6boXz9b9r3eABETlUHXSoGFu9s D4QsalAysZjiLoHI/3f/msE= X-Received: by 2002:a17:90a:9501:: with SMTP id t1mr3758101pjo.108.1584012329040; Thu, 12 Mar 2020 04:25:29 -0700 (PDT) Received: from syed ([106.210.44.120]) by smtp.gmail.com with ESMTPSA id e30sm54230818pga.6.2020.03.12.04.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2020 04:25:28 -0700 (PDT) Date: Thu, 12 Mar 2020 16:55:17 +0530 From: Syed Nayyar Waris To: vilhelm.gray@gmail.com Cc: jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] counter: 104-quad-8: Add lock guards - differential encoder cable Message-ID: <20200312112517.GA32485@syed> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add lock protection from race conditions in the 104-quad-8 counter driver for differential encoder cable status changes. There is no IRQ handling so spin_lock calls are used for protection. Fixes: bbef69e088c3 ("counter: 104-quad-8: Support Differential Encoder Cable Status") Signed-off-by: Syed Nayyar Waris Split the patch from generic driver interface and clock prescaler related code changes. Also, include more code statements for protection using spin_lock calls and remove protection from few code statements as they are unnecessary. --- drivers/counter/104-quad-8.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 9dab190..1ce9660 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -1153,16 +1153,22 @@ static ssize_t quad8_signal_cable_fault_read(struct counter_device *counter, { const struct quad8_iio *const priv = counter->priv; const size_t channel_id = signal->id / 2; - const bool disabled = !(priv->cable_fault_enable & BIT(channel_id)); + bool disabled; unsigned int status; unsigned int fault; + spin_lock(&((struct quad8_iio *)priv)->lock); + + disabled = !(priv->cable_fault_enable & BIT(channel_id)); + if (disabled) return -EINVAL; /* Logic 0 = cable fault */ status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); + spin_unlock(&((struct quad8_iio *)priv)->lock); + /* Mask respective channel and invert logic */ fault = !(status & BIT(channel_id)); @@ -1194,6 +1200,8 @@ static ssize_t quad8_signal_cable_fault_enable_write( if (ret) return ret; + spin_lock(&priv->lock); + if (enable) priv->cable_fault_enable |= BIT(channel_id); else @@ -1204,6 +1212,8 @@ static ssize_t quad8_signal_cable_fault_enable_write( outb(cable_fault_enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); + spin_unlock(&priv->lock); + return len; } -- 2.7.4